formatting tool removes `import "fmt"` before it can be used in subsequent code

Importing an a package (such as 'fmt') without a reference to the package in the current file automatically removes it:

 

The import is removed whenever a reference to it doesn't exist. It is not removed once a reference has been made. I imagine a formatting setting can be adjusted somewhere but it's not clear. Is this the 'go.formatOnSave' setting? How do I prevent the editor from 'correcting' me in this way.

Mac Version 10.12.6, GoLand 2018.3.1

Thanks! 

 

0

Hi,

It's supposed that you don't need to manage your imports manually. GoLand does it for you. You can just type `fmtPrintln` and complete the function call, GoLand will import it. Remove the call – GoLand will remove the import.

If you still want to do manual work, you can disable the feature via Preferences | Go | Imports | Optimize imports on the fly.

No, it has nothing to do with the gofmt.

0

请先登录再写评论。