python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

"Find All References" does NOT find all references

Open SHxKM opened this issue 5 years ago • 11 comments

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:

  1. ctrl-click a (python) function, say perform_job() to open the contextual menu
  2. Hit "Find All References"
  3. You will get X results
  4. Now run a separate query "Search in Files" query for perform_job
  5. 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.

SHxKM avatar Aug 06 '19 13:08 SHxKM

Could you give a specific code example when references are missing?

MikhailArkhipov avatar Aug 19 '19 23:08 MikhailArkhipov

Also experiencing this issue. Have disabled jedi everywhere.

afreepenguin avatar Oct 21 '19 20:10 afreepenguin

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.

jakebailey avatar Oct 21 '19 20:10 jakebailey

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.

afreepenguin avatar Oct 21 '19 20:10 afreepenguin

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.

afreepenguin avatar Oct 21 '19 22:10 afreepenguin

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).

jakebailey avatar Oct 21 '19 23:10 jakebailey

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!

totallyzen avatar Oct 28 '19 17:10 totallyzen

In terms of my environment:

  • Was using pyenv myself with a global 3.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

totallyzen avatar Oct 28 '19 17:10 totallyzen

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.

eedwards-sk avatar Nov 21 '19 18:11 eedwards-sk

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": Screen Shot 2020-03-11 at 8 37 57 PM

user is wondering for some time... I thought I was using this funciton somewhere...

the user tries using search instead:

Screen Shot 2020-03-11 at 8 38 12 PM

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

ivanistheone avatar Mar 12 '20 00:03 ivanistheone

Same issue in find all references, this issue haven't fixed for serval months...

baiyongrui avatar May 19 '20 01:05 baiyongrui