aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin
diff options
context:
space:
mode:
authorTomasz N <przepompownia@users.noreply.github.com>2024-10-10 11:40:03 +0200
committerGitHub <noreply@github.com>2024-10-10 11:40:03 +0200
commitb3109084c2c3675aa886bf16ff15f50025f30096 (patch)
tree3fbd9a0fc4d4c2802e93c853f0f6cd4997be55e5 /test/functional/plugin
parent641c4b1a2acbf4d93142af9799dd13539b6ecde9 (diff)
downloadrneovim-b3109084c2c3675aa886bf16ff15f50025f30096.tar.gz
rneovim-b3109084c2c3675aa886bf16ff15f50025f30096.tar.bz2
rneovim-b3109084c2c3675aa886bf16ff15f50025f30096.zip
fix(lsp): fix cursor position after snippet expansion (#30659)
Problem: on `CompleteDone` cursor can jump to the end of line instead of the end of the completed word. Solution: remove only inserted word for snippet expansion instead of everything until eol. Fixes #30656 Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Diffstat (limited to 'test/functional/plugin')
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua121
1 files changed, 88 insertions, 33 deletions
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
index cb49526f56..ec2f88ec32 100644
--- a/test/functional/plugin/lsp/completion_spec.lua
+++ b/test/functional/plugin/lsp/completion_spec.lua
@@ -471,6 +471,39 @@ describe('vim.lsp.completion: item conversion', function()
)
end)
+--- @param completion_result lsp.CompletionList
+--- @return integer
+local function create_server(completion_result)
+ return exec_lua(function()
+ local server = _G._create_server({
+ capabilities = {
+ completionProvider = {
+ triggerCharacters = { '.' },
+ },
+ },
+ handlers = {
+ ['textDocument/completion'] = function(_, _, callback)
+ callback(nil, completion_result)
+ end,
+ },
+ })
+
+ local bufnr = vim.api.nvim_get_current_buf()
+ vim.api.nvim_win_set_buf(0, bufnr)
+ return vim.lsp.start({
+ name = 'dummy',
+ cmd = server.cmd,
+ on_attach = function(client, bufnr0)
+ vim.lsp.completion.enable(true, client.id, bufnr0, {
+ convert = function(item)
+ return { abbr = item.label:gsub('%b()', '') }
+ end,
+ })
+ end,
+ })
+ end)
+end
+
describe('vim.lsp.completion: protocol', function()
before_each(function()
clear()
@@ -487,39 +520,6 @@ describe('vim.lsp.completion: protocol', function()
after_each(clear)
- --- @param completion_result lsp.CompletionList
- --- @return integer
- local function create_server(completion_result)
- return exec_lua(function()
- local server = _G._create_server({
- capabilities = {
- completionProvider = {
- triggerCharacters = { '.' },
- },
- },
- handlers = {
- ['textDocument/completion'] = function(_, _, callback)
- callback(nil, completion_result)
- end,
- },
- })
-
- local bufnr = vim.api.nvim_get_current_buf()
- vim.api.nvim_win_set_buf(0, bufnr)
- return vim.lsp.start({
- name = 'dummy',
- cmd = server.cmd,
- on_attach = function(client, bufnr0)
- vim.lsp.completion.enable(true, client.id, bufnr0, {
- convert = function(item)
- return { abbr = item.label:gsub('%b()', '') }
- end,
- })
- end,
- })
- end)
- end
-
local function assert_matches(fn)
retry(nil, nil, function()
fn(exec_lua('return _G.capture.matches'))
@@ -726,3 +726,58 @@ describe('vim.lsp.completion: protocol', function()
end)
end)
end)
+
+describe('vim.lsp.completion: integration', function()
+ before_each(function()
+ clear()
+ exec_lua(create_server_definition)
+ exec_lua(function()
+ vim.fn.complete = vim.schedule_wrap(vim.fn.complete)
+ end)
+ end)
+
+ after_each(clear)
+
+ it('puts cursor at the end of completed word', function()
+ local completion_list = {
+ isIncomplete = false,
+ items = {
+ {
+ label = 'hello',
+ insertText = '${1:hello} friends',
+ insertTextFormat = 2,
+ },
+ },
+ }
+ exec_lua(function()
+ vim.o.completeopt = 'menuone,noselect'
+ end)
+ create_server(completion_list)
+ feed('i world<esc>0ih<c-x><c-o>')
+ retry(nil, nil, function()
+ eq(
+ 1,
+ exec_lua(function()
+ return vim.fn.pumvisible()
+ end)
+ )
+ end)
+ feed('<C-n><C-y>')
+ eq(
+ { true, { 'hello friends world' } },
+ exec_lua(function()
+ return {
+ vim.snippet.active({ direction = 1 }),
+ vim.api.nvim_buf_get_lines(0, 0, -1, true),
+ }
+ end)
+ )
+ feed('<tab>')
+ eq(
+ #'hello friends',
+ exec_lua(function()
+ return vim.api.nvim_win_get_cursor(0)[2]
+ end)
+ )
+ end)
+end)