Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Some references or definitions are not found #1754

Open
Tuzoff opened this issue Oct 22, 2019 · 19 comments
Open

Some references or definitions are not found #1754

Tuzoff opened this issue Oct 22, 2019 · 19 comments
Assignees

Comments

@Tuzoff
Copy link

Tuzoff commented Oct 22, 2019

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 How to update the language server to the latest stable version 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

@karthiknadig karthiknadig self-assigned this Oct 22, 2019
@brettcannon
Copy link
Member

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

@karthiknadig
Copy link
Member

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

@greggaree
Copy link

greggaree commented Nov 2, 2019

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
Copy link

greggaree commented Nov 6, 2019

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

@karthiknadig
Copy link
Member

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

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Nov 6, 2019
@greggaree
Copy link

@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?

@jakebailey
Copy link
Member

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.

@greggaree
Copy link

greggaree commented Nov 21, 2019

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?

@ClericPy
Copy link

ClericPy commented Feb 8, 2020

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.

@YodaEmbedding

This comment has been minimized.

@jakebailey
Copy link
Member

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

@YodaEmbedding
Copy link

YodaEmbedding commented Feb 27, 2020

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.

@MikhailArkhipov
Copy link

Might be regression per #1988

@PhilipMay
Copy link

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

@MikhailArkhipov
Copy link

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

@PhilipMay
Copy link

Hi, any progress on this ugly bug?

@MikhailArkhipov
Copy link

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.

@PhilipMay
Copy link

PhilipMay commented Jun 14, 2020

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

@MikhailArkhipov
Copy link

PR is up.

@MikhailArkhipov MikhailArkhipov self-assigned this Jun 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants