From 7c1d5f286a971484fc1f1d367e762853471873e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 4 May 2020 20:04:30 +0300 Subject: Fix line index rebuild during incremental changes --- crates/rust-analyzer/src/main_loop.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 401fae755..b163ea848 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -676,13 +676,13 @@ fn apply_document_changes( // remember the last valid line in the index and only rebuild it if needed. enum IndexValid { All, - UpToLine(u64), + UpToLineExclusive(u64), } impl IndexValid { fn covers(&self, line: u64) -> bool { match *self { - IndexValid::UpToLine(to) => to >= line, + IndexValid::UpToLineExclusive(to) => to > line, _ => true, } } @@ -692,10 +692,10 @@ fn apply_document_changes( for change in content_changes { match change.range { Some(range) => { - if !index_valid.covers(range.start.line) { + if !index_valid.covers(range.end.line) { line_index = Cow::Owned(LineIndex::new(&old_text)); } - index_valid = IndexValid::UpToLine(range.start.line); + index_valid = IndexValid::UpToLineExclusive(range.start.line); let range = range.conv_with(&line_index); let mut text = old_text.to_owned(); match std::panic::catch_unwind(move || { @@ -713,7 +713,7 @@ fn apply_document_changes( } None => { *old_text = change.text; - index_valid = IndexValid::UpToLine(0); + index_valid = IndexValid::UpToLineExclusive(0); } } } -- cgit v1.2.3