Skip to content

Commit

Permalink
lsp: Skip computation of edits_since_save when there are no disk ba…
Browse files Browse the repository at this point in the history
…sed diagnostics (#23269)

Thought of this improvement while @ConradIrwin and I were looking into
whether this code is misbehaving. It seems not to be.

Release Notes:

- N/A
  • Loading branch information
mgsloan authored Jan 18, 2025
1 parent 9a7b73b commit 10f3586
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions crates/project/src/lsp_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,30 +1826,34 @@ impl LocalLspStore {
.then_with(|| a.message.cmp(&b.message))
}

let snapshot = self.buffer_snapshot_for_lsp_version(buffer, server_id, version, cx)?;

diagnostics.sort_unstable_by(|a, b| {
Ordering::Equal
.then_with(|| a.range.start.cmp(&b.range.start))
.then_with(|| b.range.end.cmp(&a.range.end))
.then_with(|| compare_diagnostics(&a.diagnostic, &b.diagnostic))
});

let snapshot = self.buffer_snapshot_for_lsp_version(buffer, server_id, version, cx)?;

let edits_since_save = std::cell::LazyCell::new(|| {
let saved_version = buffer.read(cx).saved_version();
Patch::new(
snapshot
.edits_since::<Unclipped<PointUtf16>>(saved_version)
.collect(),
)
});

let mut sanitized_diagnostics = Vec::new();
let edits_since_save = Patch::new(
snapshot
.edits_since::<Unclipped<PointUtf16>>(buffer.read(cx).saved_version())
.collect(),
);
for entry in diagnostics {
let start;
let end;
if entry.diagnostic.is_disk_based {
// Some diagnostics are based on files on disk instead of buffers'
// current contents. Adjust these diagnostics' ranges to reflect
// any unsaved edits.
start = edits_since_save.old_to_new(entry.range.start);
end = edits_since_save.old_to_new(entry.range.end);
start = (*edits_since_save).old_to_new(entry.range.start);
end = (*edits_since_save).old_to_new(entry.range.end);
} else {
start = entry.range.start;
end = entry.range.end;
Expand Down

0 comments on commit 10f3586

Please sign in to comment.