python-language-server
python-language-server copied to clipboard
Some references or definitions are not found
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:
- Open a project by someone who can't really code and try to make sense of it
- For some names choose either of Peek Reference or Definition, Find All References or Go to Definition
- Some of the references/definitions are missing though they are easily found in the code
Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can.
@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.
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.
@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 sorry about the delayed response. Moving this to the LS repo.
@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?
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.
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?
Similar issue
1. Reproduce Progress
-
input code on vscode
-
from asyncio.base_events import tasks
-
-
hover upon base_events, right click ->
go to definition
-
goto success
-
find the line in base_events.py maybe at line 37
-
from . import constants
-
-
hover upon constants, right click ->
go to definition
-
goto failed
- no new logs in output or devtools console
2. Discovery
- I found that lsp analysis will not work on the base_events.py file opened by
go to definition
- But,
lsp
will work on thebase_events.py
if opened at first (before startup)- open this file, reload vscode
- 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.
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!
If you use bar
in some way (like adding print(bar)
), is the reference found then?
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.
Might be regression per #1988
Should the guys from vscode-python be involved here? This bug is 6 months old and very ugly for a python developer.
It has nothing to do with the extension, just LS bug.
Hi, any progress on this ugly bug?
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 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.
PR is up.