Python-language-server: use ctrl + click jump to definition as deep as pycharm can do

Created on 26 May 2020  路  6Comments  路  Source: microsoft/python-language-server




Vscode can't jump to definition as deep as pycharm can do.

For example:

from django.shortcuts import render

when i use 'ctrl + click' on "render", it can jump to the render function, but when
i click the method "render_to_string()" inside render function, it can not jump to definition any more, the following is the code snippet:

def render(request, template_name, context=None, content_type=None, status=None, using=None):
    content = loader.render_to_string(template_name, context, request, using=using)
    return HttpResponse(content, content_type, status)

Second example:

import requests
res = requests.get('https://www.google.com')

when i use 'ctrl + click' on "get()", it can jump to the get() function, but when
i click the method "setdefault()" or "request()" inside get() function, it can not jump to definition any more, the following is the code snippet:

def get(url, params=None, **kwargs):
    kwargs.setdefault('allow_redirects', True)
    return request('get', url, params=params, **kwargs)

But when i use pycharm, it can jump to the definition of "render_to_string()" function. So everytime i want to dive into code definition, I must toggle between vscode and pycharm, I feel shame vscode does not have this function. If this extension can add this feature, it would be great!

Most helpful comment

This is expected behavior for performance reasons. Try setting the setting in this comment and see if it works.

https://github.com/microsoft/python-language-server/issues/840#issuecomment-600907450

All 6 comments

This is expected behavior for performance reasons. Try setting the setting in this comment and see if it works.

https://github.com/microsoft/python-language-server/issues/840#issuecomment-600907450

@jakebailey
Thanks for your help, its useful!

@jakebailey I have enabled jedi, but its hard to use, because sometimes it need much time to load the other module when i click 'go to definition'.

Did you try setting

"python.analysis.memory.keepLibraryAst": true

Yes, i have enabled the following:

{"python.analysis.memory.keepLibraryAst": true,
"python.analysis.memory.keepLibraryLocalVariables": true,}

@MikhailArkhipov Even though I have jumped into the code definition, when I try to enter again, it is still very slow, as shown in the following:

vscode-debug4

Was this page helpful?
0 / 5 - 0 ratings