mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Merge #5796
5796: Align diagnostics config with the rest of rust-analyzer
r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
0e66dc690e
10 changed files with 93 additions and 98 deletions
|
@ -7,7 +7,10 @@ use base_db::{
|
|||
salsa::{Database, Durability},
|
||||
FileId,
|
||||
};
|
||||
use ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosition, LineCol};
|
||||
use ide::{
|
||||
Analysis, AnalysisChange, AnalysisHost, CompletionConfig, DiagnosticsConfig, FilePosition,
|
||||
LineCol,
|
||||
};
|
||||
use vfs::AbsPathBuf;
|
||||
|
||||
use crate::{
|
||||
|
@ -71,7 +74,7 @@ impl BenchCmd {
|
|||
match &self.what {
|
||||
BenchWhat::Highlight { .. } => {
|
||||
let res = do_work(&mut host, file_id, |analysis| {
|
||||
analysis.diagnostics(file_id, true, None).unwrap();
|
||||
analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap();
|
||||
analysis.highlight_as_html(file_id, false).unwrap()
|
||||
});
|
||||
if verbosity.is_verbose() {
|
||||
|
|
|
@ -8,7 +8,7 @@ use rustc_hash::FxHashSet;
|
|||
|
||||
use base_db::SourceDatabaseExt;
|
||||
use hir::Crate;
|
||||
use ide::Severity;
|
||||
use ide::{DiagnosticsConfig, Severity};
|
||||
|
||||
use crate::cli::{load_cargo::load_cargo, Result};
|
||||
|
||||
|
@ -47,7 +47,8 @@ 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, None).unwrap() {
|
||||
for diagnostic in analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap()
|
||||
{
|
||||
if matches!(diagnostic.severity, Severity::Error) {
|
||||
found_error = true;
|
||||
}
|
||||
|
|
|
@ -7,24 +7,25 @@
|
|||
//! configure the server itself, feature flags are passed into analysis, and
|
||||
//! tweak things like automatic insertion of `()` in completions.
|
||||
|
||||
use std::{collections::HashSet, ffi::OsString, path::PathBuf};
|
||||
use std::{ffi::OsString, path::PathBuf};
|
||||
|
||||
use flycheck::FlycheckConfig;
|
||||
use ide::{AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig};
|
||||
use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig};
|
||||
use lsp_types::ClientCapabilities;
|
||||
use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest};
|
||||
use rustc_hash::FxHashSet;
|
||||
use serde::Deserialize;
|
||||
use vfs::AbsPathBuf;
|
||||
|
||||
use crate::diagnostics::DiagnosticsConfig;
|
||||
use crate::diagnostics::DiagnosticsMapConfig;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub client_caps: ClientCapsConfig,
|
||||
|
||||
pub publish_diagnostics: bool,
|
||||
pub experimental_diagnostics: bool,
|
||||
pub diagnostics: DiagnosticsConfig,
|
||||
pub diagnostics_map: DiagnosticsMapConfig,
|
||||
pub lru_capacity: Option<usize>,
|
||||
pub proc_macro_srv: Option<(PathBuf, Vec<OsString>)>,
|
||||
pub files: FilesConfig,
|
||||
|
@ -45,14 +46,6 @@ 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)]
|
||||
|
@ -146,8 +139,8 @@ impl Config {
|
|||
|
||||
with_sysroot: true,
|
||||
publish_diagnostics: true,
|
||||
experimental_diagnostics: true,
|
||||
diagnostics: DiagnosticsConfig::default(),
|
||||
diagnostics_map: DiagnosticsMapConfig::default(),
|
||||
lru_capacity: None,
|
||||
proc_macro_srv: None,
|
||||
files: FilesConfig { watcher: FilesWatcher::Notify, exclude: Vec::new() },
|
||||
|
@ -184,8 +177,6 @@ impl Config {
|
|||
hover: HoverConfig::default(),
|
||||
linked_projects: Vec::new(),
|
||||
root_path,
|
||||
|
||||
analysis: AnalysisConfig::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,8 +191,11 @@ impl Config {
|
|||
|
||||
self.with_sysroot = data.withSysroot;
|
||||
self.publish_diagnostics = data.diagnostics_enable;
|
||||
self.experimental_diagnostics = data.diagnostics_enableExperimental;
|
||||
self.diagnostics = DiagnosticsConfig {
|
||||
disable_experimental: !data.diagnostics_enableExperimental,
|
||||
disabled: data.diagnostics_disabled,
|
||||
};
|
||||
self.diagnostics_map = DiagnosticsMapConfig {
|
||||
warnings_as_info: data.diagnostics_warningsAsInfo,
|
||||
warnings_as_hint: data.diagnostics_warningsAsHint,
|
||||
};
|
||||
|
@ -303,8 +297,6 @@ impl Config {
|
|||
goto_type_def: data.hoverActions_enable && data.hoverActions_gotoTypeDef,
|
||||
};
|
||||
|
||||
self.analysis = AnalysisConfig { disabled_diagnostics: data.analysis_disabledDiagnostics };
|
||||
|
||||
log::info!("Config::update() = {:#?}", self);
|
||||
}
|
||||
|
||||
|
@ -369,14 +361,6 @@ 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)]
|
||||
|
@ -434,6 +418,7 @@ config_data! {
|
|||
|
||||
diagnostics_enable: bool = true,
|
||||
diagnostics_enableExperimental: bool = true,
|
||||
diagnostics_disabled: FxHashSet<String> = FxHashSet::default(),
|
||||
diagnostics_warningsAsHint: Vec<String> = Vec::new(),
|
||||
diagnostics_warningsAsInfo: Vec<String> = Vec::new(),
|
||||
|
||||
|
@ -464,7 +449,5 @@ config_data! {
|
|||
rustfmt_overrideCommand: Option<Vec<String>> = None,
|
||||
|
||||
withSysroot: bool = true,
|
||||
|
||||
analysis_disabledDiagnostics: HashSet<String> = HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::lsp_ext;
|
|||
pub(crate) type CheckFixes = Arc<FxHashMap<FileId, Vec<Fix>>>;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct DiagnosticsConfig {
|
||||
pub struct DiagnosticsMapConfig {
|
||||
pub warnings_as_info: Vec<String>,
|
||||
pub warnings_as_hint: Vec<String>,
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ use stdx::format_to;
|
|||
|
||||
use crate::{lsp_ext, to_proto::url_from_abs_path};
|
||||
|
||||
use super::DiagnosticsConfig;
|
||||
use super::DiagnosticsMapConfig;
|
||||
|
||||
/// Determines the LSP severity from a diagnostic
|
||||
fn diagnostic_severity(
|
||||
config: &DiagnosticsConfig,
|
||||
config: &DiagnosticsMapConfig,
|
||||
level: flycheck::DiagnosticLevel,
|
||||
code: Option<flycheck::DiagnosticCode>,
|
||||
) -> Option<lsp_types::DiagnosticSeverity> {
|
||||
|
@ -141,7 +141,7 @@ pub(crate) struct MappedRustDiagnostic {
|
|||
///
|
||||
/// If the diagnostic has no primary span this will return `None`
|
||||
pub(crate) fn map_rust_diagnostic_to_lsp(
|
||||
config: &DiagnosticsConfig,
|
||||
config: &DiagnosticsMapConfig,
|
||||
rd: &flycheck::Diagnostic,
|
||||
workspace_root: &Path,
|
||||
) -> Vec<MappedRustDiagnostic> {
|
||||
|
@ -259,10 +259,10 @@ mod tests {
|
|||
use expect::{expect_file, ExpectFile};
|
||||
|
||||
fn check(diagnostics_json: &str, expect: ExpectFile) {
|
||||
check_with_config(DiagnosticsConfig::default(), diagnostics_json, expect)
|
||||
check_with_config(DiagnosticsMapConfig::default(), diagnostics_json, expect)
|
||||
}
|
||||
|
||||
fn check_with_config(config: DiagnosticsConfig, diagnostics_json: &str, expect: ExpectFile) {
|
||||
fn check_with_config(config: DiagnosticsMapConfig, diagnostics_json: &str, expect: ExpectFile) {
|
||||
let diagnostic: flycheck::Diagnostic = serde_json::from_str(diagnostics_json).unwrap();
|
||||
let workspace_root = Path::new("/test/");
|
||||
let actual = map_rust_diagnostic_to_lsp(&config, &diagnostic, workspace_root);
|
||||
|
@ -402,9 +402,9 @@ mod tests {
|
|||
#[cfg(not(windows))]
|
||||
fn rustc_unused_variable_as_info() {
|
||||
check_with_config(
|
||||
DiagnosticsConfig {
|
||||
DiagnosticsMapConfig {
|
||||
warnings_as_info: vec!["unused_variables".to_string()],
|
||||
..DiagnosticsConfig::default()
|
||||
..DiagnosticsMapConfig::default()
|
||||
},
|
||||
r##"{
|
||||
"message": "unused variable: `foo`",
|
||||
|
@ -486,9 +486,9 @@ mod tests {
|
|||
#[cfg(not(windows))]
|
||||
fn rustc_unused_variable_as_hint() {
|
||||
check_with_config(
|
||||
DiagnosticsConfig {
|
||||
DiagnosticsMapConfig {
|
||||
warnings_as_hint: vec!["unused_variables".to_string()],
|
||||
..DiagnosticsConfig::default()
|
||||
..DiagnosticsMapConfig::default()
|
||||
},
|
||||
r##"{
|
||||
"message": "unused variable: `foo`",
|
||||
|
|
|
@ -775,11 +775,7 @@ fn handle_fixes(
|
|||
None => {}
|
||||
};
|
||||
|
||||
let diagnostics = snap.analysis.diagnostics(
|
||||
file_id,
|
||||
snap.config.experimental_diagnostics,
|
||||
snap.config.disabled_diagnostics(),
|
||||
)?;
|
||||
let diagnostics = snap.analysis.diagnostics(&snap.config.diagnostics, file_id)?;
|
||||
|
||||
for fix in diagnostics
|
||||
.into_iter()
|
||||
|
@ -1051,13 +1047,10 @@ pub(crate) fn publish_diagnostics(
|
|||
) -> Result<Vec<Diagnostic>> {
|
||||
let _p = profile::span("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,
|
||||
snap.config.disabled_diagnostics(),
|
||||
)?
|
||||
.diagnostics(&snap.config.diagnostics, file_id)?
|
||||
.into_iter()
|
||||
.map(|d| Diagnostic {
|
||||
range: to_proto::range(&line_index, d.range),
|
||||
|
|
|
@ -248,7 +248,7 @@ impl GlobalState {
|
|||
Event::Flycheck(task) => match task {
|
||||
flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => {
|
||||
let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
|
||||
&self.config.diagnostics,
|
||||
&self.config.diagnostics_map,
|
||||
&diagnostic,
|
||||
&workspace_root,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue