Skip to content

Commit 0bdd602

Browse files
authored
Merge pull request #27339 from MariaSolOs/completion
feat(lsp): completion side effects
2 parents 8ba73f0 + e6cfcae commit 0bdd602

File tree

12 files changed

+1110
-301
lines changed

12 files changed

+1110
-301
lines changed

runtime/doc/lsp.txt

+26
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,32 @@ save({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.save()*
16041604
• {client_id} (`integer`)
16051605

16061606

1607+
==============================================================================
1608+
Lua module: vim.lsp.completion *lsp-completion*
1609+
1610+
*vim.lsp.completion.BufferOpts*
1611+
1612+
Fields: ~
1613+
{autotrigger}? (`boolean`) Whether to trigger completion
1614+
automatically. Default: false
1615+
1616+
1617+
*vim.lsp.completion.enable()*
1618+
enable({enable}, {client_id}, {bufnr}, {opts})
1619+
Enables or disables completions from the given language client in the
1620+
given buffer.
1621+
1622+
Parameters: ~
1623+
{enable} (`boolean`) True to enable, false to disable
1624+
• {client_id} (`integer`) Client ID
1625+
{bufnr} (`integer`) Buffer handle, or 0 for the current buffer
1626+
{opts} (`vim.lsp.completion.BufferOpts?`) See
1627+
|vim.lsp.completion.BufferOpts|.
1628+
1629+
trigger() *vim.lsp.completion.trigger()*
1630+
Trigger LSP completion in the current buffer.
1631+
1632+
16071633
==============================================================================
16081634
Lua module: vim.lsp.inlay_hint *lsp-inlay_hint*
16091635

runtime/doc/news.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ DEFAULTS
8585
- |gra| in Normal and Visual mode maps to |vim.lsp.buf.code_action()|
8686
- CTRL-S in Insert mode maps to |vim.lsp.buf.signature_help()|
8787

88+
• Snippet:
89+
- `<Tab>` in Insert and Select mode maps to |vim.snippet.jump({ direction = 1 })|
90+
when a snippet is active and jumpable forwards.
91+
- `<S-Tab>` in Insert and Select mode maps to |vim.snippet.jump({ direction = -1 })|
92+
when a snippet is active and jumpable backwards.
93+
8894
EDITOR
8995

9096
* On Windows, filename arguments on the command-line prefixed with "~\" or
@@ -97,7 +103,8 @@ EVENTS
97103

98104
LSP
99105

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

102109
LUA
103110

runtime/lua/vim/lsp.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ local validate = vim.validate
33

44
local lsp = vim._defer_require('vim.lsp', {
55
_changetracking = ..., --- @module 'vim.lsp._changetracking'
6-
_completion = ..., --- @module 'vim.lsp._completion'
76
_dynamic = ..., --- @module 'vim.lsp._dynamic'
87
_snippet_grammar = ..., --- @module 'vim.lsp._snippet_grammar'
98
_tagfunc = ..., --- @module 'vim.lsp._tagfunc'
109
_watchfiles = ..., --- @module 'vim.lsp._watchfiles'
1110
buf = ..., --- @module 'vim.lsp.buf'
1211
client = ..., --- @module 'vim.lsp.client'
1312
codelens = ..., --- @module 'vim.lsp.codelens'
13+
completion = ..., --- @module 'vim.lsp.completion'
1414
diagnostic = ..., --- @module 'vim.lsp.diagnostic'
1515
handlers = ..., --- @module 'vim.lsp.handlers'
1616
inlay_hint = ..., --- @module 'vim.lsp.inlay_hint'
@@ -1003,8 +1003,7 @@ end
10031003
--- - findstart=0: column where the completion starts, or -2 or -3
10041004
--- - findstart=1: list of matches (actually just calls |complete()|)
10051005
function lsp.omnifunc(findstart, base)
1006-
log.debug('omnifunc.findstart', { findstart = findstart, base = base })
1007-
return vim.lsp._completion.omnifunc(findstart, base)
1006+
return vim.lsp.completion._omnifunc(findstart, base)
10081007
end
10091008

10101009
--- @class vim.lsp.formatexpr.Opts

runtime/lua/vim/lsp/_completion.lua

-276
This file was deleted.

runtime/lua/vim/lsp/client.lua

+14-9
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ end
868868
--- @param command lsp.Command
869869
--- @param context? {bufnr: integer}
870870
--- @param handler? lsp.Handler only called if a server command
871-
function Client:_exec_cmd(command, context, handler)
871+
--- @param on_unsupported? function handler invoked when the command is not supported by the client.
872+
function Client:_exec_cmd(command, context, handler, on_unsupported)
872873
context = vim.deepcopy(context or {}, true) --[[@as lsp.HandlerContext]]
873874
context.bufnr = context.bufnr or api.nvim_get_current_buf()
874875
context.client_id = self.id
@@ -882,14 +883,18 @@ function Client:_exec_cmd(command, context, handler)
882883
local command_provider = self.server_capabilities.executeCommandProvider
883884
local commands = type(command_provider) == 'table' and command_provider.commands or {}
884885
if not vim.list_contains(commands, cmdname) then
885-
vim.notify_once(
886-
string.format(
887-
'Language server `%s` does not support command `%s`. This command may require a client extension.',
888-
self.name,
889-
cmdname
890-
),
891-
vim.log.levels.WARN
892-
)
886+
if on_unsupported then
887+
on_unsupported()
888+
else
889+
vim.notify_once(
890+
string.format(
891+
'Language server `%s` does not support command `%s`. This command may require a client extension.',
892+
self.name,
893+
cmdname
894+
),
895+
vim.log.levels.WARN
896+
)
897+
end
893898
return
894899
end
895900
-- Not using command directly to exclude extra properties,

0 commit comments

Comments
 (0)