diff options
author | Maria José Solano <majosolano99@gmail.com> | 2025-03-10 09:20:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-10 09:20:27 -0700 |
commit | 3b0fe2659e74276e995655d1f8954b48005292e6 (patch) | |
tree | 2468cf6b51d31ac239ad9330de3486a60265a3a3 /test | |
parent | 67c39f5ecae0edc3777b2db0f7e637cafa097d05 (diff) | |
download | rneovim-3b0fe2659e74276e995655d1f8954b48005292e6.tar.gz rneovim-3b0fe2659e74276e995655d1f8954b48005292e6.tar.bz2 rneovim-3b0fe2659e74276e995655d1f8954b48005292e6.zip |
feat(lsp): support completion context #32793
Problem:
vim.lsp.completion with "autotrigger" enabled, does not send
completion context, even though it has all the necessary info.
Solution:
Include the context for "autotrigger".
trigger() also optionally accepts context when manually invoked.
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/plugin/lsp/completion_spec.lua | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index c5fa411efe..8d362642de 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -1127,6 +1127,73 @@ describe('vim.lsp.completion: protocol', function() eq('foo', matches[1].abbr) end) end) + + it('sends completion context when invoked', function() + local params = exec_lua(function() + local params + local server = _G._create_server({ + capabilities = { + completionProvider = true, + }, + handlers = { + ['textDocument/completion'] = function(_, params0, callback) + params = params0 + callback(nil, nil) + end, + }, + }) + + local bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + vim.lsp.start({ + name = 'dummy', + cmd = server.cmd, + on_attach = function(client, bufnr0) + vim.lsp.completion.enable(true, client.id, bufnr0) + end, + }) + + vim.lsp.completion.trigger() + + return params + end) + + eq({ triggerKind = 1 }, params.context) + end) + + it('sends completion context with trigger characters', function() + exec_lua(function() + local server = _G._create_server({ + capabilities = { + completionProvider = { + triggerCharacters = { 'h' }, + }, + }, + handlers = { + ['textDocument/completion'] = function(_, params, callback) + _G.params = params + callback(nil, { isIncomplete = false, items = { label = 'hello' } }) + end, + }, + }) + + local bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + vim.lsp.start({ + name = 'dummy', + cmd = server.cmd, + on_attach = function(client, bufnr0) + vim.lsp.completion.enable(true, client.id, bufnr0, { autotrigger = true }) + end, + }) + end) + + feed('ih') + + retry(100, nil, function() + eq({ triggerKind = 2, triggerCharacter = 'h' }, exec_lua('return _G.params.context')) + end) + end) end) describe('vim.lsp.completion: integration', function() |