emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.79k stars 890 forks source link

`lsp-completion-at-point` short-circuits the completion function chain #4386

Open magnars opened 7 months ago

magnars commented 7 months ago

Thank you for the bug report

Bug description

After adding my own function to completion-at-point-functions it turns out that lsp-completion-at-point shortcuts the completion function chain when it does not find any completions of its own.

A completion at point-function can return nil to pass on the completion, allowing the next completion function in line to try. I think maybe lsp-completion-at-point always returns a lambda, which then would short-circuit the others in the list.

One way to work around that would be to ensure that lsp-mode appends instead of prepends its function to the list. Now it places itself in front of everything else, blocking them.

Steps to reproduce

Expected behavior

If lsp-mode can't complete, let the other completion functions have a go - OR wait with lsp-mode completions until the end.

Which Language Server did you use?

Not relevant.

OS

MacOS

Error callstack

No error call stack.

Anything else?

I realize the way lsp works might not mesh very well with how emacs completion works. I would assume that is why it is not being a "good citizen" with the other completion functions in the list. Maybe an option would be to move lsp-completion to the end of the chain.

yyoncho commented 7 months ago

I realize the way lsp works might not mesh very well with how emacs completion works. I would assume that is why it is not being a "good citizen" with the other completion functions in the list. Maybe an option would be to move lsp-completion to the end of the chain.

Back when we started we were discussing how to make the lsp-mode configuration work the decision was to create a default configuration and allow the user to turn it off when the default configuration does not work for them or provide an extension point to make the custom adjustments. You would agree that we cannot support all possible configurations OOTB. In this particular case, you may use lsp-completion-mode-hook and order the completion-at-point-functions the way you want.

Let me know if that works for you.

magnars commented 7 months ago

Yes, I can for sure make that work. I would argue that lsp-mode should partake better in the completion function chain, but I can work around the issue using the hook. Thanks for the quick answer!