Goland无法自动导入”fmt”吗?

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

Goland can't auto import "fmt"?

问题

Goland (版本 2021.2,在 Linux 上) 在添加使用 fmt 函数的代码行时无法自动导入 "fmt"。我需要手动添加 import "fmt"。但是对于其他内置的 Go 包似乎没有问题。

这是一个 bug 还是特殊设计?

另外,对于第三方包 github.com/stretchr/testify/assert,自动导入会提示几个导入 assert 的选项,但在我的情况下,上述选项始终不在列表中,必须手动 import

截图

Goland无法自动导入”fmt”吗?


@更新:问题的原因和解决方案已找到

问题:
Goland无法自动导入”fmt”吗?

解决方案:只需删除这两行,然后导入就会立即生效。

感谢 s0xzwasd 在问题下的评论,以及 jinseok.oh 的答案,实际上提到了这个设置。

英文:

Goland (version 2021.2, on Linux) can't auto import "fmt", when add a line of code that use fmt's functions.
I need to add import "fmt" by hand.
But seems it doesn't have problem with other built-in go packages.

It that a bug, or a special design ?

BTW, the similar issue occur for 3rd-party package "github.com/stretchr/testify/assert", the auto import will hint several options to import assert, but the above one is always not in the list in my case, had to import by hand.

Screenshot:

Goland无法自动导入”fmt”吗?


@Update: Cause of issue & solution found

Issue:
Goland无法自动导入”fmt”吗?

Solution: just remove the 2 line, then import works immediately.

Thanks to s0xzwasd's comment under question, and jinseok.oh's answer, which actually mentioned the setting.

答案1

得分: 1

有一个全局的Println()函数和fmt.Println()函数。

如果你输入Println并按下ctl+space,IDE会自动补全Println()。

/// 添加

Goland无法自动导入”fmt”吗?

另外你需要检查一下。是否有从import和completion中排除的内容?

如果不存在,那么我最后的建议是进行缓存无效化/重启

Goland无法自动导入”fmt”吗?

英文:

There is Global Println() function and also fmt.Println() function()

If you writh Println and press ctl+space only then IDE will set autocomplete Println().

/// add

Goland无法自动导入”fmt”吗?

Also you have to check this. Is there any exclucde from import and completion?

If doesn't exist, then my last advise is doing invalidate caches/ restart

Goland无法自动导入”fmt”吗?

huangapple
  • 本文由 发表于 2021年11月28日 13:16:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/70140842.html
匿名

发表评论

匿名网友

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

确定