【问题标题】:How to enable autoimport in GoClipse?如何在 GoClipse 中启用自动导入?
【发布时间】:2015-12-02 18:11:10
【问题描述】:

根据this post可以在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.

问题

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

【问题讨论】:

  • 也许,它是 gofmt。尝试将 gofmt 路径更改为 goimports 路径。
  • 我已经运行 get 命令来获取导入代码,但我找不到二进制文件。我期待这与 gocode 相同。运行 get 命令后,gocode 二进制文件驻留在 eclipse 工作区的 bin 目录中,但这对于 goimports 的工作方式不同?
  • 嗨@Alfred。想知道你是否解决了。如果没有,我的回答对你有帮助吗?谢谢。
  • @bshuster13 现在可以了。谢谢你。也许您可以将 ctrl shift f 添加到您的答案中。
  • @Alfred 干得好!谢谢你。

标签: eclipse go import goclipse


【解决方案1】:

我的眼睛发现了一件事:

我知道 goimports 网址不再是 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并确保在按下CTRL+SHIFT+F时它使用goimports

【讨论】:

  • 当我保存文件时,什么也没有发生。例如,regex 应该被导入但没有任何反应
  • @Alfred:您需要“格式化”代码。 “鼠标右键”->source->Go format(gofmt) or ctr-shift-f.
  • @RickyA 谢谢。我假设像在 java 中那样组织导入是 ctrl shift o。
猜你喜欢
  • 2011-11-19
  • 1970-01-01
  • 2018-08-04
  • 1970-01-01
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-23
  • 1970-01-01
相关资源
最近更新 更多