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

feat(LSP): Allow users to manage Company backends manually #16627

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

niontrix
Copy link
Contributor

Why?:

  • Currently lsp-mode aggressively inserts the company-capf backend, which contains its completion-at-point-function, as the ultimate first item of the list of company-backends. If a language server does not provide all the functionality, that could otherwise be provided by another Company backend like company-files for example, lsp-mode will practically block any other Company backend inside company-backends from running, because it tells Company that it may be able to complete at point but in the end doesn't provide any completion candidates. This is not ideal and users may want to manage company-backends by themselves. Also using this variable within some language layers; we could also be able to provide a more focused list of Company backends for that mode that extends the functionality currently not provided by the language server.

This change addresses the need by:

  • Introduce new lsp-layer variable lsp-manage-backends-manually, which can either be :all (to manage the backends for every major-mode manually), a list of major-modes (to manage backends for these specific modes manually) or nil to let lsp-mode manage the company-backends
  • Modify lsp/init-lsp-mode to set lsp-completion-provider based on the value of lsp-manage-backends-manually

Why?:
- Currently lsp-mode aggressively inserts the company-capf backend, which
  contains its completion-at-point-function, as the ultimate first item of the
  list of company-backends. If a language server does not provide all the
  functionality, that could otherwise be provided by another Company backend like
  company-files for example, lsp-mode will practically block any other Company
  backend inside company-backends from running, because it tells Company that it
  may be able to complete at point but in the end doesn't provide any completion
  candidates. This is not ideal and users may want to manage company-backends by
  themselves. Also using this variable within some language layers; we could also
  be able to provide a more focused list of Company backends for that mode that
  extends the functionality currently not provided by the language server.

This change addresses the need by:
- Introduce new lsp-layer variable lsp-manage-backends-manually, which can
  either be :all (to manage the backends for every major-mode manually), a
  list of major-modes (to manage backends for these specific modes manually)
  or nil to let lsp-mode manage the company-backends
- Modify lsp/init-lsp-mode to set lsp-completion-provider based on the
  value of lsp-manage-backends-manually
@niontrix niontrix marked this pull request as draft October 30, 2024 14:07
@niontrix
Copy link
Contributor Author

Ok, maybe this is not ready just yet. When company-capf is not the first item in the company-backends list the sorting of the candidates is now broken - at least when using it with gopls. I'll try to find the issue first or create an issue upstream.

@niontrix
Copy link
Contributor Author

To make company-files work in conjunction with company-capf one needs to set company-backends like this for example

(setq-local company-backends '(:separate company-capf company-files company-yasnippet))

@niontrix niontrix marked this pull request as ready for review October 30, 2024 18:11
@niontrix niontrix marked this pull request as draft November 1, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant