diff options
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 075abf45c..ceddb2b05 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -1,14 +1,13 @@ | |||
1 | //! The main loop of `rust-analyzer` responsible for dispatching LSP | 1 | //! The main loop of `rust-analyzer` responsible for dispatching LSP |
2 | //! requests/replies and notifications back to the client. | 2 | //! requests/replies and notifications back to the client. |
3 | use std::{ | 3 | use std::{ |
4 | borrow::Cow, | ||
5 | env, fmt, panic, | 4 | env, fmt, panic, |
6 | time::{Duration, Instant}, | 5 | time::{Duration, Instant}, |
7 | }; | 6 | }; |
8 | 7 | ||
9 | use crossbeam_channel::{select, Receiver}; | 8 | use crossbeam_channel::{select, Receiver}; |
10 | use lsp_server::{Connection, Notification, Request, Response}; | 9 | use lsp_server::{Connection, Notification, Request, Response}; |
11 | use lsp_types::{notification::Notification as _, DidChangeTextDocumentParams}; | 10 | use lsp_types::notification::Notification as _; |
12 | use ra_db::VfsPath; | 11 | use ra_db::VfsPath; |
13 | use ra_ide::{Canceled, FileId}; | 12 | use ra_ide::{Canceled, FileId}; |
14 | use ra_prof::profile; | 13 | use ra_prof::profile; |
@@ -425,20 +424,15 @@ impl GlobalState { | |||
425 | })? | 424 | })? |
426 | .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| { | 425 | .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| { |
427 | if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) { | 426 | if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) { |
428 | let DidChangeTextDocumentParams { text_document, content_changes } = params; | 427 | let doc = this.mem_docs.get_mut(&path).unwrap(); |
429 | let vfs = &mut this.vfs.write().0; | 428 | let vfs = &mut this.vfs.write().0; |
430 | let world = this.snapshot(); | ||
431 | let file_id = vfs.file_id(&path).unwrap(); | 429 | let file_id = vfs.file_id(&path).unwrap(); |
432 | |||
433 | // let file_id = vfs.file_id(&path).unwrap(); | ||
434 | let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap(); | 430 | let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap(); |
435 | let line_index = world.analysis.file_line_index(file_id)?; | 431 | apply_document_changes(&mut text, params.content_changes); |
436 | apply_document_changes(&mut text, content_changes, Cow::Borrowed(&line_index)); | ||
437 | 432 | ||
438 | // The version passed in DidChangeTextDocument is the version after all edits are applied | 433 | // The version passed in DidChangeTextDocument is the version after all edits are applied |
439 | // so we should apply it before the vfs is notified. | 434 | // so we should apply it before the vfs is notified. |
440 | let doc = this.mem_docs.get_mut(&path).unwrap(); | 435 | doc.version = params.text_document.version; |
441 | doc.version = text_document.version; | ||
442 | 436 | ||
443 | vfs.set_file_contents(path.clone(), Some(text.into_bytes())); | 437 | vfs.set_file_contents(path.clone(), Some(text.into_bytes())); |
444 | } | 438 | } |