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

Some references or definitions are not found

Open Tuzoff opened this issue 5 years ago • 19 comments

Environment data

  • VS Code version: Code 1.39.2 (6ab5985, 2019-10-15T15:33:00.827Z)
  • Extension version (available under the Extensions sidebar): 2019.10.41019
  • OS and version: Darwin x64 19.0.0 (remote OS Linux x64 4.15.0-43-generic)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.5.2 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: N/A
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info microsoft/vscode-python#3977): Jedi

Expected behaviour

Finds all references/definitions using Peek..., Find... or Go to... tools

Actual behaviour

Some of the references/definitions are missing though they are easily found in the code

Steps to reproduce:

  1. Open a project by someone who can't really code and try to make sense of it
  2. For some names choose either of Peek Reference or Definition, Find All References or Go to Definition
  3. Some of the references/definitions are missing though they are easily found in the code

Tuzoff avatar Oct 22 '19 20:10 Tuzoff

Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can.

brettcannon avatar Oct 24 '19 16:10 brettcannon

@Tuzoff Can you try using Language Server? Jedi mostly provide auto completion and static analysis. It does not do so well when it come to references.

karthiknadig avatar Oct 28 '19 17:10 karthiknadig

In the last few weeks (maybe longer?), while using the Language Server, I have noticed a similar problem with at least three symbols in my code. This bug also seems to be affecting "Rename Symbol", not all symbols will be renamed.

I composed a simple script that will recreate the reference bug for one of these symbols:

class SomeClass(object):

    def __init__(self):
        self.h = [0,1]
     
    def a(self):
        self.h[1] = 0

    def r(self):
        self.h[1] = 0

Once you have entered the code into VS Code Python, do the following:

Select first or second occurrence of self.h, then do 'Peek References', only two references will be found. Select third occurrence of self.h, do 'Peek References', all three references will be found! Now, go back and select first or second occurrence of self.h, all three references will be found! Next, make some textual modification to the code (i.e. add an extra space between an equals sign and a 0). Finally, repeat the first instruction at the beginning of this paragraph. You should only see two references.

greggaree avatar Nov 02 '19 22:11 greggaree

@karthiknadig Why is the "info needed" label still attached to this issue? My previous comment confirms this problem exists while using the Language Server.

My environment data:

  • VS Code Version: 1.39.2
  • Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
  • Date: 2019-10-15T15:33:40.634Z
  • Electron: 4.2.10
  • Chrome: 69.0.3497.128
  • Node.js: 10.11.0
  • V8: 6.9.427.31-electron.0
  • Python Language Server version: 0.4.71.0
  • Extension version (available under the Extensions sidebar): 2019.10.44104
  • OS: Ubuntu Mate 18.04 LTS (Linux x64 4.15.0-66-generic)
  • Python version: 3.6.8 64-bit
  • Type of virtual environment used: none
  • Relevant/affected Python packages and their versions: N/A
  • Jedi or Language Server: Language Server (python.jediEnabled = False)

greggaree avatar Nov 06 '19 00:11 greggaree

@greggaree sorry about the delayed response. Moving this to the LS repo.

karthiknadig avatar Nov 06 '19 04:11 karthiknadig

@MikhailArkhipov, @jakebailey any thoughts on this issue?

This issue occurs when the language server is enabled. See my previous posts for the language server version and a test case that reproduces the bug.

I have only seen this issue occur when searching for two types of references:

  • state variables that were defined within classes (i.e. self.some_variable)
  • 'static' variables that were defined within classes (i.e. SomeClass.variable)

I don't seem to have any problem finding all references for globally defined variables.

When running my previously posted test case in PyCharm and WingIDE, I had no missing references.

Shouldn't this issue be labelled as a bug?

greggaree avatar Nov 07 '19 14:11 greggaree

This issue was just transferred to us, we haven't yet had time to look into it to say where the bug may be or if it's a known issue with class scoping and references.

jakebailey avatar Nov 07 '19 17:11 jakebailey

In the settings.json file, when I change python.jediEnabled to true, VS Code features like peek references, rename, etc. will once again find all references.

I did some research online and discovered a StackOverflow posting from Jul 19 2019 about the same issue as I have. The SO poster noticed that VS Code has trouble finding class based references.

@brettcannon responded to the SO post, and he said some related issues had been posted at python language server. One or both of those related issues may have been fixed, but it doesn't resolve the issue I or the SO poster have been experiencing.

This seems to deserve a bug label.

I do a lot of refactoring and renaming as part of my work. So not having to switch between jedi.enabled false/true, reloading Python Extension, etc. would save me a lot of time.

I noticed the current assignee to this issue, @karthiknadig, belongs to the vs-code-python repo. Shouldn't this issue be assigned to someone from python-language-server repo?

greggaree avatar Nov 21 '19 16:11 greggaree

Similar issue

1. Reproduce Progress

  1. input code on vscode

    1. from asyncio.base_events import tasks
      
  2. hover upon base_events, right click -> go to definition

  3. goto success

  4. find the line in base_events.py maybe at line 37

    1. from . import constants
      
  5. hover upon constants, right click -> go to definition

  6. goto failed

    1. no new logs in output or devtools console

2. Discovery

  1. I found that lsp analysis will not work on the base_events.py file opened by go to definition
  2. But, lsp will work on the base_events.py if opened at first (before startup)
    1. open this file, reload vscode
    2. Then go to definition worked

3. Question

Will LSP analysis work on files opened by go to definition ?

PS: I checked some files opened after background analysis, goto def didn't work either... But jedi will work well for new opened files.

BTW, is there a way reload language server for analysis of the new open files? Switching python interpreter will make sense, any others?


New solution: killing Microsoft.Python.LanguageServer.exe and waiting for its restarting, will give a hand.

ClericPy avatar Feb 08 '20 08:02 ClericPy

I've noticed that imported symbols in non-empty __init.py__ files don't seem to be detected.

"""
./
    src/
        __init__.py
        foo.py
    main.py
"""

# src/foo.py
def bar(x):
    pass

# src/__init__.py
from foo import bar

# ./main.py
from src import bar

# bar is not found by language server!

YodaEmbedding avatar Feb 26 '20 10:02 YodaEmbedding

If you use bar in some way (like adding print(bar)), is the reference found then?

jakebailey avatar Feb 26 '20 17:02 jakebailey

My bad. __init__.py should have said from src.foo import bar or from .foo import bar. What I posted is not valid python. Please disregard.

YodaEmbedding avatar Feb 27 '20 09:02 YodaEmbedding

Might be regression per #1988

MikhailArkhipov avatar Apr 17 '20 22:04 MikhailArkhipov

Should the guys from vscode-python be involved here? This bug is 6 months old and very ugly for a python developer.

PhilipMay avatar Apr 21 '20 20:04 PhilipMay

It has nothing to do with the extension, just LS bug.

MikhailArkhipov avatar Apr 21 '20 20:04 MikhailArkhipov

Hi, any progress on this ugly bug?

PhilipMay avatar Jun 12 '20 19:06 PhilipMay

I think the solution might be to revert the PR in question. I looked into it and I am not sure the issue can be fixed with that PR.

MikhailArkhipov avatar Jun 12 '20 19:06 MikhailArkhipov

@MikhailArkhipov could you please try your solution and - if it works - fix it? This bug destroys an elementary functionality to do python programming IMO. It would be really nice to have it fixed.

PhilipMay avatar Jun 14 '20 09:06 PhilipMay

PR is up.

MikhailArkhipov avatar Jun 16 '20 02:06 MikhailArkhipov