Search code examples
gogoland

Goland can't auto import "fmt"?


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:

fmt import hint in goland


@Update: Cause of issue & solution found

Issue: imports setting in goland

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.


Solution

  • 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

    enter image description here

    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

    enter image description here