emacs-bug-tracker
[Top][All Lists]
Advanced

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

bug#59149: closed (Feature Request: Report progress of long requests in


From: GNU bug Tracking System
Subject: bug#59149: closed (Feature Request: Report progress of long requests in Eglot)
Date: Fri, 09 Dec 2022 13:08:01 +0000

Your message dated Fri, 9 Dec 2022 13:06:47 +0000
with message-id 
<CALDnm53vP0rk6QMMw-qkEWCt_ZR8=0ppNK6_q6+PYRX7fMVj4w@mail.gmail.com>
and subject line Re: bug#59149: [SPAM UNSURE] Re: bug#59149: Feature Request: 
Report progress of long requests in Eglot
has caused the debbugs.gnu.org bug report #59149,
regarding Feature Request: Report progress of long requests in Eglot
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
59149: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59149
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: Feature Request: Report progress of long requests in Eglot Date: Wed, 09 Nov 2022 09:13:29 -0500
Something I think would be nice to have in eglot is some kind of
progress indicator for long running requests. Attached is my attempt at
implementing these. The patch contains links to relevant LSP specs in
the commit message.

Here is a link to an old github discussion about progress notifications:
https://github.com/joaotavora/eglot/discussions/835 

It uses the built in progress-reporter to display progress in the
echo area. Something that may be missing is a way for the user to
enable/disable this. Not sure what the right facilities are for that.
The eglot-stay-out-of pattern maybe? I didn't include that because I'm
not sure what to "stay out of". Maybe the symbol `progress-reporter'?
Happy to add something like that.

>From b53753f611045bb44ef4d1d30d6f426be889f277 Mon Sep 17 00:00:00 2001
From: dannyfreeman <danny@dfreeman.email>
Date: Wed, 9 Nov 2022 08:46:45 -0500
Subject: [PATCH] Eglot: Display progress notifications in minibuffer as they
 arrive

The LSP spec describes methods for reporting progress on long running
jobs to the client:

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#progress
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workDoneProgress

This change reports those notifications in the minibuffer as they come
in. It shows a percent indicator (if the server provides theme), or a
spinner. This change should open the door for writing a "cancel long
running request" command, which are identified by these progress
notifications. See
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_workDoneProgress_cancel
---
 lisp/progmodes/eglot.el | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index ecfede8fa6..b85d9fd445 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -820,6 +820,9 @@ eglot-lsp-server
    (spinner
     :documentation "List (ID DOING-WHAT DONE-P) representing server progress."
     :initform `(nil nil t) :accessor eglot--spinner)
+   (progress-reporter-alist
+    :documentation "Alist of (PROGRESS-TOKEN . PROGRESS-REPORTER)."
+    :accessor eglot--progress-reporter-alist)
    (inhibit-autoreconnect
     :initform t
     :documentation "Generalized boolean inhibiting auto-reconnection if true."
@@ -2035,6 +2038,42 @@ eglot-handle-notification
   (_server (_method (eql telemetry/event)) &rest _any)
   "Handle notification telemetry/event.") ;; noop, use events buffer
 
+(defun eglot--progress-report-message (title message)
+  "Format a $/progress report message, given a TITLE and/or MESSAGE string."
+  (cond
+   ((and title message) (format "%s %s" title message))
+   (title title)
+   (message message)))
+
+(defun eglot--progress-reporter (server token)
+  "Get a prgress-reporter identified by the progress TOKEN from the SERVER ."
+  (cdr (assoc token (eglot--progress-reporter-alist server))))
+
+(defun eglot--progress-reporter-delete (server token)
+  "Delete progress-reporters identified by the progress TOKEN from the SERVER."
+  (setf (eglot--progress-reporter-alist server)
+        (assoc-delete-all token (eglot--progress-reporter-alist server))))
+
+(cl-defmethod eglot-handle-notification
+  (server (_method (eql $/progress)) &key token value)
+  "Handle a $/progress notification identified by TOKEN from the SERVER."
+  (cl-destructuring-bind (&key kind title percentage message) value
+    (pcase kind
+      ("begin" (let* ((prefix (format (concat "[eglot] %s %s:" (when 
percentage " "))
+                                      (eglot-project-nickname server) token))
+                      (pr (if percentage
+                              (make-progress-reporter prefix 0 100 percentage 
1 0)
+                            (make-progress-reporter prefix nil nil nil 1 0))))
+                 (eglot--progress-reporter-delete server token)
+                 (setf (eglot--progress-reporter-alist server)
+                       (cons (cons token pr) (eglot--progress-reporter-alist 
server)))
+                 (progress-reporter-update pr percentage 
(eglot--progress-report-message title message))))
+      ("report" (when-let ((pr (eglot--progress-reporter server token)))
+                  (progress-reporter-update pr percentage 
(eglot--progress-report-message title message))))
+      ("end" (when-let ((pr (eglot--progress-reporter server token)))
+               (progress-reporter-done pr)
+               (eglot--progress-reporter-delete server token))))))
+
 (cl-defmethod eglot-handle-notification
   (_server (_method (eql textDocument/publishDiagnostics)) &key uri diagnostics
            &allow-other-keys) ; FIXME: doesn't respect `eglot-strict-mode'
-- 
2.38.1

Thank you,
-- 
Danny Freeman

--- End Message ---
--- Begin Message --- Subject: Re: bug#59149: [SPAM UNSURE] Re: bug#59149: Feature Request: Report progress of long requests in Eglot Date: Fri, 9 Dec 2022 13:06:47 +0000
I just pushed this to the emacs-29 branch, as it's a feature within 
a new feature for that branch already.

Danny, I also tweaked the implementation slightly to use a hash table
instead of an alist.  I didn't actually test this, as I have no server handy
that supplies these $/progress notifications, but it should be functionally
equivalent.  let me know if it's not, it's easy to tweak.

Also, I added a missing entry in the eglot.texi manual.

João

On Sat, Dec 3, 2022 at 1:23 PM João Távora <joaotavora@gmail.com> wrote:
Hi Danny,

Thanks, no it hasn't.  But I have a lot of little things to do and 
limited free time. Your patch should be next in the queue,
though.

João


--
João Távora

--- End Message ---

reply via email to

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