Skip to content

Commit 7c1d5f2

Browse files
committed
Fix line index rebuild during incremental changes
1 parent 191abf3 commit 7c1d5f2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,13 @@ fn apply_document_changes(
676676
// remember the last valid line in the index and only rebuild it if needed.
677677
enum IndexValid {
678678
All,
679-
UpToLine(u64),
679+
UpToLineExclusive(u64),
680680
}
681681

682682
impl IndexValid {
683683
fn covers(&self, line: u64) -> bool {
684684
match *self {
685-
IndexValid::UpToLine(to) => to >= line,
685+
IndexValid::UpToLineExclusive(to) => to > line,
686686
_ => true,
687687
}
688688
}
@@ -692,10 +692,10 @@ fn apply_document_changes(
692692
for change in content_changes {
693693
match change.range {
694694
Some(range) => {
695-
if !index_valid.covers(range.start.line) {
695+
if !index_valid.covers(range.end.line) {
696696
line_index = Cow::Owned(LineIndex::new(&old_text));
697697
}
698-
index_valid = IndexValid::UpToLine(range.start.line);
698+
index_valid = IndexValid::UpToLineExclusive(range.start.line);
699699
let range = range.conv_with(&line_index);
700700
let mut text = old_text.to_owned();
701701
match std::panic::catch_unwind(move || {
@@ -713,7 +713,7 @@ fn apply_document_changes(
713713
}
714714
None => {
715715
*old_text = change.text;
716-
index_valid = IndexValid::UpToLine(0);
716+
index_valid = IndexValid::UpToLineExclusive(0);
717717
}
718718
}
719719
}

0 commit comments

Comments
 (0)