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

Goto definition goes to stub files instead of actual definitions #65

Closed
jahan01 opened this issue Jul 7, 2020 · 42 comments
Closed

Goto definition goes to stub files instead of actual definitions #65

jahan01 opened this issue Jul 7, 2020 · 42 comments
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@jahan01
Copy link

jahan01 commented Jul 7, 2020

Expected behaviour

Goto definition goes to actual code even if types are defined in a stub file

Actual behaviour

Goto definition goes to stub files instead of actual code

Code Snippet / Additional information

from http import HTTPStatus

print(HTTPStatus.GATEWAY_TIMEOUT)

Try goto definition (F12) on either HTTPStatus in line 1 or GATEWAY_TIMEOUT in line 3

@tekumara
Copy link

tekumara commented Jul 8, 2020

Duplicate microsoft/pyright#795

@judej judej added the needs investigation Could be an issue - needs investigation label Aug 6, 2020
@huguesv
Copy link
Contributor

huguesv commented Aug 6, 2020

Goto definition on HTTPStatus results include both the .py and .pyi, which is currently the expected result. As discussed in the linked topic on pyright, we have no control on which of the multiple results appears first.

Goto definition on GATEWAY_TIMEOUT results only include the .pyi, which is a bug, it should be able to find it in sources as well but it doesn't right now.

@jahan01
Copy link
Author

jahan01 commented Aug 10, 2020

As a suggestion, if you couldn't control the order of displayed results, it would be nice to have an option turn off displaying *.pyi files in all the results as whole or only display results from *.pyi files when there are no *.py files.

@savannahostrowski
Copy link
Contributor

@jahan01 Thanks for the suggestion. We're looking into solutions and will update here soon.

@savannahostrowski savannahostrowski added enhancement New feature or request needs decision Do we want this enhancement? needs spec and removed bug Something isn't working needs investigation Could be an issue - needs investigation needs decision Do we want this enhancement? labels Aug 10, 2020
@gousaiyang
Copy link

Could we have two separate commands like Go To Declaration/Go To Definition for C/C++ in Visual Studio?

  • Go To Declaration goes to .h files for C/C++, for Python we can go to the .pyi files
  • Go To Definition goes to .cpp files for C++, for Python we can go to the .py files
  • If one of the .pyi file and .py file is missing, the other command could still go to the existing file

@chaleaoch
Copy link

hello, is this a bug in below gif?
websocket_firefox

@jakebailey
Copy link
Member

At the moment, that is expected behavior.

@vinicius-cleves
Copy link

vinicius-cleves commented Sep 19, 2020

I am trying to annotate tqdm. So I did the following:

  1. Created a file typings/tqdm/__init__.pyi with:
from typing import Any, Generic, Iterable, Iterator, TypeVar
T = TypeVar('T')
class tqdm(Generic[T]):
	def __init__(self, iterable: Iterable[T], *args: Any, **kwargs: Any): ...
	def __iter__(self) -> Iterator[T]: ...
  1. Added "python.analysis.stubPath": "${workspaceFolder}/typings" to .vscode/settings.json

