Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
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

Closed

Description

Environment data

  • VS Code version: 1.29.1
  • 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:

  1. Make new file, test.py
  2. paste the following:
def iadd_no_overflow(a, b):
    """Perform `a += b` on integer numpy arrays without overflowing"""
    dest += src
    dest[dest < src] = np.iinfo(dest.dtype).max

Note the file is dirty (not saved). The same happens if the file is saved.

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

Activity

  1. james-rose commented on Dec 12, 2018

    @james-rose

    Same problem for me, macOS Mojave 10.14.1, VS Code 1.29.1, conda 3.6.6

  2. MikhailArkhipov commented on Oct 11, 2019

    @MikhailArkhipov

    In the fragment above dest is undefined. The code below works OK. Closing.

    dest = 1
    def iadd_no_overflow(a, b):
        """Perform `a += b` on integer numpy arrays without overflowing"""
        dest += src
        dest[dest < src] = np.iinfo(dest.dtype).max
  3. cipri-tom commented on Oct 21, 2019

    @cipri-tom
    Author

    Ahh, nice catch 🎉 ! Thank you for the insight!!

    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?

  4. jakebailey commented on Oct 21, 2019

    @jakebailey
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions