admin管理员组文章数量:1401476
I'm migrating to VSCode from WebStorm (for work reasons). In WebStorm, when you rename a folder/file in the list of folders/files, it will refactor your code so that that folder or file name change is reflected everywhere it is imported.
That is, if I change a folder 'ponents' to 'ps' from within the file explorer, all lines in all files which referenced 'ponents', e.g. 'import XYZ from ../ponents/XYZ' will be changed to 'import XYZ from ../ps/XYZ'. Is there a way to enable this in VSCode (either natively or perhaps an extension)?
I'm migrating to VSCode from WebStorm (for work reasons). In WebStorm, when you rename a folder/file in the list of folders/files, it will refactor your code so that that folder or file name change is reflected everywhere it is imported.
That is, if I change a folder 'ponents' to 'ps' from within the file explorer, all lines in all files which referenced 'ponents', e.g. 'import XYZ from ../ponents/XYZ' will be changed to 'import XYZ from ../ps/XYZ'. Is there a way to enable this in VSCode (either natively or perhaps an extension)?
Share Improve this question asked Dec 19, 2018 at 16:33 CeruleanCerulean 6,03311 gold badges72 silver badges123 bronze badges2 Answers
Reset to default 7Yes, there is a setting and it works when renaming or moving files, but I'm not sure about directories.
On Windows you can access VSCode's Settings panel by pressing CTRL, simultaneously.
Then search the Settings for Update imports
and you should see something that looks like this:
It should be set to prompt by default when you move/rename a file.
Update: After some more tries, VS Code can actually rename paths after renaming folders. But it fails to do so sometimes. It will have some editor pop-out and it needs a little extra time to save the path change. Keep the editor open for a while to let the auto-refactoring finish.
I feel like it still does not support auto-refactoring of folder names until now.
But after enabling the settings of "Update Imports On File Move", it can be done by opening a new folder and moving files to the new folder (all paths can correctly refactor), instead of directly renaming the folder.
P.S. Sometimes the folder cannot auto-refactoring the correct path. Better close all opened files and consider moving files 1 by 1.
本文标签:
版权声明:本文标题:javascript - Visual Studio Code: Is there a way to automatically refactor JS imports when changing a directory (or file) name in 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744296838a2599382.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论