Skip to content

feat: dedup text edits #4840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading