python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.76k stars 186 forks source link

Resolving Python Symbols with Wildcard Imports using `python-lsp-server` #426

Open nashid opened 10 months ago

nashid commented 10 months ago

I asked previously this question.

Please note wildcard imports are well supported within Jedi. Thats why I am asking about wild card imports in this repository.

ccordoba12 commented 10 months ago

@davidhalter, sorry for the ping, but is this correct? Does Jedi support wild card imports in the sense that we can expect go-to-definitions of them to work as expected?

rchl commented 10 months ago

It works just fine.

LSP-pylsp textDocument/definition (9): {'textDocument': {'uri': 'file:///.../main.py'}, 'position': {'line': 4, 'character': 15}, 'workDoneToken': '$ublime-work-done-progress-9'}
LSP-pylsp (9) (duration: 6ms): [{'range': {'start': {'line': 1, 'character': 4}, 'end': {'line': 1, 'character': 28}}, 'uri': 'file:///.../utils.py'}]

Might be something wrong in how you are using pylsp if you are not running it through an editor.

For example you should make sure to specify rootUri in the initialize request to a directory that contains the files.

davidhalter commented 10 months ago

@ccordoba12 Yes.

claireratigan commented 10 months ago

I am also having this issue while using helix editor with a python-lsp lsp backend. Where star/wildcard imports are used I get a warning 'from [...] import *' used; unable to detect undefined names

nashid commented 10 months ago

@ccordoba12 @rchl I am having this issue with the python-lsp backend. I can share the exact setup with you if needed. But it is already also confirmed by @timratigan. I would really appreciate your help with this.

ccordoba12 commented 10 months ago

@timratigan, that's a linting warning (probably coming from flake8) and it's expected because linting tools can't warn you about undefined/unused names when you use wildcard imports.

@nashid, please share a simple set of files that reproduce the issue for you. But I think your problem is probably related to what @rchl said:

Might be something wrong in how you are using pylsp if you are not running it through an editor.

For example you should make sure to specify rootUri in the initialize request to a directory that contains the files.

So, please investigate that too.

claireratigan commented 10 months ago

my bad, thanks :)

Tal500 commented 8 months ago

@timratigan, that's a linting warning (probably coming from flake8) and it's expected because linting tools can't warn you about undefined/unused names when you use wildcard imports.

@nashid, please share a simple set of files that reproduce the issue for you. But I think your problem is probably related to what @rchl said:

Might be something wrong in how you are using pylsp if you are not running it through an editor. For example you should make sure to specify rootUri in the initialize request to a directory that contains the files.

So, please investigate that too.

Since Jedi is so great, can python-lsp-server (optionally) query Jedi for every symbol appearing in the document, and show an error if the symbol doesn't appear (Jedi just works also with star imports)? A similar logic already implemented in Pylance, and it would be nice to have it here.

I know that you might say "that's the job of pyflake", but pyflake complains about star import, because of its local scanning behavior, but this LSP can be smarter (and slower, therefore only optionally).