aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2024-08-31 02:23:49 +0800
committerGitHub <noreply@github.com>2024-08-30 20:23:49 +0200
commit42ed0ffad9851f3794a9dff080a2789c87c6d7c8 (patch)
treeb6475df03f863ce9179a614158d437d56f31813f
parent5f95f1249f464e4f0ceed468ec5a1ba6e810da14 (diff)
downloadrneovim-42ed0ffad9851f3794a9dff080a2789c87c6d7c8.tar.gz
rneovim-42ed0ffad9851f3794a9dff080a2789c87c6d7c8.tar.bz2
rneovim-42ed0ffad9851f3794a9dff080a2789c87c6d7c8.zip
fix(lsp): when prefix is non word add all result into matches (#30044)
Problem: prefix can be a symbol like period, the fuzzy matching can't handle it correctly. Solution: when prefix is empty or a symbol add all lsp completion result into matches.
-rw-r--r--runtime/lua/vim/lsp/completion.lua2
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua33
2 files changed, 28 insertions, 7 deletions
diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua
index e28fec5e25..89d6d0e8b9 100644
--- a/runtime/lua/vim/lsp/completion.lua
+++ b/runtime/lua/vim/lsp/completion.lua
@@ -238,7 +238,7 @@ function M._lsp_to_complete_items(result, prefix, client_id)
---@type fun(item: lsp.CompletionItem):boolean
local matches
- if prefix == '' then
+ if not prefix:find('%w') then
matches = function(_)
return true
end
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
index 766dd16541..16d64fc95d 100644
--- a/test/functional/plugin/lsp/completion_spec.lua
+++ b/test/functional/plugin/lsp/completion_spec.lua
@@ -18,35 +18,36 @@ local create_server_definition = t_lsp.create_server_definition
---@param candidates lsp.CompletionList|lsp.CompletionItem[]
---@param lnum? integer 0-based, defaults to 0
---@return {items: table[], server_start_boundary: integer?}
-local function complete(line, candidates, lnum)
+local function complete(line, candidates, lnum, server_boundary)
lnum = lnum or 0
-- nvim_win_get_cursor returns 0 based column, line:find returns 1 based
local cursor_col = line:find('|') - 1
line = line:gsub('|', '')
return exec_lua(
[[
- local line, cursor_col, lnum, result = ...
+ local line, cursor_col, lnum, result, server_boundary = ...
local line_to_cursor = line:sub(1, cursor_col)
local client_start_boundary = vim.fn.match(line_to_cursor, '\\k*$')
- local items, server_start_boundary = require("vim.lsp.completion")._convert_results(
+ local items, new_server_boundary = require("vim.lsp.completion")._convert_results(
line,
lnum,
cursor_col,
1,
client_start_boundary,
- nil,
+ server_boundary,
result,
"utf-16"
)
return {
items = items,
- server_start_boundary = server_start_boundary
+ server_start_boundary = new_server_boundary
}
]],
line,
cursor_col,
lnum,
- candidates
+ candidates,
+ server_boundary
)
end
@@ -162,6 +163,26 @@ describe('vim.lsp.completion: item conversion', function()
eq(expected, result)
end)
+ it('works on non word prefix', function()
+ local completion_list = {
+ { label = ' foo', insertText = '->foo' },
+ }
+ local result = complete('wp.|', completion_list, 0, 2)
+ local expected = {
+ {
+ abbr = ' foo',
+ word = '->foo',
+ },
+ }
+ result = vim.tbl_map(function(x)
+ return {
+ abbr = x.abbr,
+ word = x.word,
+ }
+ end, result.items)
+ eq(expected, result)
+ end)
+
it('trims trailing newline or tab from textEdit', function()
local range0 = {
start = { line = 0, character = 0 },