How to stop GoLand from auto removal of unused imports?

你离开我真会死。 提交于 2019-11-30 17:40:27

问题


I am working with Jetbrains GoLand and am wondering if its possible to somehow disable the auto removal of unused imports. I have searched the Jetbrains forums earlier and there is no such information for specifically for Goland. This picture shows the problem.


回答1:


This feature is used so that you do not receive compilation errors for unused imports from Go.

While you can deactivate the feature via "Settings (Preferences) | Go | Imports | Optimize imports on the fly", my recommendation is to leave this as is and instead let the IDE manage the imports for you.

For example, you can start typing "template.New" inside the "main" function and the IDE will ask which "template" package to import as there are two packages in the standard library "text/template" and "html/template". When only one package is available, that will be imported automatically. When you will remove the last reference to the "template" package, the IDE will remove the import automatically, thus allowing you to run the code without any compilation issues.



来源:https://stackoverflow.com/questions/51410979/how-to-stop-goland-from-auto-removal-of-unused-imports

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!