I wanted to rename a module in a Python project, however I would then need to update all the imports to match. The VSC Python extension has a clearly documented feature that should do this listed here: https://code.visualstudio.com/docs/python/editing#_rename-module, however when renaming the module by clicking on it and hitting F2, no such Refactor Preview tab appears. Extract Method and Extract Variable work normally. I'm having trouble finding a relevant setting to toggle and think I may be missing something obvious. I already updated VSC to 1.66 (March 2022 update) and the Python extension to v.2022.4.0 and am feeling thoroughly baffled.
-
I tried and found no problem. Can you provide more picture descriptions and tips given by vscodeMingJie-MSFT– MingJie-MSFT2022-04-04 06:26:34 +00:00Commented Apr 4, 2022 at 6:26
-
I updated my Python extension to the pre-release version (v2022.5.10911002), and now renaming a module will rename said module in other python files in the project without asking or showing the preview tab like the documentation shows. The re-named files appear as unsaved, recently edited tabs in the editor. I'm wondering what version you happen to be on, @MingJie?Kokonoe– Kokonoe2022-04-04 13:50:45 +00:00Commented Apr 4, 2022 at 13:50
-
My python version is the same as you. I've tried, but as the video in the document depicts, there's no problem. Can you show me some pictures to let me know what's wrong with your pythonMingJie-MSFT– MingJie-MSFT2022-04-06 02:16:18 +00:00Commented Apr 6, 2022 at 2:16
-
I have the exact same problem, came here looking for an answer... :'( For me, it happens in a .py file. I have an Apple M2 with Sonoma 14.7.1, and VS about says: Version: 1.95.3. I only have Python, Pylance, and Python Debugger extensions active. I highlight a variable, press (command) F2, there is a little field which appears and promises me that I can preview after pressing command enter, but pressing it doesn't do anything. Changing the keybindings for refactorPreview.apply (which is listed under command enter) or its variants doesn't help.relatively– relatively2024-12-03 17:56:18 +00:00Commented Dec 3, 2024 at 17:56
Add a comment
|
1 Answer
Note that VSCode 1.69 (June 2022) will add a Refactoring Preview option in Command Palette (PR 151566), following the issue 151140 "Allow refactorings to be previewed": showPreview.
If showPreview was set to false, there would be no preview visible.
Official documentation: "Refactoring / Refactor Preview"
Can we set showPreview to true?
Yes, you can set it in the settings.json file:
- Open Command Palette (
Ctrl+Shift+PorCmd+Shift+Pon macOS). - Search for
Preferences: Open Settings (JSON). - Add:
{ "editor.refactorPreview": true }
You cannot directly toggle editor.refactorPreview from the Command Palette.
Refactor with Preview does not exist in my Command Palette
- Make sure you are using VSC 1.69 or later
- Make sure that
Pylanceis set as your language server in VSC settings:{ "python.languageServer": "Pylance" }
2 Comments
relatively
I do not see how this answers the question. Can we set showPreview to true? If so, how? Can one access this option in the Command Palette? If so, how? Somehow, your little clip doesn't enlighten me.
relatively
Moreover, Refactor with Preview doesn't exist in my command palette.
