Skip to content

Commit 8e81a06

Browse files
committed
fix(lsp): refresh and relocate stale diagnostics
1 parent 7380cba commit 8e81a06

8 files changed

Lines changed: 949 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 153 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ json_comments = "0.2.2"
8282
lazy_static = "1.5.0"
8383
libloading = "0.8.9"
8484
nix = { version = "0.28.0", features = ["fs", "process", "signal"] }
85+
notify = "8.2.0"
8586
once_cell = "1.19.0"
8687
path-absolutize = "3.1.1"
8788
pulldown-cmark = "0.13"

src/editor.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12748,6 +12748,20 @@ impl Editor {
1274812748
self.update_diagnostics(uri, diagnostics, diagnostics::DiagnosticReportKind::Push)
1274912749
}
1275012750

12751+
fn clear_current_buffer_diagnostics(&mut self) {
12752+
if self.diagnostics.is_empty() {
12753+
return;
12754+
}
12755+
let Ok(Some(uri)) = self.current_buffer().uri() else {
12756+
return;
12757+
};
12758+
if self.diagnostics.remove(&uri).is_none() {
12759+
return;
12760+
}
12761+
self.diagnostic_reports.remove(&uri);
12762+
self.sync_diagnostic_gutter_signs();
12763+
}
12764+
1275112765
fn update_diagnostics(
1275212766
&mut self,
1275312767
uri: Option<&str>,
@@ -23791,6 +23805,21 @@ impl Editor {
2379123805
}
2379223806

2379323807
fn replace_range(&mut self, range: TextRange, new_text: &str) {
23808+
let diagnostic_edit = (!self.diagnostics.is_empty())
23809+
.then(|| self.current_buffer().uri().ok().flatten())
23810+
.flatten()
23811+
.and_then(|uri| {
23812+
self.diagnostics.contains_key(&uri).then(|| {
23813+
let source = self.current_buffer();
23814+
(
23815+
uri,
23816+
crate::lsp::Range {
23817+
start: source.position_to_lsp(range.start),
23818+
end: source.position_to_lsp(range.end),
23819+
},
23820+
)
23821+
})
23822+
});
2379423823
let pending =
2379523824
(self.config.lsp.enabled && self.current_buffer().file.is_some()).then(|| {
2379623825
let source = self.current_buffer();
@@ -23819,6 +23848,12 @@ impl Editor {
2381923848
new_text,
2382023849
);
2382123850
}
23851+
if let Some((uri, edit)) = diagnostic_edit {
23852+
if let Some(diagnostics) = self.diagnostic_reports.rebase(&uri, &edit, new_text) {
23853+
self.diagnostics.insert(uri, diagnostics);
23854+
self.sync_diagnostic_gutter_signs();
23855+
}
23856+
}
2382223857
perf::increment("edit:replacements", 1);
2382323858
self.update_anchors_for_edit(edit);
2382423859
self.set_special_mark_at_char('.', edit.start_char, AnchorAffinity::Left);
@@ -24358,6 +24393,7 @@ impl Editor {
2435824393
self.draw_commandline(render_buffer);
2435924394
return Ok(());
2436024395
};
24396+
self.clear_current_buffer_diagnostics();
2436124397
if let Some(transaction) = transaction {
2436224398
self.set_inline_history_transaction_applied(&transaction, false);
2436324399
}
@@ -24389,6 +24425,7 @@ impl Editor {
2438924425
self.draw_commandline(render_buffer);
2439024426
return Ok(());
2439124427
};
24428+
self.clear_current_buffer_diagnostics();
2439224429
if let Some(transaction) = self
2439324430
.current_buffer()
2439424431
.undo_history

0 commit comments

Comments
 (0)