dragon202076 2017-11-07 09:37
浏览 35
已采纳

如何禁用删除未使用的导入?

I use goimports to automatically reformat my code and make it clean and also keep import in order. But sometimes it works in an incomfortable way together with IDE autosave. Like in this scenario:

  1. I want to add new package to my code.

  2. Then I install it with dep ensure and refresh my IDE cache.

  3. I can comfortably use the package with IDE autocomplete and navigation.

What happens with goimports and IDE?

  1. I add new package
  2. In order to run dep ensure I have to save a file
  3. goimports finds unused package and removes it from imports. Not good.

Workaround:

A. Add new package manually with dep ensure -add %packagename%

B. Disable goimports and move to gofmt - so-so.

C. Do not autoformat code on save - undesirable.

How to setup things more convenient?

P.S. Unsure about tag godeps but DEP is definitly wrong here.

  • 写回答

1条回答 默认 最新

  • dshgdhdfcas30210 2017-11-07 10:10
    关注

    The correct solution would be to invoke dep ensure -add package/name yourself and then just start using the package without manually importing it, the IDE will figure out that you want to use that package and will add the import automatically. The current behavior you are experiencing is exactly what's expected from the IDE since goimports is invoked on save and because the import is not used it will be automatically removed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考