embark icon indicating copy to clipboard operation
embark copied to clipboard

lsp-mode and `embark-prefix-help-command`

Open jdtsmith opened this issue 4 years ago • 2 comments

Although it works with normal prefix help, the lsp-mode prefix (s-' for me) does not work with embark-prefix-help-command (see emacs-lsp/lsp-mode#3203). I think that's because the bindings are all rewritten to be menu-items, e.g.:

(menu-item "maybe-lsp-ui-peek-find-references" lsp-ui-peek-find-references :filter (lambda (item) (when (with-current-buffer (or (when (buffer-live-p lsp--describe-buffer) lsp--describe-buffer) (current-buffer)) (and (fboundp 'lsp-ui-peek-find-references) (lsp-feature\? "textDocument/references"))) item)))

This is apparently by design:

(defmacro lsp-define-conditional-key (keymap key def desc cond &rest bindings)
  "In KEYMAP, define key sequence KEY as DEF conditionally.
This is like `define-key', except the definition disappears
whenever COND evaluates to nil.
DESC is the short-description for the binding.
BINDINGS is a list of (key def desc cond)."
...

This macro repurposes menu-item bindings as normal bindings so it can disable them using a :filter form. Embark clears these bindings out as "not real key bindings". Which clearly isn't the case here.

Example:

C-h b s-' h h:

s-' h h runs the command lsp-describe-thing-at-point (found in
lsp-mode-map), which is an interactive compiled Lisp function in
‘lsp-mode.el’.

It is bound to s-' h h.

(lsp-describe-thing-at-point)

Display the type signature and documentation of the thing at
point.

with the relevant bit of the keymap:

	  (104 keymap
	       (104 menu-item "maybe-lsp-describe-thing-at-point" lsp-describe-thing-at-point :filter
		    (lambda #1#
		      (when
			  (with-current-buffer #2#
			    (lsp-feature\? "textDocument/hover"))
			. #3#)))

jdtsmith avatar Nov 13 '21 19:11 jdtsmith

See #383

minad avatar Nov 13 '21 21:11 minad

Interesting. Is it relatively easy to first add support for menu-item key bindings?

jdtsmith avatar Nov 14 '21 16:11 jdtsmith

I've added preliminary support for menu-items but it just always shows all of them, none of this disappearing stuff is supported yet.

oantolin avatar Feb 27 '23 03:02 oantolin

OK, now :filter is supported. If you're still using lsp, please let me know if da144277663d761a22e0425117528b19b4fd43ba fixes this issue.

oantolin avatar Feb 27 '23 08:02 oantolin

I'm not sure I want to install and configure lsp just to test whether the :filter support in Embark really fixes this issue. I'll optimistically trust that it does, but please reopen the issue if there are still any problems.

oantolin avatar Mar 01 '23 14:03 oantolin