From dee1f61c4375b764762ad5a4b91b4b84ff4175a0 Mon Sep 17 00:00:00 2001 From: CHEN Xian-an Date: Sat, 19 Jul 2025 17:39:57 +0800 Subject: [PATCH] feat: dedup text edits --- lsp-mode.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lsp-mode.el b/lsp-mode.el index 5b21e1294f..036db25cb8 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -4545,6 +4545,12 @@ interface TextDocumentEdit { (and (= left-line right-line) (= left-character right-character))) +(lsp-defun lsp--text-edit-equal ((&TextEdit :range (&Range :start left-start :end left-end)) + (&TextEdit :range (&Range :start right-start :end right-end))) + "Return whether LEFT and RIGHT text edits are equal." + (and (lsp--position-equal left-start right-start) + (lsp--position-equal left-end right-end))) + (lsp-defun lsp--text-edit-sort-predicate ((&TextEdit :range (&Range :start left-start :end left-end)) (&TextEdit :range (&Range :start right-start :end right-end))) (if (lsp--position-equal left-start right-start) @@ -4654,6 +4660,7 @@ LSP server result." (defun lsp--apply-text-edits (edits &optional operation) "Apply the EDITS described in the TextEdit[] object. OPERATION is symbol representing the source of this text edit." + (setq edits (seq-uniq edits #'lsp--text-edit-equal)) (unless (seq-empty-p edits) (atomic-change-group (run-hooks 'lsp-before-apply-edits-hook)