mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 20:35:09 +00:00
Set the document version after changes are applied but before vfs
This commit is contained in:
parent
bd44f3a620
commit
c9531dc797
1 changed files with 6 additions and 3 deletions
|
@ -420,14 +420,17 @@ impl GlobalState {
|
||||||
})?
|
})?
|
||||||
.on::<lsp_types::notification::DidChangeTextDocument>(|this, params| {
|
.on::<lsp_types::notification::DidChangeTextDocument>(|this, params| {
|
||||||
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
||||||
*this.mem_docs.get_mut(&path).unwrap() = params.text_document.version;
|
let doc = this.mem_docs.get_mut(&path).unwrap();
|
||||||
let vfs = &mut this.vfs.write().0;
|
let vfs = &mut this.vfs.write().0;
|
||||||
let file_id = vfs.file_id(&path).unwrap();
|
let file_id = vfs.file_id(&path).unwrap();
|
||||||
let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap();
|
let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap();
|
||||||
apply_document_changes(&mut text, params.content_changes);
|
apply_document_changes(&mut text, params.content_changes);
|
||||||
vfs.set_file_contents(path.clone(), Some(text.into_bytes()));
|
|
||||||
|
|
||||||
this.mem_docs.insert(path, params.text_document.version);
|
// The version passed in DidChangeTextDocument is the version after all edits are applied
|
||||||
|
// so we should apply it before the vfs is notified.
|
||||||
|
*doc = params.text_document.version;
|
||||||
|
|
||||||
|
vfs.set_file_contents(path.clone(), Some(text.into_bytes()));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
|
|
Loading…
Reference in a new issue