'vscode "no refactorings available" for python
Ctrl + alt + R for extension python.python 2020.1.58038 always gives me a "No refactorings available" message.
Probably a configuration issue but I've tried several times to uninstall/reinstall and restart vs code to no avail.
Thought maybe I was missing python-rope but python -m pip install --upgrade rope Requirement already up-to-date: rope in c:\users\cdoyle\appdata\roaming\python\python37\site-packages (0.16.0)
VS Code Version info : Version: 1.42.0 (user setup) Commit: ae08d5460b5a45169385ff3fd44208f431992451 Date: 2020-02-06T10:51:34.058Z Electron: 6.1.6 Chrome: 76.0.3809.146 Node.js: 12.4.0 V8: 7.6.303.31-electron.0 OS: Windows_NT x64 10.0.18362
Also I don't see any open issues https://github.com/Microsoft/vscode-python/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+refactoring
Not sure what to try next.
Thanks
Solution 1:[1]
I'm new to programming Python in VS Code and ran into the same problem. I successfully used the "Rename Symbol" command to rename a function and update all its references. More detail at https://code.visualstudio.com/docs/editor/refactoring . Hope this helps!
Solution 2:[2]
I would like to add further:
If you want to change a variable name / function name at one go, you can use "Rename Symbol" in VS Code editor by right clicking that particular name.
If your code has something related to both variable name and function name and you want to apply the change at both places, then you can use "Change all Occurrences".
Example of above-
test = "Hello"
def test_func():
print("World")
print(test)
test_func()
If i want to change variable "test" to "new" and function "test_func" to "new_func", i can use "Change all Occurrences". But if i want to change only say variable name, then i have too use "Rename symbol".
Solution 3:[3]
Visual Studio Code and its Python extension is (at the time of writing this) very limited when it comes to refactoring. Out of the box it provides two refactoring actions: Extract Method and Extract Variable. The reason you're seeing "No refactorings available" is because the currently selected text doesn't match any of these actions. Try selecting a line of text and then press [Ctrl][Shift][R].
Rope support was removed in VSCode in favour of Language Server Protocol integration which is used by their Pylance language server extension. Pylance is now installed automatically with vscode-python extension, and it's actively developed - maybe they will implement more refactorings in the future. If you're looking for more robust refactoring, check out PyCharm refactoring, it is currently much more sophisticated.
Solution 4:[4]
For Python 3.10.2 use right-click, Change All Occurrences (CTRL-F2) on VSCode version 1.65.2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jein |
| Solution 2 | Subhasish Paul |
| Solution 3 | Bartłomiej Fulanty |
| Solution 4 | Wayne Barrass-Brown |
