简体   繁体   English

JS 中的 VS Code 重构似乎在未打开的文件中不起作用

[英]VS Code refactoring in JS doesn't seem to work in unopened files

When trying to refactor function names, variable names, or class names within all files using F2 (as shown at https://code.visualstudio.com/docs/editor/refactoring#_rename-symbol ), I only seem to have success when those other files are open in the editor.当尝试使用 F2 重构所有文件中的 function 名称、变量名称或 class 名称时(如https://code.visualstudio.com/docs/editor/refactoring#_rename-symbol所示),我似乎只有在那些其他文件在编辑器中打开。 If they're closed, VS Code won't rename those instances.如果它们已关闭,VS Code 将不会重命名这些实例。 Am I missing something?我错过了什么吗?

Before rename with files closed:在关闭文件重命名之前:在此处输入图像描述

After rename with files closed:重命名并关闭文件后:在此处输入图像描述

Before rename with files open:在打开文件重命名之前:在此处输入图像描述

After rename with files open:打开文件重命名后:在此处输入图像描述

I tried looking into settings for refactor or replace, but didn't find anything that wasn't enabled that obviously should be.我尝试查看重构或替换的设置,但没有发现任何显然应该启用但未启用的内容。 If I successfully rename something when a file is open, undo it, then close the file and re-attempt the refactor, it fails again.如果我在文件打开时成功重命名某些内容,撤消它,然后关闭文件并重新尝试重构,它再次失败。

EDIT: I submitted this as a bug to the vscode team on github: https://github.com/microsoft/vscode/issues/146120编辑:我在 github 上将此作为错误提交给 vscode 团队: https://github.com/microsoft/vscode/issues/146120

Thanks to Andrii Dieiev on Github.感谢 Github 上的 Andrii Diieev。

https://github.com/microsoft/vscode/issues/146120#issuecomment-1079793615 https://github.com/microsoft/vscode/issues/146120#issuecomment-1079793615

Adding a basic jsconfig.json file is enough to ensure all files in our project are interpreted as part of the workspace:添加基本的 jsconfig.json 文件足以确保我们项目中的所有文件都被解释为工作区的一部分:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6"
  },
  "exclude": ["node_modules"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM