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

Allow company-mode to wait for a backend with special value of prefix before proceeding to the next #992

Open
kiennq opened this issue Jun 30, 2020 · 8 comments
Labels

Comments

@kiennq
Copy link
Contributor

kiennq commented Jun 30, 2020

Open per emacs-lsp/lsp-mode#1611 (comment)

This is especially useful for capf since it has to return prefix before hand and company-capf is based on that to determine if it should be used or not.
However in the case of programmed completion, most capf will not know if it has any completion item when it return prefix bounds and just quickly return symbol bounds, thus prevent company-mode to go to next backends.
Perhaps :company-prefix property can be re-used and pass special value so that company-mode will wait to see if there's any completion item from that backend before going to the next.

@dgutov dgutov changed the title [Feature request] Allow company-mode to wait for a backend with special value of prefix before proceeding to the next. [Feature request] Allow company-mode to wait for a backend with special value of prefix before proceeding to the next Jun 30, 2020
@dgutov
Copy link
Member

dgutov commented Jun 30, 2020

Okay, but.

most capf will not know if it has any completion item when it return prefix bounds and just quickly return symbol bounds

This is the normal case. Non-nil prefix means "I can complete here", and then an empty completion table means that there are in fact no completions, period. Especially for a backend like LSP, which uses smart external processes, and not just tea leaves and guessing.

Is there a particular reason you need this?

@dgutov dgutov changed the title [Feature request] Allow company-mode to wait for a backend with special value of prefix before proceeding to the next Allow company-mode to wait for a backend with special value of prefix before proceeding to the next Jun 30, 2020
@kiennq
Copy link
Contributor Author

kiennq commented Jun 30, 2020

We have several questions on lsp-mode about why other company backends not working when lsp-mode return no completion item.
For now, it's indeed by design, since lsp-mode will try to complete on everywhere, thus prevent other backends from running.
While it's possible to use company-other-backend or using multi backend, they're actually providing sub-optimal solution as company-other-backend requires another hot key and multi-backend provide noise items even when there's completion items from main backend.

I feel it would be natural for backend that return no completion item should pass the control to next one.

One possible problem is that if a backend is return no completion item due to interrupted by input, we should not pass the control to next one in that case though.

@dgutov
Copy link
Member

dgutov commented Jun 30, 2020

I feel it would be natural for backend that return no completion item should pass the control to next one.

In general, that's not my impression. If a high-quality backend returns no completions, doesn't that mean that indeed there are none? And completions offered by the fallback to company-dabbrev-code would be false positives.

@kiennq
Copy link
Contributor Author

kiennq commented Jun 30, 2020

Let put this another way, for example I have an backend that suggest high quality completion item, but does nothing in comment, and I want to have something else like company-ispell to do that job.
What should be the config for multi-backend to support that?
I think you mention :exclusive before, will that comply with the desired behavior?

@dgutov
Copy link
Member

dgutov commented Jun 30, 2020

but does nothing in comment, and I want to have something else like company-ispell to do that job

Normally, the "high-quality" backend would then see if it's inside a comment in its prefix handler, and if so, it will return nil.

See company-clang, company-gtags and company-dabbrev-code for examples.

The corresponding c-a-p-f behavior will be returning nil from the lsp-completion-at-point call when invoked inside a comment (you can't use company-in-string-or-comment, obviously, but it's trivial to re-implement).

@netjune
Copy link

netjune commented Jul 1, 2020

This seems like another issue: #806

For example, in a function, I want to declare a variable and I'm typing its name. In this case, company-lsp will not give any candicates. And I want company-dabbrev-code to give candicates in other files or functions. I use same variable names in different functions commonly.

@kiennq
Copy link
Contributor Author

kiennq commented Jul 1, 2020

This is indeed similar to :exclusive property of completion-at-point-functions.
@dgutov Can you consider supporting it in company-mode too?

@dgutov
Copy link
Member

dgutov commented Jul 1, 2020

I'm not sure it's the best approach, to have a backend decide whether it's non-exclusive (which is the approach :exclusive takes).

At least in this case, LSP should probably indeed be "exclusive", with an option (okay) for the user to override this.

@dgutov dgutov mentioned this issue Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants