diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index ac95e428e..e95d4157c 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -420,14 +420,17 @@ impl GlobalState { | |||
420 | })? | 420 | })? |
421 | .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| { | 421 | .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| { |
422 | if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) { | 422 | if let Ok(path) = from_proto::vfs_path(¶ms.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(); |
424 | let vfs = &mut this.vfs.write().0; | 424 | let vfs = &mut this.vfs.write().0; |
425 | let file_id = vfs.file_id(&path).unwrap(); | 425 | let file_id = vfs.file_id(&path).unwrap(); |
426 | let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap(); | 426 | let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap(); |
427 | apply_document_changes(&mut text, params.content_changes); | 427 | apply_document_changes(&mut text, params.content_changes); |
428 | vfs.set_file_contents(path.clone(), Some(text.into_bytes())); | ||
429 | 428 | ||
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())); | ||
431 | } | 434 | } |
432 | Ok(()) | 435 | Ok(()) |
433 | })? | 436 | })? |