Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command: eglot-execute-server-command #846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,24 @@ COMMAND is a symbol naming the command."
(jsonrpc-request server :workspace/executeCommand
`(:command ,(format "%s" command) :arguments ,arguments)))

(defun eglot-execute-server-command (command)
"Ask current server to execute COMMAND
(Server announces the available commands in its _initialize_ reply.)"
;; This defun simply calls cl-defmethod `eglot-execute-command', because
;; that cannot be interactive.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really? it can't? What a pity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, (info "(elisp) Generic Functions") says

     Functions defined using ‘cl-defmethod’ cannot be made interactive,
     i.e. commands (*note Defining Commands::), by adding the
     ‘interactive’ form to them.  If you need a polymorphic command, we
     recommend defining a normal command that calls a polymorphic
     function defined via ‘cl-defgeneric’ and ‘cl-defmethod’.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢 maybe @monnier can explain this. I can't see a technical reason why Emacs wouldn't allow this, but surely there must be one.

(interactive
(list (let ((commands (append (eglot--server-capable :executeCommandProvider
:commands)
nil)))
(if (not commands)
(eglot--error "Server provides no custom commands.")
(completing-read "Select command: " commands nil t)))))
;; Don't check if server knows COMMAND if it was given
;; non-interactively. If the server doesn't know it, the user is
;; going to receive a jsonrpc error message.
(when (< 0 (length command))
(eglot-execute-command (eglot--current-server-or-lose) command nil)))

(cl-defmethod eglot-handle-notification
(_server (_method (eql window/showMessage)) &key type message)
"Handle notification window/showMessage."
Expand Down