Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #15262 - adamse:master, r=HKalbasi
add check.ignore to list cargo check diagnostics to ignore (dead_code, unused_imports, ...) fixes #14798
bors 2023-08-09
parent 6918eb6 · parent 9cb1f45 · commit e13fac3
-rw-r--r--crates/rust-analyzer/src/config.rs5
-rw-r--r--crates/rust-analyzer/src/diagnostics.rs2
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs7
-rw-r--r--docs/user/generated_config.adoc7
-rw-r--r--editors/code/package.json9
5 files changed, 30 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index fa20c796ec..4a31e0ba0a 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -150,6 +150,10 @@ config_data! {
///
/// Set to `"all"` to pass `--all-features` to Cargo.
check_features | checkOnSave_features: Option<CargoFeaturesDef> = "null",
+ /// List of `cargo check` (or other command specified in `check.command`) diagnostics to ignore.
+ ///
+ /// For example for `cargo check`: `dead_code`, `unused_imports`, `unused_variables`,...
+ check_ignore: FxHashSet<String> = "[]",
/// Specifies the working directory for running checks.
/// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
// FIXME: Ideally we would support this in some way
@@ -1098,6 +1102,7 @@ impl Config {
remap_prefix: self.data.diagnostics_remapPrefix.clone(),
warnings_as_info: self.data.diagnostics_warningsAsInfo.clone(),
warnings_as_hint: self.data.diagnostics_warningsAsHint.clone(),
+ check_ignore: self.data.check_ignore.clone(),
}
}
diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs
index 33422fd058..b65f38a0c7 100644
--- a/crates/rust-analyzer/src/diagnostics.rs
+++ b/crates/rust-analyzer/src/diagnostics.rs
@@ -6,6 +6,7 @@ use std::mem;
use ide::FileId;
use ide_db::FxHashMap;
use nohash_hasher::{IntMap, IntSet};
+use rustc_hash::FxHashSet;
use triomphe::Arc;
use crate::lsp_ext;
@@ -17,6 +18,7 @@ pub struct DiagnosticsMapConfig {
pub remap_prefix: FxHashMap<String, String>,
pub warnings_as_info: Vec<String>,
pub warnings_as_hint: Vec<String>,
+ pub check_ignore: FxHashSet<String>,
}
#[derive(Debug, Default, Clone)]
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index e1d1130ff1..06564578d8 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -292,6 +292,13 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
let mut source = String::from("rustc");
let mut code = rd.code.as_ref().map(|c| c.code.clone());
+
+ if let Some(code_val) = &code {
+ if config.check_ignore.contains(code_val) {
+ return Vec::new();
+ }
+ }
+
if let Some(code_val) = &code {
// See if this is an RFC #2103 scoped lint (e.g. from Clippy)
let scoped_code: Vec<&str> = code_val.split("::").collect();
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index ea00c9540f..820535cc1b 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -161,6 +161,13 @@ List of features to activate. Defaults to
Set to `"all"` to pass `--all-features` to Cargo.
--
+[[rust-analyzer.check.ignore]]rust-analyzer.check.ignore (default: `[]`)::
++
+--
+List of `cargo check` (or other command specified in `check.command`) diagnostics to ignore.
+
+For example for `cargo check`: `dead_code`, `unused_imports`, `unused_variables`,...
+--
[[rust-analyzer.check.invocationLocation]]rust-analyzer.check.invocationLocation (default: `"workspace"`)::
+
--
diff --git a/editors/code/package.json b/editors/code/package.json
index 76d7e91f38..96fc8d7ecf 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -700,6 +700,15 @@
}
]
},
+ "rust-analyzer.check.ignore": {
+ "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`,...",
+ "default": [],
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "uniqueItems": true
+ },
"rust-analyzer.check.invocationLocation": {
"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.",
"default": "workspace",