英文:
Goland can't auto import "fmt"?
问题
Goland (版本 2021.2,在 Linux 上) 在添加使用 fmt 函数的代码行时无法自动导入 "fmt"。我需要手动添加 import "fmt"
。但是对于其他内置的 Go 包似乎没有问题。
这是一个 bug 还是特殊设计?
另外,对于第三方包 github.com/stretchr/testify/assert
,自动导入会提示几个导入 assert
的选项,但在我的情况下,上述选项始终不在列表中,必须手动 import
。
截图:
@更新:问题的原因和解决方案已找到
解决方案:只需删除这两行,然后导入就会立即生效。
感谢 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:
@Update: Cause of issue & solution found
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()。
/// 添加
另外你需要检查一下。是否有从import和completion中排除的内容?
如果不存在,那么我最后的建议是进行缓存无效化/重启
英文:
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
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论