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: [SPAM UNSURE] Re: bug#59149: Feature Request: Report progress of long requests in Eglot Date: Fri, 25 Nov 2022 11:15:33 -0500 Message-ID: <87r0xrxb0i.fsf@dfreeman.email> References: <87educqkar.fsf@dfreeman.email> <86cz9jmg9r.fsf@stephe-leake.org> <87k03qvmla.fsf@dfreeman.email> <86fseckwvb.fsf@stephe-leake.org> <87tu2pohub.fsf@dfreeman.email> <86ilj5k0sn.fsf@stephe-leake.org> <87wn7l316m.fsf@dfreeman.email> <86edtsk3xi.fsf@stephe-leake.org> <87o7swv3nx.fsf@gmail.com> <8635a8jb8e.fsf@stephe-leake.org> 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="33125"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59149@debbugs.gnu.org, joaotavora@gmail.com To: Stephen Leake Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 25 17:20:29 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 1oybRE-0008Nb-Mp for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 25 Nov 2022 17:20:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oybQv-0006F7-5Q; Fri, 25 Nov 2022 11:20:09 -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 1oybQs-0006ET-EL for bug-gnu-emacs@gnu.org; Fri, 25 Nov 2022 11:20:06 -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 1oybQs-0004er-3d for bug-gnu-emacs@gnu.org; Fri, 25 Nov 2022 11:20:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oybQn-0006SC-W9 for bug-gnu-emacs@gnu.org; Fri, 25 Nov 2022 11:20:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Danny Freeman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 25 Nov 2022 16:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59149 X-GNU-PR-Package: emacs X-Debbugs-Original-Cc: 59149@debbugs.gnu.org, bug-gnu-emacs@gnu.org, =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Received: via spool by submit@debbugs.gnu.org id=B.166939316724763 (code B ref -1); Fri, 25 Nov 2022 16:20:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Nov 2022 16:19:27 +0000 Original-Received: from localhost ([127.0.0.1]:37010 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oybQE-0006RK-GK for submit@debbugs.gnu.org; Fri, 25 Nov 2022 11:19:27 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:54120) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oybQC-0006RC-Oc for submit@debbugs.gnu.org; Fri, 25 Nov 2022 11:19:25 -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 1oybQB-000652-2F for bug-gnu-emacs@gnu.org; Fri, 25 Nov 2022 11:19:23 -0500 Original-Received: from out-51.mta0.migadu.com ([91.218.175.51]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oybQ8-0004ZC-9e for bug-gnu-emacs@gnu.org; Fri, 25 Nov 2022 11:19:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1669393154; 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: in-reply-to:in-reply-to:references:references; bh=uEXBL/qFIDwmhECJgbQImS8R21oGHcriyEyMg7PxzHg=; b=IEcxwGNheaTa096m5mmpwdbHeG8/Q9fM2pFtnCyeApWo0xCSSobOxHcMDI3OMiyl0DNqGB iqxAWdt65VPrc7qx36Hxgtdkak0N/CB4qiG08BVY9OISnQ7/UcaA26FIOHdwEvXehfllOS 6J+mjVffZdO+KfVbLDlCOSSsfibCerw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <8635a8jb8e.fsf@stephe-leake.org> X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=91.218.175.51; envelope-from=danny@dfreeman.email; helo=out-51.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=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:249016 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Stephen Leake writes: > Jo=C3=A3o T=C3=A1vora writes: > >> 1. Get rid of the :apply-edit progress reporter entirely. To be honest, >> I don't think it's doing much. We could just as well have a call to >> message there, or nothing at all. >> 2. Do my original "sketchy" suggestion, where :$progress is considered a >> built-in ignorable capability (and checked with eglot--server-capable >> in the new code that Danny is proposing). Stephen's eglot-connect >> trick is an acceptable technique. >> >> 3. Add a boolean user varible eglot-report-progress. I don't like to >> add user variables unless they represent things directly related to >> the fundamental LSP logic, and not its customization or evolution. >> Since this seems to be of those fundamental things, I think it's >> acceptable. >> >> The alternatives are: >> >> a: 1+2 >> b: 1+3 >> c: 2 >> d: 3 >> >> Stephen, you request to shoosh that particular apply-edits progress >> reporter is another separate request, we shouldn't let it block Danny's >> effort to support $progress messages.=20=20 >> So I think we should do either 'c' or 'd' for now, and we can always >> address your request later. > > Ok. Since that rules out b, I vote for d. I am more partial to option d as well. From a user's perspective it seems more straight forward than having to figure out the pseudo server capability. I've attached an updated patch --=20 Danny Freeman --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Eglot-Display-progress-notifications-in-minibuffer-a.patch Content-Description: eglot progress report patch >From 2787503eda061f934eebd23e7ee661d3f5ea547d 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 * lisp/progmodes/eglot.el (eglot-report-progress): New custom variable. (eglot-lsp-server): New slot for tracking active progress reporters. (eglot-handle-notification): New impl for $/progress server responses. (eglot--format-markup): replace tab with spaces. (eglot--TextDocumentItem): replace tab with spaces. 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 | 48 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index a0fb253e10..f01e6542af 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -386,6 +386,10 @@ eglot-menu-string "String displayed in mode line when Eglot is active." :type 'string) +(defcustom eglot-report-progress t + "If non-nil, show progress of long running server work in the minibuffer." + :type 'boolean) + (defvar eglot-withhold-process-id nil "If non-nil, Eglot will not send the Emacs process id to the language server. This can be useful when using docker to run a language server.") @@ -831,6 +835,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." @@ -1569,7 +1576,7 @@ eglot--format-markup (setq-local markdown-fontify-code-blocks-natively t) (insert string) (let ((inhibit-message t) - (message-log-max nil)) + (message-log-max nil)) (ignore-errors (delay-mode-hooks (funcall mode)))) (font-lock-ensure) (string-trim (buffer-string))))) @@ -2049,6 +2056,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." + (when eglot-report-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' @@ -2172,7 +2216,7 @@ eglot--TextDocumentItem (append (eglot--VersionedTextDocumentIdentifier) (list :languageId - (eglot--language-id (eglot--current-server-or-lose)) + (eglot--language-id (eglot--current-server-or-lose)) :text (eglot--widening (buffer-substring-no-properties (point-min) (point-max)))))) -- 2.38.1 --=-=-=--