manateelazycat / lsp-bridge

A blazingly fast LSP client for Emacs
GNU General Public License v3.0
1.35k stars 197 forks source link

How can I detect if ACM menu is active when hitting Tab? #974

Closed aguynamedben closed 6 days ago

aguynamedben commented 1 week ago

Thank you for providing this package, it's incredible.

Which function or variable can I use to detect it if the ACM menu is currently showing? I'm trying to use lsp-bridge alongside copilot.el and mimic tab completion in VS Code:

  1. If the ACM menu is showing and I hit Tab, take the ACM completion
  2. Otherwise, take the copilot.el completion

However I'm unable to determine a variable or function I can use from acm that will tell me if it's currently showing or not.

I've tried these 4 conditions, but they all seem to return false even when I'm hitting Tab while the ACM menu is open.

Attempt 1

(if (acm-frame-visible-p acm-menu-frame)
    (progn
      (message "Using lsp-bridge completion - old")
      (acm-complete))
  (progn
    (message "Using copilot.el completion - old")
    (copilot-accept-completion)))

Result: Uses copilot

Attempt 2

(if (lsp-bridge-completion-ui-visible-p)
  (progn
    (message "Using lsp-bridge completion - old2")
    (acm-complete))
  (progn
    (message "Using copilot.el completion - old2")
    (copilot-accept-completion)))

Result: Uses copilot

Attempt 3

(if (and acm-mode acm-menu-candidates)
  (progn
    (message "Using lsp-bridge completion - old2")
    (acm-complete))
  (progn
    (message "Using copilot.el completion - old2")
    (copilot-accept-completion)))

Result: Uses copilot

Attempt 4

(if (frame-visible-p acm-menu-frame)
  (progn
    (message "Using lsp-bridge completion - old2")
    (acm-complete))
  (progn
    (message "Using copilot.el completion - old2")
    (copilot-accept-completion)))

Result: Uses copilot

Checking if acm-menu-candidates is nil seems to "works" the first time, but that variable stays populated after the ACM menu is hiding. Also, I tried if (and (fboundp 'lsp-bridge-completion-ui-visible-p) (funcall 'lsp-bridge-completion-ui-visible-p)) but that also seems to return nil even when I'm hitting tab and the ACM menu is open.

Maybe this is a race condition? Do you have any suggestions or docs on how to conditionally handle Tab?

manateelazycat commented 1 week ago

I have try below code, works fine

(run-with-timer 5 nil (lambda ()
                        (when (acm-frame-visible-p acm-menu-frame)
                          (message "acm frame is show"))))
manateelazycat commented 6 days ago

It cannot be reproduced. If there is any problem, please reopen the issue. Thank you.