aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs14
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.
3use std::{ 3use std::{
4 borrow::Cow,
5 env, fmt, panic, 4 env, fmt, panic,
6 time::{Duration, Instant}, 5 time::{Duration, Instant},
7}; 6};
8 7
9use crossbeam_channel::{select, Receiver}; 8use crossbeam_channel::{select, Receiver};
10use lsp_server::{Connection, Notification, Request, Response}; 9use lsp_server::{Connection, Notification, Request, Response};
11use lsp_types::{notification::Notification as _, DidChangeTextDocumentParams}; 10use lsp_types::notification::Notification as _;
12use ra_db::VfsPath; 11use ra_db::VfsPath;
13use ra_ide::{Canceled, FileId}; 12use ra_ide::{Canceled, FileId};
14use ra_prof::profile; 13use 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(&params.text_document.uri) { 426 if let Ok(path) = from_proto::vfs_path(&params.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 }