How can I disable problem underlines for unused variables with the Rust Analyzer VS Code extension and instead highlight it gray?

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

How can I disable problem underlines for unused variables with the Rust Analyzer VS Code extension and instead highlight it gray?

问题

我正在使用VS Code编写Rust代码,但未使用的变量会显示难看的波浪线,我想要禁用它,只让未使用的变量变成灰色,就像IntelliJ IDEA显示未使用函数一样。

VS Code:

How can I disable problem underlines for unused variables with the Rust Analyzer VS Code extension and instead highlight it gray?

goland

How can I disable problem underlines for unused variables with the Rust Analyzer VS Code extension and instead highlight it gray?

英文:

I am coding in Rust by using VS Code, but the variable that i'm not used shows a ugly wavy underline, i want to disable it and just make my unused variables being gray which seems like IntelliJ IDEA shows unused functions.

VS Code:

How can I disable problem underlines for unused variables with the Rust Analyzer VS Code extension and instead highlight it gray?

goland

How can I disable problem underlines for unused variables with the Rust Analyzer VS Code extension and instead highlight it gray?

答案1

得分: 2

Chayim的答案所示,您可以将警告更改为提示,这具有更为微妙的视觉提示。我不确定是否有一种方法可以移除所有与下划线相关的视觉提示。如下所示:

"rust-analyzer.diagnostics.warningsAsHint": [
   "unused_variables"
],

至于将其标记为灰色,截止到我撰写此回答时,Rust Analyzer扩展程序没有提供任何用于未使用内容的专用语义标记(我使用了Developer: Inspect Editor Tokens and Scopes命令进行了检查)。语义高亮有一个关于“修饰符”的机制。目前还没有用于未使用内容的修饰符,但这里有一个相关的功能请求:SemanticTokensModifier: Add unused token modifier #604。您可以给这个问题票投一票以表示支持,并订阅它以获取有关讨论和进展的通知。如果/当它被实施时,您还需要等待Rust Analyzer扩展程序开始使用该功能。

英文:

As shown in Chayim's answer you can change change the warnings to hints, which have a more subtle visual cue. I'm not sure of a way to remove all underline-related visual cues. Like so:

"rust-analyzer.diagnostics.warningsAsHint": [
   "unused_variables"
],

As for highlighting it grey, the Rust Analyzer extension doesn't provide any dedicated semantic token for unused things at the time of this writing (I checked using the Developer: Inspect Editor Tokens and Scopes command). Semantic highlighting has a mechanism for "modifiers". There isn't yet a modifier for unused things, but there's a feature-request for that here: SemanticTokensModifier: Add unused token modifier #604. You can give that issue ticket a thumbs up to show support for it, and subscribe to it to get notified about discussion and progress. If/when it does get implemented, you'd then also have to wait for the Rust Analyzer extension to make use of the feature.

答案2

得分: 0

我不相信你可以将名称变成灰色,但你可以通过更改设置来避免波浪线。在 VS Code 的 settings.json 中:

{
    "rust-analyzer.diagnostics.warningsAsHint": [
        "dead_code",
        "unused_variables"
    ]
}
英文:

I don't believe you can make the name grey, but you can avoid the squiggles by changing the settings. In settings.json of VS Code:

{
    "rust-analyzer.diagnostics.warningsAsHint": [
        "dead_code",
        "unused_variables"
    ]
}

huangapple
  • 本文由 发表于 2023年6月29日 00:47:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575226.html
匿名

发表评论

匿名网友

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

确定