Function: eglot--apply-workspace-edit
eglot--apply-workspace-edit is a byte-compiled function defined in
eglot.el.gz.
Signature
(eglot--apply-workspace-edit WEDIT ORIGIN)
Documentation
Apply (or offer to apply) the workspace edit WEDIT.
ORIGIN is a symbol designating the command that originated this edit proposed by the server.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(defun eglot--apply-workspace-edit (wedit origin)
"Apply (or offer to apply) the workspace edit WEDIT.
ORIGIN is a symbol designating the command that originated this
edit proposed by the server."
(eglot--dbind ((WorkspaceEdit) changes documentChanges) wedit
(let ((prepared
(mapcar (eglot--lambda ((TextDocumentEdit) textDocument edits)
(eglot--dbind ((VersionedTextDocumentIdentifier) uri version)
textDocument
(list (eglot-uri-to-path uri) edits version)))
documentChanges)))
(unless (and changes documentChanges)
;; We don't want double edits, and some servers send both
;; changes and documentChanges. This unless ensures that we
;; prefer documentChanges over changes.
(cl-loop for (uri edits) on changes by #'cddr
do (push (list (eglot-uri-to-path uri) edits) prepared)))
(cl-flet ((notevery-visited-p ()
(cl-notevery #'find-buffer-visiting
(mapcar #'car prepared)))
(accept-p ()
(y-or-n-p
(format "[eglot] Server wants to edit:\n%sProceed? "
(cl-loop
for (f eds _) in prepared
concat (format
" %s (%d change%s)\n"
f (length eds)
(if (> (length eds) 1) "s" ""))))))
(apply ()
(cl-loop for edit in prepared
for (path edits version) = edit
do (with-current-buffer (find-file-noselect path)
(eglot--apply-text-edits edits version))
finally (eldoc) (eglot--message "Edit successful!"))))
(let ((decision (eglot--confirm-server-edits origin prepared)))
(cond
((or (eq decision 'diff)
(and (eq decision 'maybe-diff) (notevery-visited-p)))
(eglot--propose-changes-as-diff prepared))
((or (memq decision '(t summary))
(and (eq decision 'maybe-summary) (notevery-visited-p)))
(when (accept-p) (apply)))
(t
(apply))))))))