on master help sign in
diff full-doc LSP edits (#4041)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

commit8c2cc4301742d9d759a8c2964ade0719d4b15645 authorKirawi <67773714+kirawi@users.noreply.github.com> dateSun 2 Oct 2022, 15:23 (4 years ago) parent6caa7a7
1 file changed+14
helix-lsp/src/lib.rs+14
helix-lsp/src/lib.rs+14
@@ -204,6 +204,20 @@ pub mod util {
204204 // in reverse order.
205205 edits.sort_unstable_by_key(|edit| edit.range.start);
206206
207+ // Generate a diff if the edit is a full document replacement.
208+ #[allow(clippy::collapsible_if)]
209+ if edits.len() == 1 {
210+ let is_document_replacement = edits.first().and_then(|edit| {
211+ let start = lsp_pos_to_pos(doc, edit.range.start, offset_encoding)?;
212+ let end = lsp_pos_to_pos(doc, edit.range.end, offset_encoding)?;
213+ Some(start..end)
214+ }) == Some(0..doc.len_chars());
215+ if is_document_replacement {
216+ let new_text = Rope::from(edits.pop().unwrap().new_text);
217+ return helix_core::diff::compare_ropes(doc, &new_text);
218+ }
219+ }
220+
207221 Transaction::change(
208222 doc,
209223 edits.into_iter().map(|edit| {