unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Danny Freeman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stephen Leake <stephen_leake@stephe-leake.org>
Cc: 59149@debbugs.gnu.org
Subject: bug#59149: Feature Request: Report progress of long requests in Eglot
Date: Wed, 23 Nov 2022 09:12:12 -0500	[thread overview]
Message-ID: <87tu2pohub.fsf@dfreeman.email> (raw)
In-Reply-To: <86fseckwvb.fsf@stephe-leake.org>

[-- Attachment #1: Type: text/plain, Size: 5961 bytes --]


Stephen Leake <stephen_leake@stephe-leake.org> writes:

> Note that this is checking the _server_ capabilities; since LSP does not
> define "projess" as a capability, no server will ever advertise that
> it is supported.
>
> So we can't use eglot-ignores-server-capabilities; we could maybe
> introduce eglot-ignored-client-capabilities.
>
> But we already have a mechanism for that; eglot-stay-out-of.
>
> So a user can do:
>
> (add-to-list 'eglot-stay-out-of 'progress)
>
> And in eglot-handle-notification ($/progress) we check for that:
>
> (unless (eglot--stay-out-of-p 'progress)

Yeah, I think this will be the way to go as well.


> There's probably a way to fold that check into the cl-defmethod
> dispatching parameters; I did not look into that.

If there is I do not know how to do it either. I think a boolean check
in the body of the function is fine (and probably more clear).

> I just ran into the progress reporter in eglot--apply-text-edits; I'd
> like to turn that off, but leave other progress-reporters on.
> 
> So we need something more fine-grained:
> 
> (setq eglot-progress-reporter-disable '(apply-text-edits))

I believe that is a different progress reporter, unrelated to the one I
would like to introduce. It is not a progress report that come from the
lsp server, so I don't think it would be good to conflate them.

If the user wants to ignore specific progress indicators from the lsp
servers then they could implement an empty version of
eglot-handle-notification that matches their progress token.

```
(cl-defmethod eglot-handle-notification
  (_server (_method (eql $/progress)) &key (token (eql "THE PROGRESS TOKEN")) _value))
```

That would be more targeted. I also suspect it would be a pretty rare
occurrence. I personally think the best way to decide on adding more
configuration variables to eglot is to release this into the wild and
see what kind of feedback we receive.


Responding to João from a couple of threads ago:

> Thanks Danny, this doesn't look bad at all, though I have yet to
> understand how it works.  I can half-see why progress status should be a
> server property, but it would be better if you provided an automated
> test, or maybe just a step-by-step sequence diagram (which can be in
> plain text and language) that clarifies this.  An animated gif that
> might also work.

I think I can explain it with a sample of my server logs:

The first thing that happens is the lsp server sends a progress BEGIN
message, which indicates to the client that it is starting some long
running process.

```
[server-notification] Wed Nov 23 08:55:22 2022:
(:jsonrpc "2.0" :method "$/progress" :params
          (:token "clojure-lsp" :value
                  (:kind "begin" :title "clojure-lsp" :percentage 0)))
```

Following that is a series of REPORT type progress messages. These
indicate to the client that the work is ongoing. They might have a
`percentage` key somewhere between 0 and 100 to show how the work is
progressing.

```
[server-notification] Wed Nov 23 08:55:22 2022:
(:jsonrpc "2.0" :method "$/progress" :params
          (:token "clojure-lsp" :value
                  (:kind "report" :title "Finding kondo config" :percentage 5)))
[server-notification] Wed Nov 23 08:55:22 2022:
(:jsonrpc "2.0" :method "$/progress" :params
          (:token "clojure-lsp" :value
                  (:kind "report" :title "Finding cache" :percentage 10)))
[server-notification] Wed Nov 23 08:55:22 2022:
(:jsonrpc "2.0" :method "$/progress" :params
          (:token "clojure-lsp" :value
                  (:kind "report" :title "Copying kondo configs" :percentage 15)))
[server-notification] Wed Nov 23 08:55:22 2022:
(:jsonrpc "2.0" :method "$/progress" :params
          (:token "clojure-lsp" :value
                  (:kind "report" :title "Resolving config paths" :percentage 15)))
[server-notification] Wed Nov 23 08:55:22 2022:
(:jsonrpc "2.0" :method "$/progress" :params
          (:token "clojure-lsp" :value
                  (:kind "report" :title "Analyzing project files" :percentage 20)))

... this goes on for a while

[server-notification] Wed Nov 23 08:55:22 2022:
(:jsonrpc "2.0" :method "$/progress" :params
          (:token "clojure-lsp" :value
                  (:kind "report" :title "Analyzing project files" :percentage 99)))
```

Finally, the server sends an END type progress message, indicating that
the work is complete, and the client can stop showing the progress
message.

```
[server-notification] Wed Nov 23 08:55:22 2022:
(:jsonrpc "2.0" :method "$/progress" :params
          (:token "clojure-lsp" :value
                  (:kind "end" :title "Project analyzed" :percentage 100)))
```

The result of this patch is a series of messages that display in the
minibuffer:

```
[eglot:website] clojure-lsp:  
[eglot:website] clojure-lsp: 5% Finding kondo config
[eglot:website] clojure-lsp: 10% Finding cache
[eglot:website] clojure-lsp: 15% Copying kondo configs
[eglot:website] clojure-lsp: 20% Analyzing project files
[eglot:website] clojure-lsp: 26% Analyzing project files
[eglot:website] clojure-lsp: 33% Analyzing project files
[eglot:website] clojure-lsp: 39% Analyzing project files
[eglot:website] clojure-lsp: 46% Analyzing project files
[eglot:website] clojure-lsp: 52% Analyzing project files
[eglot:website] clojure-lsp: 59% Analyzing project files
[eglot:website] clojure-lsp: 66% Analyzing project files
[eglot:website] clojure-lsp: 72% Analyzing project files
[eglot:website] clojure-lsp: 79% Analyzing project files
[eglot:website] clojure-lsp: 85% Analyzing project files
[eglot:website] clojure-lsp: 92% Analyzing project files
[eglot:website] clojure-lsp: 99% Analyzing project files
[eglot:website] clojure-lsp: done
```

Does that help?

Attached is an updated patch that uses `eglot-stay-out-of`


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: progress reporter patch --]
[-- Type: text/x-patch, Size: 4114 bytes --]

From 54bc6b70c8a6da8853db1bcc45ca51796b98b6c2 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 | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index e057b12e0e..3dc71b148c 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -821,6 +821,9 @@ eglot-lsp-server
    (project
     :documentation "Project associated with server."
     :accessor eglot--project)
+   (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."
@@ -2037,6 +2040,43 @@ 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."
+  (unless (eglot--stay-out-of-p 'progress)
+    (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


[-- Attachment #3: Type: text/plain, Size: 19 bytes --]


-- 
Danny Freeman

  reply	other threads:[~2022-11-23 14:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 14:13 bug#59149: Feature Request: Report progress of long requests in Eglot Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-10 15:50 ` João Távora
2022-11-11 13:07   ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19  9:42 ` Stephen Leake
2022-11-19 18:03   ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-21 18:04     ` Stephen Leake
2022-11-23 14:12       ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-11-23 18:01         ` Stephen Leake
2022-11-23 19:36           ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-23 19:56             ` João Távora
2022-11-24 11:06               ` bug#59149: [SPAM UNSURE] " Stephen Leake
2022-11-24 14:16                 ` João Távora
2022-11-24 21:25                   ` Stephen Leake
2022-11-25 16:11                     ` João Távora
2022-11-25 16:15                     ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-25 16:31                       ` Eli Zaretskii
2022-11-25 16:41                         ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-25 16:44                           ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-26  1:03                           ` João Távora
2022-11-26 18:37                             ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-26 19:46                             ` Stefan Kangas
2022-12-01 13:29                               ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-03 13:23                                 ` João Távora
2022-12-09 13:06                                   ` João Távora
2022-12-09 13:38                                     ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-22 18:45     ` Stephen Leake

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tu2pohub.fsf@dfreeman.email \
    --to=bug-gnu-emacs@gnu.org \
    --cc=59149@debbugs.gnu.org \
    --cc=danny@dfreeman.email \
    --cc=stephen_leake@stephe-leake.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).