Now when I click on tqdm -> "Go to Definition" on another piece of code (like `from tqdm import tqdm') it jumps straight to the stub file. Also if I try to see the references on "Go to References" the source code is not listed (it was before adding the stub file). Selecting Peek -> "Peek Definition" only display the stub file as well.

I would expect it to show the source code (or at least give an option to it) when clicking "Go to Definition"

@nnemkin
Copy link

nnemkin commented Oct 18, 2020

This is a major bug. Navigation into stdlib and 3rd party libraries is basically broken. .pyi files are an implementation detail of a typechecker, please don't put them above the real code.

@ClericPy
Copy link

Anybody thought there is an ambiguous meaning between goto definition and goto stubs? My temp solution is to remove .pyi files but is not very smart.

@ewerybody
Copy link

Well alright. Thanks @jakebailey . I was looking thoroughly but didn't use the word "stub" just .pyi ... 😄
So, what about WIP? How is this supposed to work in the future? Is there a plan? is there a blog post about this? anything?

For me this is simply broken atm and it was fine in the past.
There could be another shortcut like Shift+Ctrl+Click to Goto the stub. Actual definition should always be first!, no?

I mean I wanna be fair here: You're doing awesome work already and when doing progress things need to break here and there but I'd at least wanna know how to backup.

@ssbarnea
Copy link

ssbarnea commented Nov 20, 2020

That default preference for pyi drives me insane as it is killing the entire code browsing experience for any library that happens to keep type hints outside the source files. I do not want to browse the stubs when the source files exist and we clearly need and option to tell it to respect that preference.

Our only luck is that very few libraries decided to put keep type hints in pyi files.

@pszynk
Copy link

pszynk commented Nov 23, 2020

This is a sound solution, your rarely are interested in definition or type stubs at the same time.
There should be a separate option to go to either of them.

Could we have two separate commands like Go To Declaration/Go To Definition for C/C++ in Visual Studio?

  • Go To Declaration goes to .h files for C/C++, for Python we can go to the .pyi files
  • Go To Definition goes to .cpp files for C++, for Python we can go to the .py files
  • If one of the .pyi file and .py file is missing, the other command could still go to the existing file

@ssbarnea
Copy link

My C/++ years precede the existence of vscode so I do not know what is current behavior on Cmd+click as I would wish to be Go To Definition by default.

There is a slight issue with having two options because what if you do not have a definition and you only have access to the declaration? in that case I suppose it should send you to the only one available

Apparently the UI is bit confused about what is a definition and declaration as I right click on the method and choose "Go To Definition" and instead it opens the in-line preview of the declaration:

This was happened accesing "Go To Definition":

@b99andla
Copy link

Also having trouble with this. Previously i at least got both the stub and implementation, but now I only get the stub when using F12...

@RileyMShea
Copy link

I am also experiencing this issue. My current solution involves renaming my /typings folder whenver I need goto impl. I've had it occasionally recognize both the pyi stub and the library .py implementation, but I have no way of consistently reproducing that behavior. Seems a bit odd that a stub would completely obfuscate the implementation.

@aleuyX
Copy link

aleuyX commented Dec 3, 2020

Started happening to me today. No workaround for this at least?

@savannahostrowski
Copy link
Contributor

We are currently investigating solutions to address this.

@maestro4
Copy link

maestro4 commented Feb 3, 2021

For the meantime I've downgraded pylance extension to v2020.11.1 . It now shows the documentation properly and a click will follow to the source. Unfortunately, I don't exactly know which version broke the behaviour, therefore I just tried an older version. Hope I don't have to use the older version for long, as some people are already working to resolve this issue.

Update: unfortunately, the mentioned version is also not working after restarting vscode, sorry for confusion..

@ewerybody
Copy link

This is not strictly related, no. We'd appreciate a new issue for that, but I would expect it to either be an issue with the source mapper, or that os.path contains compiled code that isn't shown.

Seems there are already some related issues: #844, #170 ? Or would you rather have another one dedicated to build-in libs?

@jakebailey
Copy link
Member

#844 is about the bundled matplotlib stubs, and #170 is a problem with Jupyter, neither are related to isfile missing its documentation. The builtins already have docs, but other stdlib code may not if they are compiled, but I would have expected this one to work.

@jakebailey
Copy link
Member

The next release includes a change to go-to-definition's behavior and adds go-to-declaration. Go-to-definition prefers source files, while go-to-declaration prefers stubs.

Here's an example jumping to Flask:

gotothing2

If either of these calls would otherwise return no results (e.g. go-to-def when only a stub is available), then the old behavior is used so that you don't mysteriously jump nowhere.

@jakebailey
Copy link
Member

This issue has been fixed in version 2021.2.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202121-10-february-2021

@salvapinyol
Copy link

salvapinyol commented Feb 13, 2021

For me is not fixed.

Example:

from operator import attrgetter

If I try Go to Definition or Go to Declaration for attrgetter, both goes to stub file.

@jmfederico
Copy link

Not fixed for me either.

For me it fails with the following:

from django.urls import include, path

It correctly takes me to the source of include, but for path it takes me to stub.

@ewerybody
Copy link

Whow! I thought it was working! But obviously not always

import pipes
pipes.quote()

Ctrl+Clicking pipes goes to the stub while quotes takes me to the source! :|

@jakebailey
Copy link
Member

jakebailey commented Feb 13, 2021

Please report these as individual bugs. We won't be reopening this issue for every case, as the primary functionality for filtering the results is in place. Not being able to jump to certain files or going to the wrong place are different issues and existed before this was fixed. (This fix is just a filter over previous results.)

@kissgyorgy
Copy link

kissgyorgy commented Feb 21, 2021

This still jumps me to the stubs most of the time on v2021.2.3, especially in Django projects.

@jakebailey
Copy link
Member

Please file a new issue for those cases, but you may want to wait for the next release, which includes a good number of improvements to the way we map stubs to their source files.

@andrewmed
Copy link

This issue has been fixed in version 2021.2.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202121-10-february-2021

This issue should not have been closed before some testing, not after getting this feedback
For me, as well, code navigation is broken with pylance. Looking for replacement...

@heejaechang
Copy link
Contributor

@andrewmed if you open new issue with repro step specific to your issue, we can take a look. "go to definition" can go to stub instead of actual definition due to million different reasons. this issue is for some specific reasons which we added logic to handle. if it didn't work for you, yours is probably due to different reasons we don't know about yet. but without repro steps, we can't even take a look.

@zakigo
Copy link

zakigo commented Jan 17, 2022

this major issue exsist now . Not solved yet. so inconvenient. Hope it will be solved as soon as possible!

pylance _v2022.1.1

Version: 1.63.2 (user setup)
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Date: 2021-12-15T09:40:02.816Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19042

@debonte
Copy link
Contributor

debonte commented Jan 20, 2022

@zakigo, as heejaechang mentioned above, we need repro steps to understand what you are seeing. Please file a new issue with repro steps for what you are seeing.

@olivarius1
Copy link

I have encountered the same issue. In the past, I could at least see .pyi files and the source code. However, now, no matter which one I use between 'Go to Definition,' 'Go to Declaration,' and 'Go to Type Definition,' I can only see .pyi files (located in .vscode-server/extensions/ms-python.vscode-pylance-2023.10.20/dist/typeshed-fallback/stdlib). My Pylance version is 2023.10.20.

@debonte
Copy link
Contributor

debonte commented Oct 13, 2023

@olivarius1, please file a new issue. The issue that you are commenting on was fixed 2.5 years ago and is likely unrelated to what you are seeing.

@cangyin
Copy link

cangyin commented Oct 29, 2023

For python 3.8.10, with pylance v2023.1.10

#!/usr/bin/python3

import sys

from unicodedata import category

Ctrl+Click on unicodedata jumps to the damn stub file, that's frustrating and drives me crazy.

@erictraut
Copy link
Contributor

Where would you expect it to take you in this case? There is no unicodedata.py file. This module is implemented in C and compiled as part of the Python interpreter. That means there is no source code on your system that can be displayed. Pylance is falling back to the type stubs in this case because they at least provide you with the interface definitions for this module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests