aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-13 20:17:05 +0100
committerAleksey Kladov <[email protected]>2021-06-13 20:17:36 +0100
commit500c909c76a5165e3e3c6ff2eacc009c90f08bbe (patch)
tree5b57ca5243009f6a63cb6f3d37acb524b8cd2c80
parentb404b91da68556141ad39fffcef2865f073dd3d1 (diff)
internal: diagnostic code is mandatory
-rw-r--r--crates/ide/src/diagnostics.rs23
-rw-r--r--crates/ide/src/diagnostics/unresolved_module.rs12
-rw-r--r--crates/rust-analyzer/src/handlers.rs11
3 files changed, 17 insertions, 29 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 253c360bb..815a633e5 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -51,28 +51,26 @@ impl DiagnosticCode {
51 51
52#[derive(Debug)] 52#[derive(Debug)]
53pub struct Diagnostic { 53pub struct Diagnostic {
54 // pub name: Option<String>, 54 pub code: DiagnosticCode,
55 pub message: String, 55 pub message: String,
56 pub range: TextRange, 56 pub range: TextRange,
57 pub severity: Severity, 57 pub severity: Severity,
58 pub fixes: Option<Vec<Assist>>,
59 pub unused: bool, 58 pub unused: bool,
60 pub code: Option<DiagnosticCode>,
61 pub experimental: bool, 59 pub experimental: bool,
60 pub fixes: Option<Vec<Assist>>,
62} 61}
63 62
64impl Diagnostic { 63impl Diagnostic {
65 fn new(code: &'static str, message: impl Into<String>, range: TextRange) -> Diagnostic { 64 fn new(code: &'static str, message: impl Into<String>, range: TextRange) -> Diagnostic {
66 let message = message.into(); 65 let message = message.into();
67 let code = Some(DiagnosticCode(code)); 66 Diagnostic {
68 Self { 67 code: DiagnosticCode(code),
69 message, 68 message,
70 range, 69 range,
71 severity: Severity::Error, 70 severity: Severity::Error,
72 fixes: None,
73 unused: false, 71 unused: false,
74 code,
75 experimental: false, 72 experimental: false,
73 fixes: None,
76 } 74 }
77 } 75 }
78 76
@@ -181,15 +179,8 @@ pub(crate) fn diagnostics(
181 } 179 }
182 180
183 res.retain(|d| { 181 res.retain(|d| {
184 if let Some(code) = d.code { 182 !ctx.config.disabled.contains(d.code.as_str())
185 if ctx.config.disabled.contains(code.as_str()) { 183 && !(ctx.config.disable_experimental && d.experimental)
186 return false;
187 }
188 }
189 if ctx.config.disable_experimental && d.experimental {
190 return false;
191 }
192 true
193 }); 184 });
194 185
195 res 186 res
diff --git a/crates/ide/src/diagnostics/unresolved_module.rs b/crates/ide/src/diagnostics/unresolved_module.rs
index b1da8f0e1..977b46414 100644
--- a/crates/ide/src/diagnostics/unresolved_module.rs
+++ b/crates/ide/src/diagnostics/unresolved_module.rs
@@ -65,9 +65,14 @@ mod baz {}
65 expect![[r#" 65 expect![[r#"
66 [ 66 [
67 Diagnostic { 67 Diagnostic {
68 code: DiagnosticCode(
69 "unresolved-module",
70 ),
68 message: "unresolved module", 71 message: "unresolved module",
69 range: 0..8, 72 range: 0..8,
70 severity: Error, 73 severity: Error,
74 unused: false,
75 experimental: false,
71 fixes: Some( 76 fixes: Some(
72 [ 77 [
73 Assist { 78 Assist {
@@ -98,13 +103,6 @@ mod baz {}
98 }, 103 },
99 ], 104 ],
100 ), 105 ),
101 unused: false,
102 code: Some(
103 DiagnosticCode(
104 "unresolved-module",
105 ),
106 ),
107 experimental: false,
108 }, 106 },
109 ] 107 ]
110 "#]], 108 "#]],
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index a81e398c4..ccf66294f 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1229,14 +1229,13 @@ pub(crate) fn publish_diagnostics(
1229 .map(|d| Diagnostic { 1229 .map(|d| Diagnostic {
1230 range: to_proto::range(&line_index, d.range), 1230 range: to_proto::range(&line_index, d.range),
1231 severity: Some(to_proto::diagnostic_severity(d.severity)), 1231 severity: Some(to_proto::diagnostic_severity(d.severity)),
1232 code: d.code.map(|d| d.as_str().to_owned()).map(NumberOrString::String), 1232 code: Some(NumberOrString::String(d.code.as_str().to_string())),
1233 code_description: d.code.and_then(|code| { 1233 code_description: Some(lsp_types::CodeDescription {
1234 lsp_types::Url::parse(&format!( 1234 href: lsp_types::Url::parse(&format!(
1235 "https://rust-analyzer.github.io/manual.html#{}", 1235 "https://rust-analyzer.github.io/manual.html#{}",
1236 code.as_str() 1236 d.code.as_str()
1237 )) 1237 ))
1238 .ok() 1238 .unwrap(),
1239 .map(|href| lsp_types::CodeDescription { href })
1240 }), 1239 }),
1241 source: Some("rust-analyzer".to_string()), 1240 source: Some("rust-analyzer".to_string()),
1242 message: d.message, 1241 message: d.message,