You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Rename variable sometimes fails when using the LanguageServer #1393
Extension version (available under the Extensions sidebar): 2018.11.0
OS and version: macOS Mojave 10.14.1
Python version (& distribution if applicable, e.g. Anaconda): python 3.6.4 64-bit conda
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
Relevant/affected Python packages and their versions:
Microsoft Python Language Server version 0.1.60.0
Steps to reproduce:
Make new file, test.py
paste the following:
defiadd_no_overflow(a, b):
"""Perform `a += b` on integer numpy arrays without overflowing"""dest+=srcdest[dest<src] =np.iinfo(dest.dtype).max
Note the file is dirty (not saved). The same happens if the file is saved.
Place cursor on dest and hit F2 or choose Rename symbol. Enter a as name.
Expected behaviour
All occurences of dest are changed into a
Actual behaviour
Got a tooltip Cannot rename, and an error in the Output window:
Logs
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
Starting Microsoft Python language server.
Microsoft Python Language Server version 0.1.60.0
Initializing for /Users/ciprian/miniconda3/bin/python
[Error - 12:12:43 PM] Request textDocument/rename failed.
Message: Cannot rename
Code: -32000
at Microsoft.Python.LanguageServer.Implementation.Server.Rename(RenameParams params, CancellationToken cancellationToken)
at Microsoft.Python.LanguageServer.Implementation.LanguageServer.Rename(JToken token, CancellationToken cancellationToken)
Output from Console under the Developer Tools panel (toggle Developer Tools on under Help):
Nothing. I mean, there are some ERR but from before. I put a console.log and then reproduce the error and nothing new appears in the console.
The thing is, I want to change all instances of dest into a, and all instances of src into b, so of course it is undefined :)
Am I abusing some refactoring powers? I'm not sure why renaming needs correct code. Does it use the syntax in order to modify only in the correct scope?
As a potential improvement, can we have some more verbose output instead of the Cannot rename message?
Our analysis is powered by tracking variable assignments. Uses of variables that don't exist (have assignments) means that there's no current way to identify that some variable is the same as another, where it comes from, etc, as the variable doesn't "exist" except as a lookup that fails. Feasibly, we could try and use scope information to track which undefined variables are in use, but generally it complicates things.
Activity
james-rose commentedon Dec 12, 2018
Same problem for me, macOS Mojave 10.14.1, VS Code 1.29.1, conda 3.6.6
pjpjq commentedon Jul 19, 2019
Same problem: https://stackoverflow.com/questions/57105741/vs-code-how-to-find-all-references-of-a-variable-in-python/57106547#57106547. Any fixes?
MikhailArkhipov commentedon Oct 11, 2019
In the fragment above
destis undefined. The code below works OK. Closing.cipri-tom commentedon Oct 21, 2019
Ahh, nice catch 🎉 ! Thank you for the insight!!
The thing is, I want to change all instances of
destintoa, and all instances ofsrcintob, so of course it is undefined :)Am I abusing some refactoring powers? I'm not sure why renaming needs correct code. Does it use the syntax in order to modify only in the correct scope?
As a potential improvement, can we have some more verbose output instead of the Cannot rename message?
jakebailey commentedon Oct 21, 2019
Our analysis is powered by tracking variable assignments. Uses of variables that don't exist (have assignments) means that there's no current way to identify that some variable is the same as another, where it comes from, etc, as the variable doesn't "exist" except as a lookup that fails. Feasibly, we could try and use scope information to track which undefined variables are in use, but generally it complicates things.