Subject: Re: bug#71642: 30.0.50; eglot-execute doesn't support ExecuteCommandParams

From: Troy Brown <[email-masked]>
Date: Wed, 19 Jun 2024 23:55:10 -0400

On Wed, Jun 19, 2024 at 6:26 PM João Távora <[email-masked]> wrote:
>
> Troy, you seem to be on to something.  It would seem Command shouldn't
> be there in the dcase matcher in eglot-execute at all.  Instead
> ExecuteCommandParams should be there.
>

I suspected that might be the case (that Command was really supposed
to be ExecuteCommandParams), but I hadn't exhaustively looked at
everything, however you have now confirmed that suspicion.

>
> I may just have been thrown off  by the confusing naming (naively
> thinking that executeCommand executes Commands, but it doesnt).
>

Yes, that makes sense, I was confused for a bit as well until I had
investigated why it had the "title" parameter, looked at the LSP
specification and realized that it was meant for something else.

> The reason no one has complained is probably that there aren't
> many users invoking custom commands, and if there are, they could
> be just using `jsonrpc-request` directly or using the deprecated
> interface.

Yes, that makes sense, I'd imagine people who are using custom
commands are using the older eglot-execute-command interface since
it's still functional.  I had looked at it and saw that it was now
deprecated so I attempted to use the new interface.

>  If so, patches welcome, as you
> seem to have grasped how this code is supposed to work.
>

I've attached a patch which I believe addresses the issue.  I did have
to reorder the interfaces to put CodeAction before
ExecuteCommandParams as both contain "command" parameters.  Since
eglot-strict-mode doesn't normally contain disallow-non-standard-keys,
it causes eglot--dcase to match ExecuteCommandParams for a CodeAction
interface if the optional "command" parameter is present.  Reordering
the interfaces allows them to match correctly since CodeAction
contains a required "title" parameter which is not present in the
ExecuteCommandParams interface.
From f7c20afc4649aeeda0b36118f50b59365d1c96e4 Mon Sep 17 00:00:00 2001
From: Troy Brown <[email-masked]>
Date: Wed, 19 Jun 2024 20:14:07 -0400
Subject: [PATCH] Eglot: Fix command execution (bug#71642)

* lisp/progmodes/eglot.el (eglot--lsp-interface-alist): Add
ExecuteCommandParams interface.
(eglot--execute): Change Command interface to ExecuteCommandParams
interface.

Copyright-paperwork-exempt: yes
---
 lisp/progmodes/eglot.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 03da5c7b22a..cf91eae5694 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -624,6 +624,7 @@ eglot--uri-path-allowed-chars
                              :command :data :tags))
       (Diagnostic (:range :message) (:severity :code :source :relatedInformation :codeDescription :tags))
       (DocumentHighlight (:range) (:kind))
+      (ExecuteCommandParams ((:command . string)) (:arguments))
       (FileSystemWatcher (:globPattern) (:kind))
       (Hover (:contents) (:range))
       (InitializeResult (:capabilities) (:serverInfo))
@@ -884,17 +885,18 @@ eglot-execute-command
 
 (cl-defgeneric eglot-execute (server action)
   "Ask SERVER to execute ACTION.
-ACTION is an LSP object of either `CodeAction' or `Command' type."
+ACTION is an LSP object of either `CodeAction' or `ExecuteCommandParams' type."
   (:method
    (server action) "Default implementation."
    (eglot--dcase action
-     (((Command)) (eglot--request server :workspace/executeCommand action))
      (((CodeAction) edit command data)
       (if (and (null edit) (null command) data
                (eglot-server-capable :codeActionProvider :resolveProvider))
           (eglot-execute server (eglot--request server :codeAction/resolve action))
         (when edit (eglot--apply-workspace-edit edit this-command))
-        (when command (eglot--request server :workspace/executeCommand command)))))))
+        (when command (eglot--request server :workspace/executeCommand command))))
+     (((ExecuteCommandParams))
+      (eglot--request server :workspace/executeCommand action)))))
 
 (cl-defgeneric eglot-initialization-options (server)
   "JSON object to send under `initializationOptions'."
-- 
2.37.1