aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorLaurenČ›iu Nicola <[email protected]>2020-07-25 10:56:39 +0100
committerLaurenČ›iu Nicola <[email protected]>2020-07-25 10:56:39 +0100
commit83a87fcd11298d8de32801ac6496ddf8b4e9c0e1 (patch)
tree62608bc0ddaee4fb4b0000840f9e632397f2c78d /crates/rust-analyzer/src/main_loop.rs
parent48f9a05692e509c3bfd7df5b1088fe2863617714 (diff)
Restore line index micro-optimization
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 51626fcd5..0ace4cb45 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -1,13 +1,14 @@
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,
4 env, fmt, panic, 5 env, fmt, panic,
5 time::{Duration, Instant}, 6 time::{Duration, Instant},
6}; 7};
7 8
8use crossbeam_channel::{select, Receiver}; 9use crossbeam_channel::{select, Receiver};
9use lsp_server::{Connection, Notification, Request, Response}; 10use lsp_server::{Connection, Notification, Request, Response};
10use lsp_types::notification::Notification as _; 11use lsp_types::{notification::Notification as _, DidChangeTextDocumentParams};
11use ra_db::VfsPath; 12use ra_db::VfsPath;
12use ra_ide::{Canceled, FileId}; 13use ra_ide::{Canceled, FileId};
13use ra_prof::profile; 14use ra_prof::profile;
@@ -421,15 +422,20 @@ impl GlobalState {
421 })? 422 })?
422 .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| { 423 .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| {
423 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) { 424 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
424 let doc = this.mem_docs.get_mut(&path).unwrap(); 425 let DidChangeTextDocumentParams { text_document, content_changes } = params;
425 let vfs = &mut this.vfs.write().0; 426 let vfs = &mut this.vfs.write().0;
427 let world = this.snapshot();
426 let file_id = vfs.file_id(&path).unwrap(); 428 let file_id = vfs.file_id(&path).unwrap();
429
430 // let file_id = vfs.file_id(&path).unwrap();
427 let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap(); 431 let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap();
428 apply_document_changes(&mut text, params.content_changes); 432 let line_index = world.analysis.file_line_index(file_id)?;
433 apply_document_changes(&mut text, content_changes, Cow::Borrowed(&line_index));
429 434
430 // The version passed in DidChangeTextDocument is the version after all edits are applied 435 // The version passed in DidChangeTextDocument is the version after all edits are applied
431 // so we should apply it before the vfs is notified. 436 // so we should apply it before the vfs is notified.
432 doc.version = params.text_document.version; 437 let doc = this.mem_docs.get_mut(&path).unwrap();
438 doc.version = text_document.version;
433 439
434 vfs.set_file_contents(path.clone(), Some(text.into_bytes())); 440 vfs.set_file_contents(path.clone(), Some(text.into_bytes()));
435 } 441 }