Skip to content

Commit 6ddcdb8

Browse files
bors[bot]kjeremy
andauthored
Merge #5511
5511: Set the document version after changes are applied but before vfs r=kjeremy a=kjeremy Co-authored-by: kjeremy <kjeremy@gmail.com>
2 parents 45eb95d + c9531dc commit 6ddcdb8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,17 @@ impl GlobalState {
420420
})?
421421
.on::<lsp_types::notification::DidChangeTextDocument>(|this, params| {
422422
if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
423-
*this.mem_docs.get_mut(&path).unwrap() = params.text_document.version;
423+
let doc = this.mem_docs.get_mut(&path).unwrap();
424424
let vfs = &mut this.vfs.write().0;
425425
let file_id = vfs.file_id(&path).unwrap();
426426
let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap();
427427
apply_document_changes(&mut text, params.content_changes);
428-
vfs.set_file_contents(path.clone(), Some(text.into_bytes()));
429428

430-
this.mem_docs.insert(path, params.text_document.version);
429+
// The version passed in DidChangeTextDocument is the version after all edits are applied
430+
// so we should apply it before the vfs is notified.
431+
*doc = params.text_document.version;
432+
433+
vfs.set_file_contents(path.clone(), Some(text.into_bytes()));
431434
}
432435
Ok(())
433436
})?

0 commit comments

Comments
 (0)