5682: Add an option to disable diagnostics r=matklad a=popzxc

As far as I know, currently it's not possible to disable a selected type of diagnostics provided by `rust-analyzer`.

This causes an inconvenient situation with a false-positive warnings: you either have to disable all the diagnostics, or you have to ignore these warnings.

There are some open issues related to this problem, e.g.: https://github.com/rust-analyzer/rust-analyzer/issues/5412, https://github.com/rust-analyzer/rust-analyzer/issues/5502

This PR attempts to make it possible to selectively disable some diagnostics on per-project basis.

Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
This commit is contained in:
bors[bot] 2020-08-18 12:04:49 +00:00 committed by GitHub
commit b8dfc331ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 155 additions and 15 deletions

View file

@ -71,7 +71,7 @@ impl BenchCmd {
match &self.what {
BenchWhat::Highlight { .. } => {
let res = do_work(&mut host, file_id, |analysis| {
analysis.diagnostics(file_id, true).unwrap();
analysis.diagnostics(file_id, true, None).unwrap();
analysis.highlight_as_html(file_id, false).unwrap()
});
if verbosity.is_verbose() {

View file

@ -47,7 +47,7 @@ pub fn diagnostics(
String::from("unknown")
};
println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id));
for diagnostic in analysis.diagnostics(file_id, true).unwrap() {
for diagnostic in analysis.diagnostics(file_id, true, None).unwrap() {
if matches!(diagnostic.severity, Severity::Error) {
found_error = true;
}

View file

@ -7,7 +7,7 @@
//! configure the server itself, feature flags are passed into analysis, and
//! tweak things like automatic insertion of `()` in completions.
use std::{ffi::OsString, path::PathBuf};
use std::{collections::HashSet, ffi::OsString, path::PathBuf};
use flycheck::FlycheckConfig;
use ide::{AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig};
@ -45,6 +45,14 @@ pub struct Config {
pub with_sysroot: bool,
pub linked_projects: Vec<LinkedProject>,
pub root_path: AbsPathBuf,
pub analysis: AnalysisConfig,
}
/// Configuration parameters for the analysis run.
#[derive(Debug, Default, Clone)]
pub struct AnalysisConfig {
pub disabled_diagnostics: HashSet<String>,
}
#[derive(Debug, Clone, Eq, PartialEq)]
@ -176,6 +184,8 @@ impl Config {
hover: HoverConfig::default(),
linked_projects: Vec::new(),
root_path,
analysis: AnalysisConfig::default(),
}
}
@ -293,6 +303,8 @@ impl Config {
goto_type_def: data.hoverActions_enable && data.hoverActions_gotoTypeDef,
};
self.analysis = AnalysisConfig { disabled_diagnostics: data.analysis_disabledDiagnostics };
log::info!("Config::update() = {:#?}", self);
}
@ -357,6 +369,14 @@ impl Config {
self.client_caps.status_notification = get_bool("statusNotification");
}
}
pub fn disabled_diagnostics(&self) -> Option<HashSet<String>> {
if self.analysis.disabled_diagnostics.is_empty() {
None
} else {
Some(self.analysis.disabled_diagnostics.clone())
}
}
}
#[derive(Deserialize)]
@ -444,5 +464,7 @@ config_data! {
rustfmt_overrideCommand: Option<Vec<String>> = None,
withSysroot: bool = true,
analysis_disabledDiagnostics: HashSet<String> = HashSet::new(),
}
}

View file

@ -775,7 +775,11 @@ fn handle_fixes(
None => {}
};
let diagnostics = snap.analysis.diagnostics(file_id, snap.config.experimental_diagnostics)?;
let diagnostics = snap.analysis.diagnostics(
file_id,
snap.config.experimental_diagnostics,
snap.config.disabled_diagnostics(),
)?;
for fix in diagnostics
.into_iter()
@ -1049,7 +1053,11 @@ pub(crate) fn publish_diagnostics(
let line_index = snap.analysis.file_line_index(file_id)?;
let diagnostics: Vec<Diagnostic> = snap
.analysis
.diagnostics(file_id, snap.config.experimental_diagnostics)?
.diagnostics(
file_id,
snap.config.experimental_diagnostics,
snap.config.disabled_diagnostics(),
)?
.into_iter()
.map(|d| Diagnostic {
range: to_proto::range(&line_index, d.range),