Skip to content

Commit

Permalink
Merge pull request #27339 from MariaSolOs/completion
Browse files Browse the repository at this point in the history
feat(lsp): completion side effects
  • Loading branch information
gpanders authored May 28, 2024
2 parents 8ba73f0 + e6cfcae commit 0bdd602
Show file tree
Hide file tree
Showing 12 changed files with 1,110 additions and 301 deletions.
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

* On Windows, filename arguments on the command-line prefixed with "~\" or
Expand All @@ -97,7 +103,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 @@ -1003,8 +1003,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 @@ -868,7 +868,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 @@ -882,14 +883,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

0 comments on commit 0bdd602

Please sign in to comment.