about summary refs log tree commit diff
path: root/src/tools/rust-analyzer
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2024-11-16 21:17:15 +0200
committerChayim Refael Friedman <chayimfr@gmail.com>2024-11-16 21:17:15 +0200
commit744e8e870c4109c4bcd74d6c1283866bf2a20cda (patch)
treede8fae284a7d04e96be4b0270f94c25e7df1cd5d /src/tools/rust-analyzer
parentcc4ffa7d6fdb61c6c0182ac4efc336e2b2991753 (diff)
downloadrust-744e8e870c4109c4bcd74d6c1283866bf2a20cda.tar.gz
rust-744e8e870c4109c4bcd74d6c1283866bf2a20cda.zip
Fix related documents diagnostics
They were converted to LSP position using the current file's line index, which is obviously wrong.
Diffstat (limited to 'src/tools/rust-analyzer')
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs
index a5c9d2823e0..4975467ece9 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs
@@ -511,12 +511,16 @@ pub(crate) fn handle_document_diagnostics(
         .into_iter()
         .filter_map(|d| {
             let file = d.range.file_id;
-            let diagnostic = convert_diagnostic(&line_index, d);
             if file == file_id {
+                let diagnostic = convert_diagnostic(&line_index, d);
                 return Some(diagnostic);
             }
             if supports_related {
-                related_documents.entry(file).or_insert_with(Vec::new).push(diagnostic);
+                let (diagnostics, line_index) = related_documents
+                    .entry(file)
+                    .or_insert_with(|| (Vec::new(), snap.file_line_index(file).ok()));
+                let diagnostic = convert_diagnostic(line_index.as_mut()?, d);
+                diagnostics.push(diagnostic);
             }
             None
         });
@@ -529,7 +533,7 @@ pub(crate) fn handle_document_diagnostics(
             related_documents: related_documents.is_empty().not().then(|| {
                 related_documents
                     .into_iter()
-                    .map(|(id, items)| {
+                    .map(|(id, (items, _))| {
                         (
                             to_proto::url(&snap, id),
                             lsp_types::DocumentDiagnosticReportKind::Full(