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