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

Cancelling out of a code-actions dropdown signals non-user error. Fix that. #1056

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Inc0n
Copy link

@Inc0n Inc0n commented Sep 22, 2022

This is to address the issue found and commented in the PR #1054 (comment).

Issue description

Here is that issue. Steps:

At any point, where there are code actions available.
Invoke the diagnosis with mouse-1.
Then cancel it by clicking away the poped up menu (i.e. not selecting any of the code actions)
This would result in the following error (with backtrace enabled, some deeper down frames are ommited):

Debugger entered--Lisp error: (error "[eglot] nil didn't match any of (((Command) comman...")
  signal(error ("[eglot] nil didn't match any of (((Command) comman..."))
  error("[eglot] %s" "nil didn't match any of (((Command) command argume...")
  eglot--error("%S didn't match any of %S" nil (((Command) command arguments) ((CodeAction) edit command)))
  (cond ((condition-case nil (progn (eglot--check-object 'Command obj-once t (memq 'disallow-non-standard-keys eglot-strict-mode) t)) (error nil)) (let* ((--cl-rest-- obj-once) (command (car (cdr (plist-member --cl-rest-- ...)))) (arguments (car (cdr (plist-member --cl-rest-- ...))))) (eglot-execute-command server (intern command) arguments))) ((condition-case nil (progn (eglot--check-object 'CodeAction obj-once t (memq 'disallow-non-standard-keys eglot-strict-mode) t)) (error nil)) (let* ((--cl-rest-- obj-once) (edit (car (cdr (plist-member --cl-rest-- ...)))) (command (car (cdr (plist-member --cl-rest-- ...))))) (progn (if edit (progn (eglot--apply-workspace-edit edit))) (if command (progn (let (...) (let* ... ...))))))) (t (eglot--error "%S didn't match any of %S" obj-once '(((Command) command arguments) ((CodeAction) edit command)))))
  (let ((obj-once action)) (cond ((condition-case nil (progn (eglot--check-object 'Command obj-once t (memq 'disallow-non-standard-keys eglot-strict-mode) t)) (error nil)) (let* ((--cl-rest-- obj-once) (command (car (cdr ...))) (arguments (car (cdr ...)))) (eglot-execute-command server (intern command) arguments))) ((condition-case nil (progn (eglot--check-object 'CodeAction obj-once t (memq 'disallow-non-standard-keys eglot-strict-mode) t)) (error nil)) (let* ((--cl-rest-- obj-once) (edit (car (cdr ...))) (command (car (cdr ...)))) (progn (if edit (progn (eglot--apply-workspace-edit edit))) (if command (progn (let ... ...)))))) (t (eglot--error "%S didn't match any of %S" obj-once '(((Command) command arguments) ((CodeAction) edit command))))))
  (let* ((server (eglot--current-server-or-lose)) (actions (jsonrpc-request server :textDocument/codeAction (list :textDocument (eglot--TextDocumentIdentifier) :range (list :start (eglot--pos-to-lsp-position beg) :end (eglot--pos-to-lsp-position end)) :context (cons ':diagnostics (cons (apply ... ...) (if action-kind ...)))) :deferred t)) (menu-items (or (let* ((--cl-vec-- actions) (--cl-idx-- -1) (action nil) (--cl-var-- nil)) (while (and (setq --cl-idx-- ...) (< --cl-idx-- ...)) (setq action (aref --cl-vec-- --cl-idx--)) (if (or ... ...) (progn ...))) (nreverse --cl-var--)) (apply #'eglot--user-error (if action-kind (list "No \"%s\" code actions here" action-kind) '("No code actions here"))))) (preferred-action (cl-find-if #'(lambda (menu-item) (plist-get (cdr menu-item) :isPreferred)) menu-items)) (default-action (car (or preferred-action (car menu-items)))) (action (if (and action-kind (null (car (cdr menu-items)))) (cdr (car menu-items)) (if (listp last-nonmenu-event) (x-popup-menu last-nonmenu-event (list "Eglot code actions:" (cons "dummy" menu-items))) (cdr (assoc (completing-read ... menu-items nil t nil nil default-action) menu-items)))))) (let ((obj-once action)) (cond ((condition-case nil (progn (eglot--check-object 'Command obj-once t (memq ... eglot-strict-mode) t)) (error nil)) (let* ((--cl-rest-- obj-once) (command (car ...)) (arguments (car ...))) (eglot-execute-command server (intern command) arguments))) ((condition-case nil (progn (eglot--check-object 'CodeAction obj-once t (memq ... eglot-strict-mode) t)) (error nil)) (let* ((--cl-rest-- obj-once) (edit (car ...)) (command (car ...))) (progn (if edit (progn ...)) (if command (progn ...))))) (t (eglot--error "%S didn't match any of %S" obj-once '((... command arguments) (... edit command)))))))
  eglot-code-actions(530 534 nil)
  funcall-interactively(eglot-code-actions 530 534 nil)
  call-interactively(eglot-code-actions)

I would consider this as a bug, since invoking the code actions via eglot-code-action lands users into a completing-read prompt, which can be exited out using C-g. Therefore, it would not land into a nil case like using mouse-1 would do.

Proposed fix

Using t explicitly allows x-pop-menu to quit instead of returning nil when mouse button event is passed.
Otherwise, the dcase later on will error out on the nil action.

I used the term lost fucs, which I mean that the focus is lost when the user gets rid of the menu without making a valid choice... (see (describe-function x-pop-menu))

Using t explicitly allows x-pop-menu to quit instead of returning nil
when mouse button event is passed.

The focus is lost when the user gets rid of the menu without making a
valid choice... (see `(describe-function x-pop-menu)`)
@joaotavora
Copy link
Owner

I've edited the description and the title so that this PR/issue can stand alone.

@joaotavora joaotavora changed the title fix x-pop-menu returning nil when lost focus Cancelling out of a code-actions dropdown signals non-user error. Fix that. Sep 22, 2022
@Inc0n
Copy link
Author

Inc0n commented Sep 22, 2022

Ok, Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants