mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
internal: diagnostic code is mandatory
This commit is contained in:
parent
b404b91da6
commit
500c909c76
@ -51,28 +51,26 @@ impl DiagnosticCode {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Diagnostic {
|
pub struct Diagnostic {
|
||||||
// pub name: Option<String>,
|
pub code: DiagnosticCode,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub range: TextRange,
|
pub range: TextRange,
|
||||||
pub severity: Severity,
|
pub severity: Severity,
|
||||||
pub fixes: Option<Vec<Assist>>,
|
|
||||||
pub unused: bool,
|
pub unused: bool,
|
||||||
pub code: Option<DiagnosticCode>,
|
|
||||||
pub experimental: bool,
|
pub experimental: bool,
|
||||||
|
pub fixes: Option<Vec<Assist>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic {
|
impl Diagnostic {
|
||||||
fn new(code: &'static str, message: impl Into<String>, range: TextRange) -> Diagnostic {
|
fn new(code: &'static str, message: impl Into<String>, range: TextRange) -> Diagnostic {
|
||||||
let message = message.into();
|
let message = message.into();
|
||||||
let code = Some(DiagnosticCode(code));
|
Diagnostic {
|
||||||
Self {
|
code: DiagnosticCode(code),
|
||||||
message,
|
message,
|
||||||
range,
|
range,
|
||||||
severity: Severity::Error,
|
severity: Severity::Error,
|
||||||
fixes: None,
|
|
||||||
unused: false,
|
unused: false,
|
||||||
code,
|
|
||||||
experimental: false,
|
experimental: false,
|
||||||
|
fixes: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,15 +179,8 @@ pub(crate) fn diagnostics(
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.retain(|d| {
|
res.retain(|d| {
|
||||||
if let Some(code) = d.code {
|
!ctx.config.disabled.contains(d.code.as_str())
|
||||||
if ctx.config.disabled.contains(code.as_str()) {
|
&& !(ctx.config.disable_experimental && d.experimental)
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ctx.config.disable_experimental && d.experimental {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res
|
res
|
||||||
|
@ -65,9 +65,14 @@ mod baz {}
|
|||||||
expect![[r#"
|
expect![[r#"
|
||||||
[
|
[
|
||||||
Diagnostic {
|
Diagnostic {
|
||||||
|
code: DiagnosticCode(
|
||||||
|
"unresolved-module",
|
||||||
|
),
|
||||||
message: "unresolved module",
|
message: "unresolved module",
|
||||||
range: 0..8,
|
range: 0..8,
|
||||||
severity: Error,
|
severity: Error,
|
||||||
|
unused: false,
|
||||||
|
experimental: false,
|
||||||
fixes: Some(
|
fixes: Some(
|
||||||
[
|
[
|
||||||
Assist {
|
Assist {
|
||||||
@ -98,13 +103,6 @@ mod baz {}
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
unused: false,
|
|
||||||
code: Some(
|
|
||||||
DiagnosticCode(
|
|
||||||
"unresolved-module",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
experimental: false,
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -1229,14 +1229,13 @@ pub(crate) fn publish_diagnostics(
|
|||||||
.map(|d| Diagnostic {
|
.map(|d| Diagnostic {
|
||||||
range: to_proto::range(&line_index, d.range),
|
range: to_proto::range(&line_index, d.range),
|
||||||
severity: Some(to_proto::diagnostic_severity(d.severity)),
|
severity: Some(to_proto::diagnostic_severity(d.severity)),
|
||||||
code: d.code.map(|d| d.as_str().to_owned()).map(NumberOrString::String),
|
code: Some(NumberOrString::String(d.code.as_str().to_string())),
|
||||||
code_description: d.code.and_then(|code| {
|
code_description: Some(lsp_types::CodeDescription {
|
||||||
lsp_types::Url::parse(&format!(
|
href: lsp_types::Url::parse(&format!(
|
||||||
"https://rust-analyzer.github.io/manual.html#{}",
|
"https://rust-analyzer.github.io/manual.html#{}",
|
||||||
code.as_str()
|
d.code.as_str()
|
||||||
))
|
))
|
||||||
.ok()
|
.unwrap(),
|
||||||
.map(|href| lsp_types::CodeDescription { href })
|
|
||||||
}),
|
}),
|
||||||
source: Some("rust-analyzer".to_string()),
|
source: Some("rust-analyzer".to_string()),
|
||||||
message: d.message,
|
message: d.message,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user