Skip to content

Commit

Permalink
Fix diagnostics deduplicating. Add check for file relevance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcticae committed Oct 2, 2024
1 parent 227cea9 commit 038bb85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions crates/cairo-lang-diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ impl<TEntry: DiagnosticEntry> Diagnostics<TEntry> {
return diagnostic_with_dup;
}
let files_db = db.upcast();
let mut indexed_dup_diagnostic = diagnostic_with_dup
.iter()
.enumerate()
.sorted_by_key(|(idx, diag)| (diag.location(db).user_location(files_db).span, *idx));
let mut indexed_dup_diagnostic =
diagnostic_with_dup.iter().enumerate().sorted_by_cached_key(|(idx, diag)| {
(diag.location(db).user_location(files_db).span, diag.format(db), *idx)
});
let mut prev_diagnostic_indexed = indexed_dup_diagnostic.next().unwrap();
let mut diagnostic_without_dup = vec![prev_diagnostic_indexed];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn map_cairo_diagnostics_to_lsp<T: DiagnosticEntry>(
db: &T::DbType,
diags: &mut Vec<Diagnostic>,
diagnostics: &Diagnostics<T>,
processed_file_id: &FileId,
trace_macro_diagnostics: bool,
) {
for diagnostic in if trace_macro_diagnostics {
Expand Down Expand Up @@ -43,14 +44,18 @@ pub fn map_cairo_diagnostics_to_lsp<T: DiagnosticEntry>(
}
}

let Some((range, _)) = get_mapped_range_and_add_mapping_note(
let Some((range, mapped_file_id)) = get_mapped_range_and_add_mapping_note(
db,
&diagnostic.location(db),
trace_macro_diagnostics.then_some(&mut related_information),
"Diagnostic mapped from here.",
) else {
continue;
};

if mapped_file_id != *processed_file_id {
continue;
}
diags.push(Diagnostic {
range,
message,
Expand Down
3 changes: 3 additions & 0 deletions crates/cairo-lang-language-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,18 +534,21 @@ impl Backend {
(*db).upcast(),
&mut diags,
&new_file_diagnostics.parser,
file,
trace_macro_diagnostics,
);
map_cairo_diagnostics_to_lsp(
(*db).upcast(),
&mut diags,
&new_file_diagnostics.semantic,
file,
trace_macro_diagnostics,
);
map_cairo_diagnostics_to_lsp(
(*db).upcast(),
&mut diags,
&new_file_diagnostics.lowering,
file,
trace_macro_diagnostics,
);

Expand Down

0 comments on commit 038bb85

Please sign in to comment.