VSCode and TypeScript - refactoring/renaming without opening the affected files

Viewed 640

Using Visual Studio Code with a TypeScript application, is it possible to rename a variable/function without the affected files to be automatically open in the Editor area?

I'd like my refactorings to be automatically applied, the affected files immediately saved without being automatically open.

I know about the "files.autoSave" setting and, by using "afterDelay", I'm indeed able to refactore without the affected files to be automatically open. But I don't want to work with this setting on! Mostly because of linting, the auto saving of files is really annoying.

Any way to perform an immediate refactoring?

3 Answers

Maybe the new Rename preview feature of VSCode 1.42 (Q1 2020) would be an acceptable alternative (to opening the files)

Rename preview

VS Code now allows you to preview Rename changes.
When renaming, you can confirm a new name via kb(acceptRenameInputWithPreview) and the Refactor Preview panel shows.
It displays pending changes in a diff editor and allows you to uncheck/check individual changes.
Once the rename has been applied (or aborted), the diff editor and preview panel close, putting you back in the current editor.

Rename preview -- https://github.com/microsoft/vscode-docs/raw/vnext/release-notes/images/1_42/preview-rename-java.gif

VSCode 1.67 (Apr. 2022) will come with Save automatically when refactoring #47573:

Just like the feature "Save automatically when Search & Replace", after refactoring the code (by pressing F2 key or using context menu), the VS Code should save the file(s) automatically.

See PR 146320, available today with VSCode insider release.

files.refactoring.autoSave

Controls if files that were part of a refactoring are saved automatically.

Related