diff options
author | Michael Lazear <[email protected]> | 2020-08-03 21:35:32 +0100 |
---|---|---|
committer | Michael Lazear <[email protected]> | 2020-08-03 21:35:32 +0100 |
commit | 2e72e74dbd41471579a10b564d97e23248aae594 (patch) | |
tree | 01de0be46feaa0237adb61d30fe09f2445be599f /crates/rust-analyzer/src/main_loop.rs | |
parent | 33e53d472158746c6a0150538bea348ce0e5a22d (diff) |
Revert "Restore line index micro-optimization"
This reverts commit 83a87fcd11298d8de32801ac6496ddf8b4e9c0e1.
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 0ace4cb45..51626fcd5 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; |
@@ -422,20 +421,15 @@ impl GlobalState { | |||
422 | })? | 421 | })? |
423 | .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| { | 422 | .on::<lsp_types::notification::DidChangeTextDocument>(|this, params| { |
424 | if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) { | 423 | if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) { |
425 | let DidChangeTextDocumentParams { text_document, content_changes } = params; | 424 | let doc = this.mem_docs.get_mut(&path).unwrap(); |
426 | let vfs = &mut this.vfs.write().0; | 425 | let vfs = &mut this.vfs.write().0; |
427 | let world = this.snapshot(); | ||
428 | let file_id = vfs.file_id(&path).unwrap(); | 426 | let file_id = vfs.file_id(&path).unwrap(); |
429 | |||
430 | // let file_id = vfs.file_id(&path).unwrap(); | ||
431 | let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap(); | 427 | let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec()).unwrap(); |
432 | let line_index = world.analysis.file_line_index(file_id)?; | 428 | apply_document_changes(&mut text, params.content_changes); |
433 | apply_document_changes(&mut text, content_changes, Cow::Borrowed(&line_index)); | ||
434 | 429 | ||
435 | // The version passed in DidChangeTextDocument is the version after all edits are applied | 430 | // The version passed in DidChangeTextDocument is the version after all edits are applied |
436 | // so we should apply it before the vfs is notified. | 431 | // so we should apply it before the vfs is notified. |
437 | let doc = this.mem_docs.get_mut(&path).unwrap(); | 432 | doc.version = params.text_document.version; |
438 | doc.version = text_document.version; | ||
439 | 433 | ||
440 | vfs.set_file_contents(path.clone(), Some(text.into_bytes())); | 434 | vfs.set_file_contents(path.clone(), Some(text.into_bytes())); |
441 | } | 435 | } |