Go语言的IDE能够进行重构操作,包括变量、函数、结构体和包的重命名。

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

IDE for Go capable of refactoring: variable, function, structure and package renaming

问题

我对任何能够重构Go源代码进行变量重命名的IDE(或脚本)都感兴趣。例如,在Java的Eclipse中,可以选择一个变量、对象或类,然后对其进行重命名,它会自动在项目的所有文件中进行重命名。如果自动字符串替换可能导致子字符串冲突,这个功能非常有用。

英文:

I am interested in any IDE (or even a script) that is capable of refactoring Go source code for variable renaming. For example in Eclipse for Java, one can select a variable, an object or a class, then to rename it and it gets automatically renamed in all the files in the project. This feature is very useful if automatic string replacement may cause substring collisions.

答案1

得分: 6

如果你对脚本感兴趣,可以使用gofmt命令,并带上-r标志。像这样:

gofmt -w -r 'OldFoo -> Foo' foopackage

根据文档:

如果没有指定路径,它会处理标准输入。如果给定一个文件,它会操作该文件;如果给定一个目录,它会递归地操作该目录下的所有.go文件(以点开头的文件会被忽略)。默认情况下,gofmt会将重新格式化的源代码打印到标准输出。

**编辑:**今天有更好的工具可以实现这个功能:gorename用于重命名,eg用于通用重构。

英文:

If you're interested in a script, use gofmt with -r flag. Like this:

gofmt -w -r 'OldFoo -> Foo' foopackage

From the docs:

> Without an explicit path, it processes the standard input. Given a file, it operates on that file; given a directory, it operates on all .go files in that directory, recursively. (Files starting with a period are ignored.) By default, gofmt prints the reformatted sources to standard output.

EDIT: Today there are better tools for that: gorename for renaming and eg for general refactoring.

答案2

得分: 2

gorename工具可以在Go源代码中进行精确的类型安全重命名标识符。

英文:

The gorename tool performs precise type-safe renaming of identifiers in Go source code.

huangapple
  • 本文由 发表于 2014年7月11日 00:17:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/24681581.html
匿名

发表评论

匿名网友

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

确定