vscode:将Go代码(类型/函数)移动到其他文件中

huangapple go评论117阅读模式
英文:

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!

huangapple
  • 本文由 发表于 2023年1月10日 22:18:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75071292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定