Open luabud opened 12 months ago
My experience is that go-to-definition
never works as long as .pyi
files exists.
For example, go-to-definition
over getLogger
in the below example always opens up pyalnce's stub instead of orignal python file:
/home/user/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/logging/__init__.pyi
I expect it to open up the real source code:
/home/user/opt/python3.11/lib/python3.11/logging/__init__.py
import logging
logging.getLogger("foo")
If I switch the user settings to "python.languageServer": "Jedi"
, then go-to-definition
works, but unfortunately, I lost all the Pylance's features.
@copdips I just tried and it works as expected. can you open new issue so we can dig in to find out what went wrong?
oops. you already did - https://github.com/microsoft/pylance-release/issues/6015
We often get feedback that the behaviour of "go to def" vs "go to declaration" is confusing as it's not super consistent. Basically, Pylance does the following IIUC:
.pyi
file and Pylance can also find a definition for that symbol in a.py
file, "go to def" takes users to the.py
file and "go to declaration" takes users to the.pyi
file..pyi
file doesn't exist, "go to def" and "go to declaration" on a symbol takes users to the.py
file where it's defined.pyi
file, but Pylance can't find corresponding symbol in.py
, OR the.py
file doesn't exist (e.g. the package is not installed but the stub is,pyi
exists for a compiled module, etc. ), then "go to def" and "go to declaration" on that symbol takes users to the.pyi
file where it's declaredMy expectation is that 1 and 2 are the most common scenarios. And 3 is the one that might confuse users since "Go to def" and "Go to declaration" end up having the same behaviour, and usually those who mean to use "go to declaration" are the people who are using types (while I imagine the majority of folks in scenario 2 are not).
For scenario 3, I think it'd be worth showing an informational notification explaining we couldn't find the symbol definition, so we're falling back to going to the symbol declaration. Something similar to what we do on the debugger side when
justMyCode
is set totrue
and users try to step into library code:Alternatively, we could just add this info in the output window if we think a notification could be too intrusive/annoying.