[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot df5e72e 09/12: Close #23: Report progress when ap

From: João Távora
Subject: [elpa] externals/eglot df5e72e 09/12: Close #23: Report progress when applying edits
Date: Fri, 22 Jun 2018 11:52:16 -0400 (EDT)

branch: externals/eglot
commit df5e72ee2589308abee70231cf9ee2a2cee93f22
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Close #23: Report progress when applying edits
    Use make-progress-reporter in eglot--apply-text-edits
    As suggested by mkcms <address@hidden>, but do it in
    eglot--apply-text-edits, where it benefits all its users.
    * eglot.el (eglot--apply-text-edits): Use a progress reporter.
    Fix marker point recovery.
 eglot.el | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/eglot.el b/eglot.el
index 489e365..9e686ee 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1584,18 +1584,27 @@ If SKIP-SIGNATURE, don't try to send 
     (eglot--error "Edits on `%s' require version %d, you have %d"
                   (current-buffer) version eglot--versioned-identifier))
-    (mapc (pcase-lambda (`(,newText ,beg . ,end))
-            (save-restriction
-              (narrow-to-region beg end)
+    (let* ((howmany (length edits))
+           (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)))
                   (insert newText)
                   (let ((temp (current-buffer)))
-                    (with-current-buffer source (replace-buffer-contents 
-          (mapcar (eglot--lambda (&key range newText)
-                    (cons newText (eglot--range-region range 'markers)))
-                  edits)))
-  (eglot--message "%s: Performed %s edits" (current-buffer) (length edits)))
+                    (with-current-buffer source
+                      (save-excursion
+                        (save-restriction
+                          (narrow-to-region beg end)
+                          (replace-buffer-contents temp)))
+                      (progress-reporter-update reporter (cl-incf done)))))))
+            (mapcar (eglot--lambda (&key range newText)
+                      (cons newText (eglot--range-region range 'markers)))
+                    edits))
+      (progress-reporter-done reporter))))
 (defun eglot--apply-workspace-edit (wedit &optional confirm)
   "Apply the workspace edit WEDIT.  If CONFIRM, ask user first."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]