0

I'm trying to use Jedi to do "jump-to-definition". For example, if my cursor is on MLPClassifier, I want to be able jump to the place where that class is defined in Python code from the imported library sklearn.

The documentation and this post suggest that I should be able to do this by pressing "\d" while my cursor is on the function/class. However, this does not work.

I think Jedi is installed correctly because autocomplete suggestions seem to work (for example, typing np.arg pops up a menu with argmax, argmin, etc.). Curiously however, running :help jedi-vim gives me "E149: Sorry, no help for jedi-vim".


FYI about my setup:

  • I am not using a virtual environment. It's a system-level Python 3.9

  • I'm using Asynchronous Lint Engine (ALE) as my Language Server Protocol (LSP) client.

cd ~/.vim/pack/vendor/start/
git clone [email protected]:dense-analysis/ale.git
  • I'm using python-lsp-server as my LSP server. This uses Jedi internally for autocomplete and jump-to-definition.
pip install python-lsp-server
  • Here are my plugin-related variables in my .vimrc.
let g:ale_linters = {'python': ['pylsp']}
let g:ale_completion_enabled = 1
let g:ale_linters_explicit = 1
let g:ale_sign_column_always = 1
packloadall
silent! helptags ALL-
4
  • 1
    Welcome to Vim :-) Did you checked if \d jumping to definition of a custom function within your python script? Then you could verify that it works across two custom file linked with import. Jan 10, 2023 at 5:35
  • I suspect sklearn to be c code and that jedy can't find the definition. I'll test with coc and let you know. Jan 10, 2023 at 5:37
  • My assumption was wrong. I does work with coc and VsCode. Jan 10, 2023 at 6:57
  • \d seems to not work for me even for function definitions in the same file! Perhaps I am misinterpreting the docs.
    – efthimio
    Jan 10, 2023 at 17:28

2 Answers 2

0

I could reproduce your problem.

It seems to me that Jedi is able to find the definition of your project methods and functions but is not very good at finding the library definition.

I have a different experience with coc-nvim that I encourage your to try.

For Python you'll have to:

  1. Install coc and
  2. Install coc-pyright using the Vim command:
:CocInstall coc-pyright

With coc-pyright the gd command bring me successfully to the definition of sklearn.neural_network.MLPClassifier().

2
  • Thanks for putting effort to reproduce! (1) How were you able to jump-to-definition within the same project with the ALE setup? Even that doesn't work for me. (2) The jump functionality is one of the core selling points of pylsp/Jedi so I must be misinterpreting the docs or setup incorrectly. Any ideas?. I'm trying to avoid COC because it requires bloat in NodeJS & other dependencies. Also, I thought pyright was a type-checker, not autocompleter/definition-jumper?
    – efthimio
    Jan 10, 2023 at 17:27
  • I have a simple Jedi setup and no ALE setup and it works out od the box for me. But I don't recall if I had to install some Python dependencies. Jan 10, 2023 at 22:40
0

Given the setup with ALE/pylsp/Jedi, we can go to definition by moving a cursor over a function name and typing :ALEGoToDefinition -vsplit.

Notice that this is an ALE command as opposed to a Jedi command. I speculate that this is expected behavior because ALE is the LSP client, and therefore it probably must mediate any on-screen changes. If Jedi were installed on its own, I would expect that \d to work as stated in the Jedi docs.

Figuring out how the various plugins interact with each other via overlapping functionality can be very thorny.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.