Skip to content

PR: Fix Inline comments including text with import cause functions/classes to disappear when under cells in the Outline explorer #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pylsp/plugins/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2021- Python Language Server Contributors.

import logging
import re
from pathlib import Path

from pylsp import hookimpl
Expand All @@ -27,7 +28,11 @@ def pylsp_document_symbols(config, document):
if not add_import_symbols:
# Skip if there's an import in the code the symbol is defined.
code = d.get_line_code()
if " import " in code or "import " in code:
pattern = (
re.compile
(r'^\s*(?!#)(from\s+\w+(\.\w+)*\s+import\s+[\w,\s*]+|import\s+[\w,\s]+)')
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would like to take advantage of compiling it once, you should move the pattern definition up, prior to the function definition, otherwise it will just compile it every time.

if pattern.match(code):
continue

# Skip imported symbols comparing module names.
Expand Down
Loading