From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Danny Freeman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59149: Feature Request: Report progress of long requests in Eglot Date: Wed, 09 Nov 2022 09:13:29 -0500 Message-ID: <87educqkar.fsf@dfreeman.email> Reply-To: Danny Freeman Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13227"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= To: 59149@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 09 15:24:21 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1osm04-0003Be-Ry for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Nov 2022 15:24:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oslzn-0002A1-Vl; Wed, 09 Nov 2022 09:24:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oslzm-00029H-76 for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2022 09:24:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oslzl-0002OK-Uy for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2022 09:24:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oslzl-0004Mh-Q2 for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2022 09:24:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Danny Freeman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Nov 2022 14:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59149 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166800379816679 (code B ref -1); Wed, 09 Nov 2022 14:24:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Nov 2022 14:23:18 +0000 Original-Received: from localhost ([127.0.0.1]:39377 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oslz3-0004Kw-Vp for submit@debbugs.gnu.org; Wed, 09 Nov 2022 09:23:18 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:57154) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oslz1-0004Ko-WF for submit@debbugs.gnu.org; Wed, 09 Nov 2022 09:23:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oslz1-00022u-OT for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2022 09:23:15 -0500 Original-Received: from out0.migadu.com ([94.23.1.103]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oslyw-0002B9-48 for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2022 09:23:14 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1668003783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=JLDlbWH5ZDpR2rl3usegdVqQqcFnrEEhT22P11nX7ig=; b=F31ZdK89zs5M4E6pewa1mZB/QFPUyQyQw1l5RFJXuac5QXr+hwlGpd+TnoeIJ26DOZ6JDb qE5mN15uB0YuPXkZp9tJy0+N7/LJcfI+f6mfJ3IwC1vRZz05qj57QGyDsoEBLh5ShtfS4n 9tPMrEV5Db8+PUsR1Sy6/YeMLprpIgg= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=94.23.1.103; envelope-from=danny@dfreeman.email; helo=out0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:247416 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Eglot-Display-progress-notifications-in-minibuffer-a.patch Content-Description: progress notification patch >From b53753f611045bb44ef4d1d30d6f426be889f277 Mon Sep 17 00:00:00 2001 From: dannyfreeman 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 --=-=-= Content-Type: text/plain Thank you, -- Danny Freeman --=-=-=--