diff options
-rw-r--r-- | crates/rust-analyzer/src/diagnostics/to_proto.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 5de481021..c632630d1 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs | |||
@@ -35,7 +35,7 @@ fn diagnostic_severity( | |||
35 | } | 35 | } |
36 | 36 | ||
37 | /// Converts a Rust span to a LSP location | 37 | /// Converts a Rust span to a LSP location |
38 | fn convert_location(workspace_root: &Path, span: &DiagnosticSpan) -> lsp_types::Location { | 38 | fn location(workspace_root: &Path, span: &DiagnosticSpan) -> lsp_types::Location { |
39 | let file_name = workspace_root.join(&span.file_name); | 39 | let file_name = workspace_root.join(&span.file_name); |
40 | let uri = url_from_abs_path(&file_name); | 40 | let uri = url_from_abs_path(&file_name); |
41 | 41 | ||
@@ -56,7 +56,7 @@ fn diagnostic_related_information( | |||
56 | span: &DiagnosticSpan, | 56 | span: &DiagnosticSpan, |
57 | ) -> Option<lsp_types::DiagnosticRelatedInformation> { | 57 | ) -> Option<lsp_types::DiagnosticRelatedInformation> { |
58 | let message = span.label.clone()?; | 58 | let message = span.label.clone()?; |
59 | let location = convert_location(workspace_root, span); | 59 | let location = location(workspace_root, span); |
60 | Some(lsp_types::DiagnosticRelatedInformation { location, message }) | 60 | Some(lsp_types::DiagnosticRelatedInformation { location, message }) |
61 | } | 61 | } |
62 | 62 | ||
@@ -84,7 +84,7 @@ fn map_rust_child_diagnostic( | |||
84 | let mut edit_map: HashMap<lsp_types::Url, Vec<lsp_types::TextEdit>> = HashMap::new(); | 84 | let mut edit_map: HashMap<lsp_types::Url, Vec<lsp_types::TextEdit>> = HashMap::new(); |
85 | for &span in &spans { | 85 | for &span in &spans { |
86 | if let Some(suggested_replacement) = &span.suggested_replacement { | 86 | if let Some(suggested_replacement) = &span.suggested_replacement { |
87 | let location = convert_location(workspace_root, span); | 87 | let location = location(workspace_root, span); |
88 | let edit = lsp_types::TextEdit::new(location.range, suggested_replacement.clone()); | 88 | let edit = lsp_types::TextEdit::new(location.range, suggested_replacement.clone()); |
89 | edit_map.entry(location.uri).or_default().push(edit); | 89 | edit_map.entry(location.uri).or_default().push(edit); |
90 | } | 90 | } |
@@ -93,7 +93,7 @@ fn map_rust_child_diagnostic( | |||
93 | if edit_map.is_empty() { | 93 | if edit_map.is_empty() { |
94 | MappedRustChildDiagnostic::SubDiagnostic(SubDiagnostic { | 94 | MappedRustChildDiagnostic::SubDiagnostic(SubDiagnostic { |
95 | related: lsp_types::DiagnosticRelatedInformation { | 95 | related: lsp_types::DiagnosticRelatedInformation { |
96 | location: convert_location(workspace_root, spans[0]), | 96 | location: location(workspace_root, spans[0]), |
97 | message: rd.message.clone(), | 97 | message: rd.message.clone(), |
98 | }, | 98 | }, |
99 | suggested_fix: None, | 99 | suggested_fix: None, |
@@ -101,7 +101,7 @@ fn map_rust_child_diagnostic( | |||
101 | } else { | 101 | } else { |
102 | MappedRustChildDiagnostic::SubDiagnostic(SubDiagnostic { | 102 | MappedRustChildDiagnostic::SubDiagnostic(SubDiagnostic { |
103 | related: lsp_types::DiagnosticRelatedInformation { | 103 | related: lsp_types::DiagnosticRelatedInformation { |
104 | location: convert_location(workspace_root, spans[0]), | 104 | location: location(workspace_root, spans[0]), |
105 | message: rd.message.clone(), | 105 | message: rd.message.clone(), |
106 | }, | 106 | }, |
107 | suggested_fix: Some(lsp_ext::CodeAction { | 107 | suggested_fix: Some(lsp_ext::CodeAction { |
@@ -217,7 +217,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
217 | primary_spans | 217 | primary_spans |
218 | .iter() | 218 | .iter() |
219 | .flat_map(|primary_span| { | 219 | .flat_map(|primary_span| { |
220 | let location = convert_location(workspace_root, &primary_span); | 220 | let primary_location = location(workspace_root, &primary_span); |
221 | 221 | ||
222 | let mut message = message.clone(); | 222 | let mut message = message.clone(); |
223 | if needs_primary_span_label { | 223 | if needs_primary_span_label { |
@@ -240,7 +240,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
240 | }) | 240 | }) |
241 | .skip(1); | 241 | .skip(1); |
242 | for macro_span in macro_calls { | 242 | for macro_span in macro_calls { |
243 | let in_macro_location = convert_location(workspace_root, ¯o_span); | 243 | let in_macro_location = location(workspace_root, ¯o_span); |
244 | related_info_macro_calls.push(lsp_types::DiagnosticRelatedInformation { | 244 | related_info_macro_calls.push(lsp_types::DiagnosticRelatedInformation { |
245 | location: in_macro_location.clone(), | 245 | location: in_macro_location.clone(), |
246 | message: "Error originated from macro call here".to_string(), | 246 | message: "Error originated from macro call here".to_string(), |
@@ -248,7 +248,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
248 | // For the additional in-macro diagnostic we add the inverse message pointing to the error location in code. | 248 | // For the additional in-macro diagnostic we add the inverse message pointing to the error location in code. |
249 | let information_for_additional_diagnostic = | 249 | let information_for_additional_diagnostic = |
250 | vec![lsp_types::DiagnosticRelatedInformation { | 250 | vec![lsp_types::DiagnosticRelatedInformation { |
251 | location: location.clone(), | 251 | location: primary_location.clone(), |
252 | message: "Exact error occurred here".to_string(), | 252 | message: "Exact error occurred here".to_string(), |
253 | }]; | 253 | }]; |
254 | 254 | ||
@@ -273,9 +273,9 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
273 | 273 | ||
274 | // Emit the primary diagnostic. | 274 | // Emit the primary diagnostic. |
275 | diagnostics.push(MappedRustDiagnostic { | 275 | diagnostics.push(MappedRustDiagnostic { |
276 | url: location.uri.clone(), | 276 | url: primary_location.uri.clone(), |
277 | diagnostic: lsp_types::Diagnostic { | 277 | diagnostic: lsp_types::Diagnostic { |
278 | range: location.range, | 278 | range: primary_location.range, |
279 | severity, | 279 | severity, |
280 | code: code.clone().map(lsp_types::NumberOrString::String), | 280 | code: code.clone().map(lsp_types::NumberOrString::String), |
281 | code_description: code_description.clone(), | 281 | code_description: code_description.clone(), |
@@ -303,7 +303,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
303 | // This is useful because they will show up in the user's editor, unlike | 303 | // This is useful because they will show up in the user's editor, unlike |
304 | // `related_information`, which just produces hard-to-read links, at least in VS Code. | 304 | // `related_information`, which just produces hard-to-read links, at least in VS Code. |
305 | let back_ref = lsp_types::DiagnosticRelatedInformation { | 305 | let back_ref = lsp_types::DiagnosticRelatedInformation { |
306 | location, | 306 | location: primary_location, |
307 | message: "original diagnostic".to_string(), | 307 | message: "original diagnostic".to_string(), |
308 | }; | 308 | }; |
309 | for sub in &subdiagnostics { | 309 | for sub in &subdiagnostics { |