Skip to content
Merged
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