manateelazycat / lsp-bridge

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

Completion menu showing before being fully created and sorted #1080

Open m-ar-c opened 1 month ago

m-ar-c commented 1 month ago

Tweaking acm-completion-backend-merge-order as suggested in #1078 worked perfectly to sort the menu, now the yasnippet completions are always at the top of the completion list.

But it didn't solve the real need I had, being :

so that I can type my key and hit tab right away and always have my beloved snippets expanded.

Because when I type a yasnippet key and hit tab right away, lsp-bridge being fast, the completion menu is shown almost instantly BUT the items in the completion menu are still being created and sorted. So, until the menu is fully populated, the yasnippet are not at the top. That means that 9 times out of 10 (because I am too quick to hit tab) the completion made is not what I want.

I see two ways to solve this :

1/ Show the completion menu only after a small delay (so that I have time to expand my yasnippet key before the menu shows up).

Or better (in my opinion) :

2/ Show the menu only when it is fully populated and sorted, so that the same actions always yields the same results (no matter the time you take to hit the keys).

I couldn't find any variables to tweak to achieve either 1/ or 2/.

(I am aware of lsp-bridge-complete-manually (as mentionned in #623) but I do want the menu to popup automatically.)

manateelazycat commented 1 month ago

lsp-bridge is full async design, every backend (lsp or yas) have result will make acm menu redraw, we can't stop lsp candidate show to wait yas candidate.

It's will make lsp-bridge slow as lsp-mode or eglot, it's not lsp-bridge's target.

manateelazycat commented 1 month ago

You can find other way to fit your need, but I won't accept any request that slow down the lsp-bridge's speed.

m-ar-c commented 1 month ago

Thanks for your answer!

I ended up adding a small delay to the popup, that way :

(require 'timeout)

(defvar lsp-bridge-try-completion-debounced-fn
  (timeout-debounce! #'lsp-bridge-try-completion 0.5)
  "Debounced version of `lsp-bridge-try-completion` with a 0.5-second delay.")

(defun lsp-bridge-try-completion-debounced ()
  "Function to call the debounced version of `lsp-bridge-try-completion`."
  (funcall lsp-bridge-try-completion-debounced-fn))

(with-eval-after-load 'lsp-bridge
  (remove-hook 'post-command-hook #'lsp-bridge-try-completion)
  (add-hook 'post-command-hook #'lsp-bridge-try-completion-debounced))

With the help of timeout. No idea if it is the proper or best way to do it, but it seems to work fine so far.

I don't really need the (unsorted) completion popup to be shown immediately (it can even be slightly annoying having a thing always poping and moving as you type), but I really need a consistent behavior and be able to hit tab right after I wrote my yasnippet key. So all's good for me now.

manateelazycat commented 1 month ago

Thanks for your answer! 感谢您的回答!

I ended up adding a small delay to the popup, that way :我最终在弹出窗口中添加了一个小延迟,这样:

(require 'timeout)

(defvar lsp-bridge-try-completion-debounced-fn
  (timeout-debounce! #'lsp-bridge-try-completion 0.5)
  "Debounced version of `lsp-bridge-try-completion` with a 0.5-second delay.")

(defun lsp-bridge-try-completion-debounced ()
  "Function to call the debounced version of `lsp-bridge-try-completion`."
  (funcall lsp-bridge-try-completion-debounced-fn))

(with-eval-after-load 'lsp-bridge
  (remove-hook 'post-command-hook #'lsp-bridge-try-completion)
  (add-hook 'post-command-hook #'lsp-bridge-try-completion-debounced))

With the help of timeout. No idea if it is the proper or best way to do it, but it seems to work fine so far.借助超时。不知道这是否是正确或最好的方法,但到目前为止似乎效果很好。

I don't really need the (unsorted) completion popup to be shown immediately (it can even be slightly annoying having a thing always poping and moving as you type), but I really need a consistent behavior and be able to hit tab right after I wrote my yasnippet key. So all's good for me now.我真的不需要立即显示(未排序的)完成弹出窗口(当您键入时总是弹出和移动某个东西甚至可能有点烦人),但我确实需要一致的行为并且能够在之后立即点击选项卡我写了我的 yasnippet 密钥。所以现在一切对我来说都很好。

OK, can you rewrite this patch as a option? I don't like this patch, but I will merge option PR if user like it.