如何重构 Visual Studio 代码中的文件名?

How can I refactor file names in Visual Studio Code?

是否可以重构项目中的文件名并自动更新所有导入,而不用担心每次更改文件名时都会破坏某些东西?

与 JetBrains 产品中的方式相同。您更改文件名,所有内容都会自动更新。

抱歉,答案很简单:不,你不能。

至少目前没有。实现这些事情取决于语言模式的作者。这里和那里支持偶尔的变量重构…… JavaScript space 中有一些额外的扩展支持方法提取和内容,但其中 none 处理文件名重构。

其实你可以。本机在 Visual Studio 代码 (>= v1.28) 上 import path renaming:

或者像 Move TS 这样的扩展名。

使用 VSCode 1.53(2021 年 1 月)应该更容易:

Improved Refactor Participants UI

Extension can participant when use create, move, rename, or delete files.
This is useful to automatically run refactorings, e.g. when renaming a Java file you also need to rename its public class.

There is now unified UI for these participants which allows you to accept, skip, and preview additional changes an extension is making.