diff options
author | Kirawi | 2022-10-02 19:23:23 +0000 |
---|---|---|
committer | GitHub | 2022-10-02 19:23:23 +0000 |
commit | 8c2cc4301742d9d759a8c2964ade0719d4b15645 (patch) | |
tree | 5299c3fb32b1f10c289742a3d1dee477bde42533 | |
parent | 6caa7a7f566e67c50537014b3e97fa8e65a8b7b3 (diff) |
diff full-doc LSP edits (#4041)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
-rw-r--r-- | helix-lsp/src/lib.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index cb234357..0717fc04 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -204,6 +204,20 @@ pub mod util { // in reverse order. edits.sort_unstable_by_key(|edit| edit.range.start); + // Generate a diff if the edit is a full document replacement. + #[allow(clippy::collapsible_if)] + if edits.len() == 1 { + let is_document_replacement = edits.first().and_then(|edit| { + let start = lsp_pos_to_pos(doc, edit.range.start, offset_encoding)?; + let end = lsp_pos_to_pos(doc, edit.range.end, offset_encoding)?; + Some(start..end) + }) == Some(0..doc.len_chars()); + if is_document_replacement { + let new_text = Rope::from(edits.pop().unwrap().new_text); + return helix_core::diff::compare_ropes(doc, &new_text); + } + } + Transaction::change( doc, edits.into_iter().map(|edit| { |