Skip to content

Commit 647749a

Browse files
authored
Merge pull request #18519 from ChayimFriedman2/invalid-offset
fix: Fix related documents diagnostics
2 parents cc4ffa7 + 744e8e8 commit 647749a

File tree

1 file changed

+7
-3
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src/handlers

1 file changed

+7
-3
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,16 @@ pub(crate) fn handle_document_diagnostics(
511511
.into_iter()
512512
.filter_map(|d| {
513513
let file = d.range.file_id;
514-
let diagnostic = convert_diagnostic(&line_index, d);
515514
if file == file_id {
515+
let diagnostic = convert_diagnostic(&line_index, d);
516516
return Some(diagnostic);
517517
}
518518
if supports_related {
519-
related_documents.entry(file).or_insert_with(Vec::new).push(diagnostic);
519+
let (diagnostics, line_index) = related_documents
520+
.entry(file)
521+
.or_insert_with(|| (Vec::new(), snap.file_line_index(file).ok()));
522+
let diagnostic = convert_diagnostic(line_index.as_mut()?, d);
523+
diagnostics.push(diagnostic);
520524
}
521525
None
522526
});
@@ -529,7 +533,7 @@ pub(crate) fn handle_document_diagnostics(
529533
related_documents: related_documents.is_empty().not().then(|| {
530534
related_documents
531535
.into_iter()
532-
.map(|(id, items)| {
536+
.map(|(id, (items, _))| {
533537
(
534538
to_proto::url(&snap, id),
535539
lsp_types::DocumentDiagnosticReportKind::Full(

0 commit comments

Comments
 (0)