microsoft / python-language-server

Microsoft Language Server for Python
Apache License 2.0
912 stars 133 forks source link

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

Open ace-han opened 4 years ago

ace-han commented 4 years ago

Environment data

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" ] }

3. 
```python
# 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...
  3. put the cursor on the word mixins or CreateModelMixin or any super class and then press F12 ( go to definition )
  4. you will go no where
  5. especially GenericViewSet is right on the same file!

Snapshots image

image

mozkileo commented 4 years ago

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

MikhailArkhipov commented 4 years ago

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

ace-han commented 4 years ago

@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