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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions runtime/doc/lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,32 @@ save({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.save()*
• {client_id} (`integer`)


==============================================================================
Lua module: vim.lsp.completion *lsp-completion*

*vim.lsp.completion.BufferOpts*

Fields: ~
• {autotrigger}? (`boolean`) Whether to trigger completion
automatically. Default: false


*vim.lsp.completion.enable()*
enable({enable}, {client_id}, {bufnr}, {opts})
Enables or disables completions from the given language client in the
given buffer.

Parameters: ~
• {enable} (`boolean`) True to enable, false to disable
• {client_id} (`integer`) Client ID
• {bufnr} (`integer`) Buffer handle, or 0 for the current buffer
• {opts} (`vim.lsp.completion.BufferOpts?`) See
|vim.lsp.completion.BufferOpts|.

trigger() *vim.lsp.completion.trigger()*
Trigger LSP completion in the current buffer.


==============================================================================
Lua module: vim.lsp.inlay_hint *lsp-inlay_hint*

Expand Down
9 changes: 8 additions & 1 deletion runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ DEFAULTS
- |gra| in Normal and Visual mode maps to |vim.lsp.buf.code_action()|
- CTRL-S in Insert mode maps to |vim.lsp.buf.signature_help()|

• Snippet:
- `<Tab>` in Insert and Select mode maps to |vim.snippet.jump({ direction = 1 })|
when a snippet is active and jumpable forwards.
- `<S-Tab>` in Insert and Select mode maps to |vim.snippet.jump({ direction = -1 })|
when a snippet is active and jumpable backwards.

EDITOR

• TODO
Expand All @@ -95,7 +101,8 @@ EVENTS

LSP

• TODO
• Completion side effects (including snippet expansion, execution of commands
and application of additional text edits) is now built-in.

LUA

Expand Down
5 changes: 2 additions & 3 deletions runtime/lua/vim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ local validate = vim.validate

local lsp = vim._defer_require('vim.lsp', {
_changetracking = ..., --- @module 'vim.lsp._changetracking'
_completion = ..., --- @module 'vim.lsp._completion'
_dynamic = ..., --- @module 'vim.lsp._dynamic'
_snippet_grammar = ..., --- @module 'vim.lsp._snippet_grammar'
_tagfunc = ..., --- @module 'vim.lsp._tagfunc'
_watchfiles = ..., --- @module 'vim.lsp._watchfiles'
buf = ..., --- @module 'vim.lsp.buf'
client = ..., --- @module 'vim.lsp.client'
codelens = ..., --- @module 'vim.lsp.codelens'
completion = ..., --- @module 'vim.lsp.completion'
diagnostic = ..., --- @module 'vim.lsp.diagnostic'
handlers = ..., --- @module 'vim.lsp.handlers'
inlay_hint = ..., --- @module 'vim.lsp.inlay_hint'
Expand Down Expand Up @@ -1002,8 +1002,7 @@ end
--- - findstart=0: column where the completion starts, or -2 or -3
--- - findstart=1: list of matches (actually just calls |complete()|)
function lsp.omnifunc(findstart, base)
log.debug('omnifunc.findstart', { findstart = findstart, base = base })
return vim.lsp._completion.omnifunc(findstart, base)
return vim.lsp.completion._omnifunc(findstart, base)
end

--- @class vim.lsp.formatexpr.Opts
Expand Down
276 changes: 0 additions & 276 deletions runtime/lua/vim/lsp/_completion.lua

This file was deleted.

23 changes: 14 additions & 9 deletions runtime/lua/vim/lsp/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,8 @@ end
--- @param command lsp.Command
--- @param context? {bufnr: integer}
--- @param handler? lsp.Handler only called if a server command
function Client:_exec_cmd(command, context, handler)
--- @param on_unsupported? function handler invoked when the command is not supported by the client.
function Client:_exec_cmd(command, context, handler, on_unsupported)
context = vim.deepcopy(context or {}, true) --[[@as lsp.HandlerContext]]
context.bufnr = context.bufnr or api.nvim_get_current_buf()
context.client_id = self.id
Expand All @@ -883,14 +884,18 @@ function Client:_exec_cmd(command, context, handler)
local command_provider = self.server_capabilities.executeCommandProvider
local commands = type(command_provider) == 'table' and command_provider.commands or {}
if not vim.list_contains(commands, cmdname) then
vim.notify_once(
string.format(
'Language server `%s` does not support command `%s`. This command may require a client extension.',
self.name,
cmdname
),
vim.log.levels.WARN
)
if on_unsupported then
on_unsupported()
else
vim.notify_once(
string.format(
'Language server `%s` does not support command `%s`. This command may require a client extension.',
self.name,
cmdname
),
vim.log.levels.WARN
)
end
return
end
-- Not using command directly to exclude extra properties,
Expand Down
Loading
Loading