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): completion side effects #27339

Merged
merged 3 commits into from
May 28, 2024
Merged

Conversation

MariaSolOs
Copy link
Member

@MariaSolOs MariaSolOs commented Feb 4, 2024

Closes #25714

This PR introduces vim.lsp.completion with the goal of supporting the completion behaviours (snippet expansion, execution of commands, application of text edits) specified by LSP.

To enable completions for a given buffer and client, users should call vim.lsp.completion.enable(true, client_id, bufnr, opts). Currently the options parameter includes the autotrigger property, which when set will request completions after a trigger character has been typed.

This PR also sets new default keymaps for the snippet navigation:

  • <Tab> will jump to the next tabstop if the snippet is active and jumpable forwards.
  • <S-Tab> will jump to the previous tabstop if the snippet is active and jumpable backwards.

If these keys are being used in other keymaps, they will be restored once the snippet session ends.

runtime/lua/vim/lsp/_completion.lua Outdated Show resolved Hide resolved
runtime/lua/vim/lsp/protocol.lua Show resolved Hide resolved
runtime/lua/vim/lsp.lua Outdated Show resolved Hide resolved
end

--- Trigger LSP completion in the current buffer.
function M.trigger_completion()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is mostly called in "scheduled" fashion (via vim.shedule() or after vim.schedule_wrap()). Usually it should be possible to do single schedule_wrap() after defining function instead of all other scheduling in place.

@MariaSolOs MariaSolOs force-pushed the completion branch 3 times, most recently from 941a60a to facf46f Compare April 28, 2024 01:22
@mfussenegger mfussenegger added this to the 0.11 milestone Apr 28, 2024
runtime/doc/lsp.txt Outdated Show resolved Hide resolved
@MariaSolOs
Copy link
Member Author

Okay the implementation is done and tests are all passing. At this point we just need to agree on whether we should enable completion by default and the structure of the public API (so just the usual bikeshedding ;)).

Not sure if we want to do that in this PR or in a separate one. Wdyt @mfussenegger @clason @justinmk @gpanders?

@MariaSolOs MariaSolOs force-pushed the completion branch 2 times, most recently from 755e769 to c972f7a Compare May 27, 2024 01:33
runtime/doc/lsp.txt Outdated Show resolved Hide resolved
Copy link
Member

@justinmk justinmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a blocker: did you intend to revert your supports_method changes in lsp.txt ?

@MariaSolOs
Copy link
Member Author

not a blocker: did you intend to revert your supports_method changes in lsp.txt ?

Yeah I didn't want to keep the changes in that file with stuff unrelated to this PR. I plan on doing a better review of the current LSP docs later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completion Nvim built-in (omni)completion lsp snippet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for LSP completion side effects (snippet expansion, command execution, additionalTextEdits)
9 participants