Visual Studio Code (Mac OS) rename symbol doesn't work
Asked Answered
U

5

38

When I right click and try to rename a variable name in Microsoft Visual Studio Code on Mac OS Mojave, it prompts for the new name, I hit enter and nothing happens.

I have Python extension and Latex extension installed.

Usually there are no errors, no nothing.

Sometimes, there's a little box that pops up saying "No Result. No Result".

The python interpreter I selected was a Conda install.

I ensured rope, and pylint were installed.

Expected behaviour: right click > rename symbol > type new name > enter > all instances of variable renamed.

Observed behaviour right click > rename symbol > type new name > enter > variable has same name everywhere, including spot of renaming.

Unique answered 6/3, 2019 at 6:46 Comment(1)
I filed github.com/microsoft/vscode-python/issues/14363Decrepitude
U
28

It turns out the solution was simple, but frustrating. To do refactoring in VS Code (at least for python) you need to be in a workspace.

I solved the problem by first closing the open folder I was in:

File > Close Folder.

then navigating to a sub folder of .py file I was editing, and opening it. In my case it was

  1. Click the little document icon in the upper left of screen
  2. In the welcome screen, choose "open folder"
  3. navigate to my desktop folder (where my .py file is)

Now refactoring works as expected

Click on file icon in upper left of screen > in the welcome screen

Unique answered 6/3, 2019 at 6:51 Comment(2)
One more variation: Although I was already in a Workspace, it was untitled. Once I saved it with a name, refactoring worked.Expostulate
There is this key combination which is called 'rename symbol', but that's not working even when in a workspace. I'm using intelliSense by Microsoft for C/C++Letendre
G
6

I use Pylance with a workspace and had the same issue. For me the solution was to restart the language server (from the Command Palette). I find it faster than closing and opening the folder.

Ctrl+Shift+P > Python: Restart Language Server

Guardado answered 13/4, 2021 at 13:32 Comment(0)
H
2

Choosing a folder did not solve the issue for me. I switched to a new language server called Pylance and everything works fine now.

Hirst answered 22/11, 2020 at 14:55 Comment(1)
Run into same issue, mine was using Jedi python language server and it is the default setting. It appears that is the cause of renaming issue. After googling for awhile, finally decided to try a different language server, and Pylance worked.Veriee
A
0

I just found out that if you use Pylance (Pyright) and have a pyrightconfig.json or a [tool.pyright] section in pyproject.toml, this can cause refactoring to fail.

In my case I had not put the localtion of the script into the include array in pyproject.toml so it was giving the "No results" error.

Aluminate answered 2/7, 2021 at 3:19 Comment(0)
P
0

In my case the solution was to reset the Python Language Server setting:

"python.languageServer": "Default",
Pelf answered 6/4, 2022 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.