如何在GoClipse中启用自动导入功能?

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

How to enable autoimport in GoClipse?

问题

根据这篇帖子,可以在GoClipse中启用自动导入功能:

  1. 安装goimports:
    go get code.google.com/p/go.tools/cmd/goimports

  2. 在Eclipse中转到:Preferences -> Go -> Go Formatter,并将其设置为goimports二进制文件的路径

这样,在格式化代码时会修复所有的导入问题。如果结合使用#67,保存时导入将自动修复。

问题

当我尝试在Eclipse中搜索Go Formatter时,找不到它。

如何在GoClipse中启用自动导入功能?

英文:

According to this post autoimport could be enabled in GoClipse:

> 1) install goimports:
> go get code.google.com/p/go.tools/cmd/goimports
>
> 2) in eclipse goto: Preferences -> Go -> Go Formatter and set it to be the path of the goimports bin
>
> This will fix all imports when you format. If you combine this with #67, then imports will be automatically fixed on save.

Problem

When I try to search for Go Formatter in Eclipse I cannot find it.

如何在GoClipse中启用自动导入功能?

答案1

得分: 5

我注意到一件事:

我知道 goimports 的 URL 不再是 google.com/p/go.tools/cmd/goimports。

所以让我们尝试以下步骤:

  1. 执行 go get golang.org/x/tools/cmd/goimports
  2. 进入 Preferences -> Go
  3. gofmt 设置为 ${GOPATH}/bin/goimports(goimports 的位置)
  4. 重新启动 Eclipse 并确保在按下<kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>F</kbd>时使用 goimports
英文:

One thing that my eyes caught out:

I know that goimports URL is no longer google.com/p/go.tools/cmd/goimports.

So lets try the following:

  1. Execute go get golang.org/x/tools/cmd/goimports
  2. Go to Preferences -> Go
  3. Set gofmt to ${GOPATH}/bin/goimports (which is where goimports is located)
  4. Restart Eclipse and make sure it uses goimports when <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>F</kbd> is pressed.

huangapple
  • 本文由 发表于 2015年11月29日 05:15:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/33976532.html
匿名

发表评论

匿名网友

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

确定