python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

Go to definitions not working in `djangorestframework` or some 3rd party packages

Open ace-han opened this issue 5 years ago • 3 comments

Environment data

  • VS Code version: 1.45.0 (should be any though)
  • Extension version (available under the Extensions sidebar): 2020.5.78807 (should be any though)
  • OS and version: Darwin x64 19.4.0 (should be any though)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6+ (should be any though)
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A, pipenv, poetry
  • Relevant/affected Python packages and their versions: djangorestframework==3..10+ (should be any though)
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info microsoft/vscode-python#3977): "python.jediEnabled": false
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

can go to definition

Actual behaviour

can NOT go to definition

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. pip install django djangorestframework
  2. setup .vscode/settings.json and extensions.json
// settings.json
{
    "python.pythonPath": "~/.local/share/virtualenvs/dv-r7UhNc7L/bin/python", // to your python path where djangorestframework lives, to make sure djangorestframework can be referred in python `sys.path`
    "python.jediEnabled": false,
    "vsintellicode.python.completionsEnabled": true
}

// extensions.json
{
    "recommendations": [
        "ms-python.python",
        "visualstudioexptteam.vscodeintellicode"
    ]
}
# in any views.py (common django concept)
from rest_framework.viewsets import ModelViewSet
class AnyViewSet(ModelViewSet):
    pass
  1. put the cursor on the word ModelViewSet and then press F12 ( go to definition )
  2. then you will go to rest_framework/viewsets.py@ModelViewSet definition
# rest_framework/viewsets.py
# other code...
class ModelViewSet(mixins.CreateModelMixin,
                   mixins.RetrieveModelMixin,
                   mixins.UpdateModelMixin,
                   mixins.DestroyModelMixin,
                   mixins.ListModelMixin,
                   GenericViewSet):
    """
    A viewset that provides default `create()`, `retrieve()`, `update()`,
    `partial_update()`, `destroy()` and `list()` actions.
    """
    pass
# other code...
  1. put the cursor on the word mixins or CreateModelMixin or any super class and then press F12 ( go to definition )
  2. you will go no where
  3. especially GenericViewSet is right on the same file!

Snapshots image

image

ace-han avatar May 15 '20 10:05 ace-han

I have the same problem and fixed this by enable python.analysis.memory.keepLibraryAst and python.analysis.memory.keepLibraryLocalVariables in settings.

mozkileo avatar May 31 '20 16:05 mozkileo

Yes, those the the settings. By default they are off for memory savings.

MikhailArkhipov avatar May 31 '20 18:05 MikhailArkhipov

@Mozkileo these two settings work like a charm!!!

@MikhailArkhipov I think this should be mentioned somewhere in the doc since some dev like me, prefers debuging while coding

ace-han avatar Jun 01 '20 02:06 ace-han