krumpelstiltskin
krumpelstiltskin

Reputation: 536

How can I goto a function definition imported from another file using jedi-vim?

I regularly use <leader>d to go to a function definition. When this definition is from another file, it brings me to the import line of the file.

How can I use jedi-vim to go to the file that defines the function imported on that line?

Upvotes: 1

Views: 2553

Answers (1)

George Hilliard
George Hilliard

Reputation: 15952

It sounds like there is something wrong with your configuration... Double check that your filetype is indeed python. This should work, according to the documentation:

5.2. g:jedi#goto_command

Function: jedi#goto()

Default: <leader>d

Go to definition (or assignment)

This function first tries jedi#goto_definitions, and falls back to jedi#goto_assignments for builtin modules. It produces an error if nothing could be found. NOTE: this implementation is subject to change. Ref: https://github.com/davidhalter/jedi/issues/570

This command tries to find the original definition of the function/class under the cursor. Just like the jedi#goto_assignments() function, it does not work if the definition isn't in a Python source file.

The difference between jedi#goto_assignments() and jedi#goto_definitions() is that the latter performs recursive lookups. Take, for example, the following module structure:

# file1.py:
from file2 import foo

# file2.py:
from file3 import bar as foo

# file3.py
def bar():
    pass

The jedi#goto_assignments() function will take you to the

from file2 import foo

statement in file1.py, while the jedi#goto_definitions() function will take you all the way to the

def bar():

line in file3.py.

Upvotes: 3

Related Questions