Tolerate language servers reporting non-monotonic buffer versions

This isn't perfect but we'll retain up to 10 old versions just in case there
are race conditions in the language server. We haven't seen this in the wild
but we're concerned about diagnostic reporting racing with code action
resolution.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-02-07 16:29:05 +01:00
parent a172c3c5c6
commit 7a35ea7b25
2 changed files with 16 additions and 12 deletions

View File

@ -1025,14 +1025,7 @@ impl Buffer {
let version = version.map(|version| version as usize);
let content =
if let Some((version, language_server)) = version.zip(self.language_server.as_mut()) {
language_server
.pending_snapshots
.retain(|&v, _| v >= version);
let snapshot = language_server
.pending_snapshots
.get(&version)
.ok_or_else(|| anyhow!("missing snapshot"))?;
&snapshot.buffer_snapshot
language_server.snapshot_for_version(version)?
} else {
self.deref()
};
@ -2772,6 +2765,20 @@ impl operation_queue::Operation for Operation {
}
}
impl LanguageServerState {
fn snapshot_for_version(&mut self, version: usize) -> Result<&text::BufferSnapshot> {
const OLD_VERSIONS_TO_RETAIN: usize = 10;
self.pending_snapshots
.retain(|&v, _| v + OLD_VERSIONS_TO_RETAIN >= version);
let snapshot = self
.pending_snapshots
.get(&version)
.ok_or_else(|| anyhow!("missing snapshot"))?;
Ok(&snapshot.buffer_snapshot)
}
}
impl Default for Diagnostic {
fn default() -> Self {
Self {

View File

@ -1241,10 +1241,7 @@ impl Project {
lsp::DocumentChangeOperation::Edit(edit) => todo!(),
}
}
// match edit {
// Ok(edit) => edit.,
// Err(_) => todo!(),
// }
Ok(Default::default())
})
} else {