python-language-server
python-language-server copied to clipboard
"Find All References" does NOT find all references
It's actually quite dangerous to rely on "Find All References" when refactoring code since it doesn't really return all references. I think this feature should be turned off until it's fixed because it's currently straight up misleading.
- VSCode Version: 1.36.1
- OS Version: macOS 10.14.5
- Python version : 3.7.2
- Type of virtual environment used : pyenv via pipenv
- Relevant/affected Python packages and their versions: N/A
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
): Language Server ("python.jediEnabled": false
)
Expected behaviour
All results are found
Actual behaviour
Only some results are found
Steps to reproduce:
- ctrl-click a (python) function, say
perform_job()
to open the contextual menu - Hit "Find All References"
- You will get X results
- Now run a separate query "Search in Files" query for
perform_job
- You will often get more results
I've tested it against PyCharm to make sure I wasn't doing something wrong with my own code, Pycharm did actually find all references.
Could you give a specific code example when references are missing?
Also experiencing this issue. Have disabled jedi everywhere.
If you have this issue, please provide a test project we can look at to try and reproduce with, otherwise we don't have anything to go off of.
Can't share work code and haven't been able to duplicate it with a simple example. Removed any workspace settings and still had the issue.
So I guess I have a couple of questions. It doesn't seem like finding all references is a feature that exists by default, need to install the python MS package, no big deal. I guess I was also expecting to be able to use find all references on the function definitions and not just the lines where it's used. Why can't you right-click on the function def and show references of it... seems like a bug.
You should be able do that; that's the intention of the feature. The language server should allow you to do this, and it is a bug if it cannot.
From our knowledge, it does work, but if it doesn't we need to have code that shows a case of it not working in order to fix it (if we had come up with cases that didn't work, we would have reported/fixed them).
hi @jakebailey I've bumped into this annoying thing myself. Not sure how it relates to the above but I've got a simple setup that should demonstrate the issue: https://github.com/totallyzen/vscode-find-references-issue
In my case the "Find References" did not work when I had initiated the search from an __init__.py
I hope this helps!
In terms of my environment:
- Was using
pyenv
myself with a global3.7.0
OS+VSCode:
Version: 1.39.2
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:33:00.827Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Darwin x64 18.7.0
I'm seeing this behavior as well -- on a private repo that I cannot share the full details, but I found what I believe may be related to the issue.
Here's a simulation of the folder structure
src/foo/bar/lib/baz.py
src/foo/bar/plugins/foo.py
tests/foo/bar/lib/baz.py
where src/foo/bar/lib/baz.py
contains my_func
:
def my_func(foo, bar):
pass
and src/foo/bar/plugins/foo.py
contains:
from foo.bar.lib.baz import (
my_func,
)
and a call like
def baz():
my_func(foo)
and tests/foo/bar/lib/baz.py
contains:
from foo.bar.lib.baz import (
my_func,
)
and some tests like
class MyFunc(unittest.TestCase):
def test_a(self):
result = my_func(foo, bar)
self.assert ...
def test_b(self):
result = my_func(foo, bar)
self.assert ...
When performing "Find all References" on my_func
inside src/foo/bar/lib/baz.py
, only the references in the file itself, and the tests/foo/bar/lib/baz.py
are found -- the reference in src/foo/bar/plugins/foo.py
is not found.
The issue I discovered seems to be because the invocation in src/foo/bar/plugins/foo.py
is using the incorrect method signature (it's providing only 1 argument, instead of 2).
Once I correct this, then performing "Find all References" surfaces the call in src/foo/bar/plugins/foo.py
I'm not sure if this is intended behavior. I would expect, especially during refactoring, that my IDE will find any references to the function call, regardless of if it's providing the correct number of arguments -- as this is often a situation that arises when you're refactoring and need to clean up all the calls to the function.
I just ran into this issue where references to a function inside the tests/
folder do not show up when "Find all references" is invoked.
Right click "Find all references":
user is wondering for some time... I thought I was using this funciton somewhere...
the user tries using search instead:

This is a public repo, in case you want to try to reproduce:
https://github.com/learningequality/pressurecooker/blob/master/pressurecooker/youtube.py#L235-L247
Perhaps some config/setting is ignoring the tests dir? Definitely unexpected though, since using "Find all references" is my main reason for using an IDE (I'm a recent convert from basic editors, and now my trust is partially eroded by this bug ;)
Version: 1.43.0 Commit: 78a4c91400152c0f27ba4d363eb56d2835f9903a Date: 2020-03-09T19:34:44.548Z Electron: 7.1.11 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Darwin x64 17.5.0 ms-python.python extension: Version: 2020.2.64397
Same issue in find all references, this issue haven't fixed for serval months...