aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs19
1 files changed, 2 insertions, 17 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index cc9bb1726..887253d5b 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -669,14 +669,11 @@ fn apply_document_changes(
669 mut line_index: Cow<'_, LineIndex>, 669 mut line_index: Cow<'_, LineIndex>,
670 content_changes: Vec<TextDocumentContentChangeEvent>, 670 content_changes: Vec<TextDocumentContentChangeEvent>,
671) { 671) {
672 // Remove when https://github.com/rust-analyzer/rust-analyzer/issues/4263 is fixed.
673 let backup_text = old_text.clone();
674 let backup_changes = content_changes.clone();
675
676 // The changes we got must be applied sequentially, but can cross lines so we 672 // The changes we got must be applied sequentially, but can cross lines so we
677 // have to keep our line index updated. 673 // have to keep our line index updated.
678 // Some clients (e.g. Code) sort the ranges in reverse. As an optimization, we 674 // Some clients (e.g. Code) sort the ranges in reverse. As an optimization, we
679 // remember the last valid line in the index and only rebuild it if needed. 675 // remember the last valid line in the index and only rebuild it if needed.
676 // The VFS will normalize the end of lines to `\n`.
680 enum IndexValid { 677 enum IndexValid {
681 All, 678 All,
682 UpToLineExclusive(u64), 679 UpToLineExclusive(u64),
@@ -700,19 +697,7 @@ fn apply_document_changes(
700 } 697 }
701 index_valid = IndexValid::UpToLineExclusive(range.start.line); 698 index_valid = IndexValid::UpToLineExclusive(range.start.line);
702 let range = from_proto::text_range(&line_index, range); 699 let range = from_proto::text_range(&line_index, range);
703 let mut text = old_text.to_owned(); 700 old_text.replace_range(Range::<usize>::from(range), &change.text);
704 match std::panic::catch_unwind(move || {
705 text.replace_range(Range::<usize>::from(range), &change.text);
706 text
707 }) {
708 Ok(t) => *old_text = t,
709 Err(e) => {
710 eprintln!("Bug in incremental text synchronization. Please report the following output on https://github.com/rust-analyzer/rust-analyzer/issues/4263");
711 dbg!(&backup_text);
712 dbg!(&backup_changes);
713 std::panic::resume_unwind(e);
714 }
715 }
716 } 701 }
717 None => { 702 None => {
718 *old_text = change.text; 703 *old_text = change.text;