英文:
vscode: Move Go code (type/function) to other file
问题
在VSCode中如何将一个函数/类型从一个Go文件移动到另一个Go文件?
...并且IDE应该更新所有使用了移动的函数/类型的地方...
在过去,我使用Python和PyCharm,它支持这种重构操作。
英文:
How to move a function/type from one Go file to an other Go file in vscode?
... and the IDE should update all usages of the moved function/type ...
In the past I used Python and PyCharm, and it supported this kind of refactoring.
答案1
得分: 2
看起来在VSCode中还没有实现这个功能(移动重构)。我能想到的唯一解决方法是使用gomvpkg
命令将包移动到新的位置。通过这种方式,如果你只有一个文件中的函数,那么应该可以顺利进行移动。它还应该更新import
语句(无论如何,请确保仔细检查它们)。我知道这很无聊,实际上我也一直在不同包之间复制/粘贴函数,因为这样更快。
> 看起来Goland已经支持这个功能,如果你愿意的话可以试试。
请告诉我你的想法!
英文:
It seems that this feature (the move-refactoring) hasn't been implemented in VSCode yet. The only workaround that just came into my mind is this.
You can use the cmd gomvpkg
to move a package to a new one. Thanks to this, if you have only the function within the file you should be good to go. It should also update the import
statements (make sure to double-check them anyway). I know that it's boring in fact I keep copying/pasting functions between packages as it's faster.
> It seems that this feature is already supported in Goland, so you can give it a try maybe if you wish.
Let me know!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论