Skip to content

Go to definition doesn't work on some classes #2460

Closed

Description

Using the Go to defintion (F12) feature doesn't always work for me. It depends on which class I'm trying to go to the definition of. I have not been able to determine what the difference is for classes that work versus those that don't. Let me know if you have some suggestions on differences to search for, I'm happy to dig.

In this screenshot, I'm trying to jump to a class called OrderManagerConfiguration. It may be worth noting that Find all references actually works for this class -- it finds about 10 references.

image

Related issues:
#1033
#2450

Environment data

  • VS Code version: 1.26.1
  • Extension version (available under the Extensions sidebar): 2018.7.1
  • OS and version: Ubuntu 16.04
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: In-house

Actual behavior

Jump to definition says the class is not found when the class actually exists.

Expected behavior

Jump to definition should jump to the definition of the class.

Steps to reproduce:

Jump to definition does not always fail. I am not able to find the pattern for the failing classes. Please give me your ideas and I can test them on my setup.

Logs

Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

See attachments
vscodelogs.txt

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

See attachments
vscodeconsole.txt

Activity

  1. d3r3kk commented on Aug 29, 2018

    @d3r3kk

    Thanks for the detailed report! Is this while using the new Python Language Server? You are using the Python Language Server if the setting for python.jediEnabled is set to false.

  2. brettcannon commented on Aug 29, 2018

    @brettcannon
    Member

    And just to double-check, this isn't an extension module you're trying to navigate to, correct?

  3. amittleider commented on Aug 30, 2018

    @amittleider
    Author

    Thanks for the reply.

    Derek Keeler (@d3r3kk) , currently I am not using the Python Language Server. (I did give it a try though, and it has the same behavior -- I get the popup saying "No definition found for class ")

    Brett Cannon (@brettcannon) I'm not sure what an extension module is. I guess you mean extending with C/C++ code (like this article https://docs.python.org/2/extending/extending.html) ? By this definition, it is not an extension module.

    I have learned a bit more about the problem. In my original example, I was trying to jump to a definition of a class called OrderManagerConfiguration, which exists in a module called wa_trading. If I am trying to jump there from another class inside wa_trading, it will find the class and jump to the definition successfully. However, if I try to jump to OrderManagerConfiguration from another module, I get the No definition found error.

    Here is a snippit of pip freeze on the modules that I am working in:

    -e git+git@[..cropped..]#egg=wa_backtest&subdirectory=backtest
    -e git+git@[..cropped..]#egg=wa_common&subdirectory=common
    -e git+git@[..cropped..]#egg=wa_dataviz&subdirectory=dataviz
    wa-live==2.5.17
    -e git+git@[..cropped..]#egg=wa_mkdata&subdirectory=mkdata
    -e git+git@[..cropped..]#egg=wa_ml&subdirectory=ml
    -e git+git@[..cropped..]#egg=wa_reporting&subdirectory=reporting
    -e git+git@[..cropped..]#egg=wa_trading&subdirectory=trading
    

    And here is what my workspace settings look like in VScode:

    {
    	"folders": [
    		{
    			"path": "walnut-finance"
    		},
    		{
    			"path": "walnut-finance/backtest"
    		},
    		{
    			"path": "walnut-finance/common"
    		},
    		{
    			"path": "walnut-finance/dataviz"
    		},
    		{
    			"path": "walnut-finance/docker"
    		},
    		{
    			"path": "walnut-finance/live"
    		},
    		{
    			"path": "walnut-finance/mkdata"
    		},
    		{
    			"path": "walnut-finance/ml"
    		},
    		{
    			"path": "walnut-finance/reporting"
    		},
    		{
    			"path": "walnut-finance/trading"
    		},
    		{
    			"path": "wa_production"
    		},
    		{
    			"path": "testing_wa_production/wa_production"
    		},
    	],
    	"settings": {}
    }
    
  4. brettcannon commented on Sep 6, 2018

    @brettcannon
    Member

    Andrew Mittleider (@amittleider) so is the code you are importing in a different folder in your workspace than where you are trying to go to the definition from? And if so how are you making the import work when running your code from VS Code to know where the code happens to be?

  5. pzelnip commented on Sep 7, 2018

    @pzelnip

    I've found that now (since the August update), Go to definition is never working for me in Python code, even when the definition of an item is in the same file. Ex:

    def foo():
       print('foo!')
    
    def bar():
       foo()
    

    Doing a "Go to Definition" on the call to foo() on the final line is giving "No definition found for foo()" See screenshot:

    gotodefn

    VS Code version: 1.27.1
    Extension version (available under the Extensions sidebar): 2018.8.0
    OS and version: OSX Sierra (10.12.6)
    Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.2
    Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv

  6. brettcannon commented on Sep 7, 2018

    @brettcannon
    Member

    Why do all of your def lines have squiggles?

    And I assume you can execute the above code in your interpreter? (I'm trying to make sure you don't have a broken install because no one else is reporting this level of issue.)

    And I can't reproduce with VS Code stable and the latest extension with either Jedi or the language server. Can you paste in what is in the Output panel for Python to see if some obvious error is there?

  7. pzelnip commented on Sep 7, 2018

    @pzelnip

    Squigglies are because I have pydocstyle set up as a linter and there's no docstrings on either method.

    As it turns out I need to apologize, as it looks like a restart of VS Code fixed the problem.

    What I'm a bit puzzled by is I had the exact same problem a few days ago, and I know I restarted VS Code yesterday for the most recent update. Not sure what changed in that time, but it appears to be working now, apologies for the confusion.

  8. brettcannon commented on Sep 10, 2018

    @brettcannon
    Member

    We pushed a new version this past Thursday so it's possible you picked that up.

  9. amittleider commented on Sep 11, 2018

    @amittleider
    Author

    Brett Cannon (@brettcannon) Sorry for the delayed response. To your question about my workspaces, yes, I am trying to jump across workspaces. The reason I need this is complicated, but in short it's because my tests are not discovered by VSCode otherwise.

    However, I have done an experiment to see if it's related to my workspaces. I have tried to reduce all my workspaces down to one folder (the parent folder), and I still have the problem. Therefore, I don't strongly suspect it's due to my workspace configuration.

    Here are the before and after workspace configurations.

    Before:

    {
    	"folders": [
    		{
    			"path": "walnut-finance/backtest"
    		},
    		{
    			"path": "walnut-finance/common"
    		},
    		{
    			"path": "walnut-finance/dataviz"
    		},
    		{
    			"path": "walnut-finance/docker"
    		},
    		{
    			"path": "walnut-finance/live"
    		},
    		{
    			"path": "walnut-finance/mkdata"
    		},
    		{
    			"path": "walnut-finance/ml"
    		},
    		{
    			"path": "walnut-finance/reporting"
    		},
    		{
    			"path": "walnut-finance/trading"
    		}
    	],
    	"settings": {}
    }
    
    

    After:

    {
    	"folders": [
    		{
    			"path": "walnut-finance"
    		}
    	],
    	"settings": {}
    }
    
  10. locked as resolved and limited conversation to collaborators on Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions