Skip to content

Commit 9cb1f45

Browse files
committed
add check.ignore to list cargo check diagnostics to ignore (dead_code, unused_imports, ...)
fixes rust-lang#14798
1 parent cabe26c commit 9cb1f45

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

crates/rust-analyzer/src/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ config_data! {
150150
///
151151
/// Set to `"all"` to pass `--all-features` to Cargo.
152152
check_features | checkOnSave_features: Option<CargoFeaturesDef> = "null",
153+
/// List of `cargo check` (or other command specified in `check.command`) diagnostics to ignore.
154+
///
155+
/// For example for `cargo check`: `dead_code`, `unused_imports`, `unused_variables`,...
156+
check_ignore: FxHashSet<String> = "[]",
153157
/// Specifies the working directory for running checks.
154158
/// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
155159
// FIXME: Ideally we would support this in some way
@@ -1098,6 +1102,7 @@ impl Config {
10981102
remap_prefix: self.data.diagnostics_remapPrefix.clone(),
10991103
warnings_as_info: self.data.diagnostics_warningsAsInfo.clone(),
11001104
warnings_as_hint: self.data.diagnostics_warningsAsHint.clone(),
1105+
check_ignore: self.data.check_ignore.clone(),
11011106
}
11021107
}
11031108

crates/rust-analyzer/src/diagnostics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::mem;
66
use ide::FileId;
77
use ide_db::FxHashMap;
88
use nohash_hasher::{IntMap, IntSet};
9+
use rustc_hash::FxHashSet;
910
use triomphe::Arc;
1011

1112
use crate::lsp_ext;
@@ -17,6 +18,7 @@ pub struct DiagnosticsMapConfig {
1718
pub remap_prefix: FxHashMap<String, String>,
1819
pub warnings_as_info: Vec<String>,
1920
pub warnings_as_hint: Vec<String>,
21+
pub check_ignore: FxHashSet<String>,
2022
}
2123

2224
#[derive(Debug, Default, Clone)]

crates/rust-analyzer/src/diagnostics/to_proto.rs

+7
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
292292

293293
let mut source = String::from("rustc");
294294
let mut code = rd.code.as_ref().map(|c| c.code.clone());
295+
296+
if let Some(code_val) = &code {
297+
if config.check_ignore.contains(code_val) {
298+
return Vec::new();
299+
}
300+
}
301+
295302
if let Some(code_val) = &code {
296303
// See if this is an RFC #2103 scoped lint (e.g. from Clippy)
297304
let scoped_code: Vec<&str> = code_val.split("::").collect();

docs/user/generated_config.adoc

+7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ List of features to activate. Defaults to
161161

162162
Set to `"all"` to pass `--all-features` to Cargo.
163163
--
164+
[[rust-analyzer.check.ignore]]rust-analyzer.check.ignore (default: `[]`)::
165+
+
166+
--
167+
List of `cargo check` (or other command specified in `check.command`) diagnostics to ignore.
168+
169+
For example for `cargo check`: `dead_code`, `unused_imports`, `unused_variables`,...
170+
--
164171
[[rust-analyzer.check.invocationLocation]]rust-analyzer.check.invocationLocation (default: `"workspace"`)::
165172
+
166173
--

editors/code/package.json

+9
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,15 @@
688688
}
689689
]
690690
},
691+
"rust-analyzer.check.ignore": {
692+
"markdownDescription": "List of `cargo check` (or other command specified in `check.command`) diagnostics to ignore.\n\nFor example for `cargo check`: `dead_code`, `unused_imports`, `unused_variables`,...",
693+
"default": [],
694+
"type": "array",
695+
"items": {
696+
"type": "string"
697+
},
698+
"uniqueItems": true
699+
},
691700
"rust-analyzer.check.invocationLocation": {
692701
"markdownDescription": "Specifies the working directory for running checks.\n- \"workspace\": run checks for workspaces in the corresponding workspaces' root directories.\n This falls back to \"root\" if `#rust-analyzer.cargo.checkOnSave.invocationStrategy#` is set to `once`.\n- \"root\": run checks in the project's root directory.\nThis config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`\nis set.",
693702
"default": "workspace",

0 commit comments

Comments
 (0)