4

I am using jedi via YCM in vim and an seeing some weird behavior in my project, regarding using the usages endpoint on the jediHttp server. Basically it only finds a small fraction of the usages in my project of a class or function. It does find all the usages in the current file, but does not find the vast majority in other files. The GoTo command works fine and will open a new buffer anywhere in the project as expected. However when I start at the definition and try to see all the usages via the GoToReferences command it only produces about 20% of the actual usages.

I have tried making a dummy project to recreate the behavior and it seems to have worked. Here is the simple project structure:

> tree -I __pycache__
.
├── setup.py
└── test_jedi
    ├── classes.py
    ├── __init__.py
    ├── mod1
    │   ├── __init__.py
    │   └── recessed.py
    └── script.py

2 directories, 6 files

Here are the contents of those files:

classes.py

class Foo:
    def __init__(self, a):
        self.a = a

    def make_a(self):
        print('hello')

mod1/recessed.py:

from test_jedi.classes import Foo

Foo(5).make_a()
print('Ran this')

script.py:

from classes import Foo
a = Foo(5)
a.make_a()

Now from within vim with recessed.py in the buffer I am able to use GoTo on Foo to immediately open a classes.py buffer. When I then try GoToReferences from the classes.py buffer I only get the usages in script.py and in classes.py. I am at a loss to why jedi does not show me the usage in recessed.py

This is the quickfix buffer that shows:

classes.py|2 col 7| class Foo
script.py|2 col 21| from classes import Foo
script.py|5 col 5| a = Foo(5)

But clearly there is no reference to mod1/recessed.py which clearly has a usage of Foo.

Any ideas?

dave
  • 897
  • 1
  • 7
  • 20

2 Answers2

3

I understand that this question is 1.5 years old, but for the sake of people who landed on this question like me, it's related to a currently open issue in Jedi.

Jedi script.usages is used by YouCompleteMe in their GoToReferences function. However, the script.usages is buggy in a lot of places, according to the author. He is very well aware of the issue, but it is low-priority as of the moment.

Link to the issue

DeanK
  • 344
  • 2
  • 14
  • Thank you for this. This was driving me nuts. I am amazed how there seem to be next to none discussions regarding this. How am I supposed to know that I should not use GoToReferences? I have probably broken someone else's code at this point and had no clue about it :( – Tushar Vazirani Dec 06 '21 at 19:30
0

Not sure if helpful, but I see many more usages when I use the base jedi-vim plugin's "leader n" command.

Try loading both plugins like me and instead of using GoToReferences in YCM when finding usages, just use jedi-vim's find usages.

mwco
  • 1
  • 1