如何阻止GoLand自动删除未使用的进口商品? [英] How to stop GoLand from auto removal of unused imports?

查看:103
本文介绍了如何阻止GoLand自动删除未使用的进口商品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Jetbrains GoLand合作,并且想知道是否有可能以某种方式禁用自动删除未使用的进口商品的功能.我之前搜索过Jetbrains论坛,并且没有专门针对Goland的此类信息. 此图片显示了问题.

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.

推荐答案

使用此功能是为了避免因Go的未使用导入而收到编译错误.

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

虽然您可以通过设置(首选项)|转到|导入|快速优化导入"来停用该功能,但我的建议是保持此状态,而让IDE为您管理导入.

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.

例如,您可以开始在"main"函数中键入"template.New",IDE将询问要导入哪个"template"软件包,因为标准库中有两个"text/template"和"html"软件包/模板".当只有一个软件包可用时,它将自动导入.当您删除对"template"包的最后一个引用时,IDE将自动删除导入,从而使您可以运行代码而没有任何编译问题.

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.

这篇关于如何阻止GoLand自动删除未使用的进口商品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