Fix inline comments that include text with import#639
Fix inline comments that include text with import#639ccordoba12 merged 7 commits intopython-lsp:developfrom
import#639Conversation
krassowski
left a comment
There was a problem hiding this comment.
Thank you for opening the PR @jsbautista!
The proposed change makes sense, but I think it misses a few cases:
from . import somethingfrom ..module import somethingfrom module import (a, b)
It will also fail with multi-line imports, but after all the existing code is not handling multi-line imports well either.
Would you mind adding a test for the various cases in:
python-lsp-server/test/plugins/test_symbols.py
Lines 51 to 80 in 04fa3e5
An alternative to using a regular expression would be using the ast module which should properly parse import expressions and ignore comments.
pylsp/plugins/symbols.py
Outdated
| pattern = ( | ||
| re.compile | ||
| (r'^\s*(?!#)(from\s+\w+(\.\w+)*\s+import\s+[\w,\s*]+|import\s+[\w,\s]+)') | ||
| ) |
There was a problem hiding this comment.
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.
import
ccordoba12
left a comment
There was a problem hiding this comment.
Looks good to me, thanks @jsbautista!
Fix Inline comments including text with import cause functions/classes to disappear when under cells in the Outline explorer