From: "João Távora" <joaotavora@gmail.com>
To: Felician Nemeth <felician.nemeth@gmail.com>
Cc: 63372@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>
Subject: bug#63372: [PATCH] Add variable: eglot-apply-text-edits-function
Date: Thu, 11 May 2023 20:54:32 +0100 [thread overview]
Message-ID: <CALDnm52mNTjPksGCKqnNsV0JoLWxAUXeGM2amN4S1O0JbVx2Ng@mail.gmail.com> (raw)
In-Reply-To: <877ctg9dzj.fsf@betli.tmit.bme.hu>
[-- Attachment #1: Type: text/plain, Size: 512 bytes --]
After having another look at eglot-x.el i don't
think eglot--apply-text-edits (plural) is the right
place to put the generic. You'd just repeat a lot
of code of the original, with no clear way to reuse it.
Maybe you want something more akin to the attached patch,
which introduces eglot-apply-text-edit (singular). In your
override for this function you can check conditions to either
proceed with the non-standard edit or delegate to the default
implementation with (cl-call-next-method).
João
[-- Attachment #2: 0001-Eglot-allow-extensions-to-application-of-LSP-edits-b.patch --]
[-- Type: application/octet-stream, Size: 3543 bytes --]
From d51a12156b6278a1ff1f4dbf0d8991d79749ae00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= <joaotavora@gmail.com>
Date: Thu, 11 May 2023 20:50:20 +0100
Subject: [PATCH] Eglot: allow extensions to application of LSP edits
(bug#63372)
* lisp/progmodes/eglot.el (eglot-apply-text-edit): New function.
(eglot--apply-text-edits): Rework.
---
lisp/progmodes/eglot.el | 47 ++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 22 deletions(-)
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index dc8d4674425..c045f71fe9b 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -843,6 +843,20 @@ eglot-workspace-folders
:name (abbreviate-file-name dir)))
`(,(project-root project) ,@(project-external-roots project))))))
+(cl-defgeneric eglot-apply-text-edit (_server edit)
+ "Apply EDIT supplied by SERVER in current buffer."
+ (eglot--dbind ((TextEdit) range newText) edit
+ (cl-destructuring-bind (beg . end) (eglot--range-region range 'markers)
+ (let ((source (current-buffer)))
+ (with-temp-buffer
+ (insert newText)
+ (let ((temp (current-buffer)))
+ (with-current-buffer source
+ (save-excursion
+ (save-restriction
+ (narrow-to-region beg end)
+ (replace-buffer-contents temp))))))))))
+
(defclass eglot-lsp-server (jsonrpc-process-connection)
((project-nickname
:documentation "Short nickname for the associated project."
@@ -3327,29 +3341,18 @@ eglot--apply-text-edits
(jsonrpc-error "Edits on `%s' require version %d, you have %d"
(current-buffer) version eglot--versioned-identifier))
(atomic-change-group
- (let* ((change-group (prepare-change-group))
- (howmany (length edits))
- (reporter (make-progress-reporter
+ (cl-loop
+ with change-group = (prepare-change-group)
+ with reporter = (make-progress-reporter
(format "[eglot] applying %s edits to `%s'..."
- howmany (current-buffer))
- 0 howmany))
- (done 0))
- (mapc (pcase-lambda (`(,newText ,beg . ,end))
- (let ((source (current-buffer)))
- (with-temp-buffer
- (insert newText)
- (let ((temp (current-buffer)))
- (with-current-buffer source
- (save-excursion
- (save-restriction
- (narrow-to-region beg end)
- (replace-buffer-contents temp)))
- (eglot--reporter-update reporter (cl-incf done)))))))
- (mapcar (eglot--lambda ((TextEdit) range newText)
- (cons newText (eglot--range-region range 'markers)))
- (reverse edits)))
- (undo-amalgamate-change-group change-group)
- (progress-reporter-done reporter))))
+ (length edits) (current-buffer))
+ 0 (length edits))
+ for e across (reverse edits) for done from 1
+ do (eglot-apply-text-edit (eglot--current-server-or-lose) e)
+ (eglot--reporter-update reporter done)
+ finally
+ (undo-amalgamate-change-group change-group)
+ (progress-reporter-done reporter))))
(defun eglot--apply-workspace-edit (wedit &optional confirm)
"Apply the workspace edit WEDIT. If CONFIRM, ask user first."
--
2.36.1.windows.1
next prev parent reply other threads:[~2023-05-11 19:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-05 11:56 [GNU ELPA] eglot-x.el: Protocol extensions for Eglot Felician Nemeth
2023-05-05 13:18 ` Ruijie Yu via Emacs development discussions.
2023-05-06 13:14 ` Felician Nemeth
2023-05-05 13:26 ` Eli Zaretskii
2023-05-05 14:20 ` João Távora
2023-05-05 14:39 ` Eli Zaretskii
2023-05-05 16:41 ` João Távora
2023-05-06 13:12 ` Felician Nemeth
2023-05-06 13:27 ` Eli Zaretskii
2023-05-06 15:17 ` Felician Nemeth
2023-05-06 15:27 ` Eli Zaretskii
2023-05-08 14:28 ` bug#63372: [PATCH] Add variable: eglot-apply-text-edits-function Felician Nemeth
2023-05-08 14:54 ` Felician Nemeth
2023-05-08 16:33 ` João Távora
2023-05-10 19:35 ` Felician Nemeth
2023-05-11 19:54 ` João Távora [this message]
2023-05-15 20:03 ` Felician Nemeth
2023-05-06 13:51 ` [GNU ELPA] eglot-x.el: Protocol extensions for Eglot João Távora
2023-05-06 15:28 ` Felician Nemeth
2023-05-05 16:38 ` Philip Kaludercic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALDnm52mNTjPksGCKqnNsV0JoLWxAUXeGM2amN4S1O0JbVx2Ng@mail.gmail.com \
--to=joaotavora@gmail.com \
--cc=63372@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=felician.nemeth@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.