GoLand IDE:如何去除未使用变量的语法高亮显示?

huangapple go评论132阅读模式
英文:

GoLand IDE: How to remove syntax highlighting for unused variables?

问题

问题:当我刚刚声明一个变量时,GoLand立即用错误提示将其标记为“变量在任何地方都没有使用”;我不喜欢这种IDE的行为。我还没有来得及在任何地方使用它,只是声明了它。

实际上,主题,请告诉我如何去除GoLand中的语法高亮(特别是未使用的变量)?

P.S.
在设置 -> 编辑器 -> 检查 -> Go 中操作没有任何好处

英文:

Problem: When I just declare a variable, GoLand immediately highlights it with an error like: "The variable is not used anywhere"; I don't like this behavior of the IDE. I have not yet had time to use it anywhere, but only announced it.

Actually, subject, tell me, please, how to remove this syntax highlighting (namely, about unused variables) in GoLand?

P.S.
There is no benefit from manipulating the: Settings -> Editor -> Inspections -> Go

答案1

得分: 2

这在Goland或者VsCode Go中似乎是不可能的(它们具有相同的行为)。

考虑到对于Go本身而言,未使用的变量是一个错误,IDE只是反映了这一点。

尽管如此,这可能会让人感到不适,其他Goland的问题也反映了这一点:例如,GO-2374提到了与导出函数类似的问题:

> 所有在库本身中未使用的导出函数(以大写字母开头)都会被标记为未使用。
这对我来说似乎很奇怪。大多数库中的导出函数在库本身中从未被使用,但我认为将它们标记为未使用是错误的,因为它们主要不是为了在库内部使用。

我仍然更喜欢当前的高亮显示方式,因为它确保我尽快不使用新变量。

英文:

This does not seem possible with Goland, of VsCode Go (which has the same behavior)

Considering an unused variable is an error for Go itself, the IDE simply reflects that.

It can be jarring though, and other Goland issues reflect this: for example, GO-2374 mentions the same kind of issue with exported functions:

> All exported functions (starting with a capital letter) that are not used within a library itself, are marked as unused.
This seems odd to me. Most exported functions in a library are never used within the library itself, but I think it is wrong to mark them as unused since they are not primarily meant to be used within the library.

I still prefer the current highlight, as it makes sure I do not introduce a new variable without using as soon as possible.

答案2

得分: 2

也许如果你有那个新的变量,可以在之后加上"_ = yourVar"。
(这样它就被使用了)
警告:之后自己扫描"_= "来查看是否还有这些。

编辑器“抱怨”的事实只是Go语言的特性。Go语言不允许声明未使用的变量。

英文:

Perhaps if you have that new var, do a
_ = yourVar after that.
(Then it is in use)
Warning: scan for "_ =" afterwards yourself to see if you still have these.

The fact that the editor "complains" is just Go. Go doesn't allow you to declare vars that are not in use.

huangapple
  • 本文由 发表于 2022年1月18日 15:31:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/70751745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定