diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 0a0e616c9..7e7f05b6d 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -667,6 +667,10 @@ fn apply_document_changes( | |||
667 | mut line_index: Cow<'_, LineIndex>, | 667 | mut line_index: Cow<'_, LineIndex>, |
668 | content_changes: Vec<TextDocumentContentChangeEvent>, | 668 | content_changes: Vec<TextDocumentContentChangeEvent>, |
669 | ) { | 669 | ) { |
670 | // Remove when https://github.com/rust-analyzer/rust-analyzer/issues/4263 is fixed. | ||
671 | let backup_text = old_text.clone(); | ||
672 | let backup_changes = content_changes.clone(); | ||
673 | |||
670 | // The changes we got must be applied sequentially, but can cross lines so we | 674 | // The changes we got must be applied sequentially, but can cross lines so we |
671 | // have to keep our line index updated. | 675 | // have to keep our line index updated. |
672 | // Some clients (e.g. Code) sort the ranges in reverse. As an optimization, we | 676 | // Some clients (e.g. Code) sort the ranges in reverse. As an optimization, we |
@@ -694,7 +698,19 @@ fn apply_document_changes( | |||
694 | } | 698 | } |
695 | index_valid = IndexValid::UpToLine(range.start.line); | 699 | index_valid = IndexValid::UpToLine(range.start.line); |
696 | let range = range.conv_with(&line_index); | 700 | let range = range.conv_with(&line_index); |
697 | old_text.replace_range(Range::<usize>::from(range), &change.text); | 701 | let mut text = old_text.to_owned(); |
702 | match std::panic::catch_unwind(move || { | ||
703 | text.replace_range(Range::<usize>::from(range), &change.text); | ||
704 | text | ||
705 | }) { | ||
706 | Ok(t) => *old_text = t, | ||
707 | Err(e) => { | ||
708 | eprintln!("Bug in incremental text synchronization. Please report the following output on https://github.com/rust-analyzer/rust-analyzer/issues/4263"); | ||
709 | dbg!(&backup_text); | ||
710 | dbg!(&backup_changes); | ||
711 | std::panic::resume_unwind(e); | ||
712 | } | ||
713 | } | ||
698 | } | 714 | } |
699 | None => { | 715 | None => { |
700 | *old_text = change.text; | 716 | *old_text = change.text; |