5

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.

4
  • I tried and found no problem. Can you provide more picture descriptions and tips given by vscode Commented 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? Commented 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 python Commented 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. Commented Dec 3, 2024 at 17:56

1 Answer 1

1

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.

https://user-images.githubusercontent.com/54879025/172922141-af06b870-1d61-4b06-9a6c-d3d7fe00d605.gif

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+P or Cmd+Shift+P on 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 Pylance is set as your language server in VSC settings:
    {
        "python.languageServer": "Pylance"
    }
    
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Moreover, Refactor with Preview doesn't exist in my command palette.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.