我正在使用 GoLand IDE 在 Go 中编写代码。当我保存文件时,我希望未使用的导入消失(如 VS 代码)
我在“代码”->“显示重新格式化文件对话框”中启用了“优化导入”。但是当我保存文件时,导入它仍然存在
Two separate entries where added to the File Watchers that are enabled by default. One for formatting the code on save, one for optimising the imports on save:
How the imports are sorted, grouped, etc. can be further defined in the Code Style settings for Go:
There is another small option to run gofmt
on reformat in the Other
tab of Go's Code Style settings:
The setting to set up gofmt
or goimports
on save is in the File Watchers. Here you can add a new file watcher at the bottom and select gofmt
or goimports
from the list.
Setting this to goimports
will do both:
gofmt
)GogLand EAP 16中删除了“保存时”选项卡。
在较新的版本中,您必须转到Settings
-> Tools
->File Watchers
并在goimports
那里添加。