Compare commits

...

3 Commits

Author SHA1 Message Date
glepnir
c452a090f1
Merge a2ed5f1013 into deac7df80a 2024-09-12 18:30:13 +02:00
Justin M. Keyes
a2ed5f1013
Update test/functional/plugin/lsp/completion_spec.lua 2024-09-10 09:21:54 -07:00
glepnir
c4445917c3 fix(lsp): wrong startcol and avoid pum deleted
Problem:
1. wrong startcol value this will cause compl_orgi_text will match triggercharacter
then when new leader add compl_leader will include triggercharacter, then
compl_match_array will build failed.

2. wrong word generate this will include symbol like -> , it will make compl_match_array build failed

3. wrong prefix value in _convert_results.

Solution:
1. use max value of server_bounary, word_boundary
2. use vimregex keyword remove unncessary symbols.
3. use max value of server_bondar and client_boundary in
   _convert_results function.
2024-09-10 19:21:57 +08:00
2 changed files with 53 additions and 4 deletions

View File

@ -154,8 +154,13 @@ local function get_completion_word(item)
return item.label
end
elseif item.textEdit then
local word = item.textEdit.newText
return word:match('^(%S*)') or word
local word = item.textEdit.newText:gsub('%s+$', '')
if word:match('^%W') then
-- remove unnecessary symbols in label like "->w_locked" => "w_locked"
local matched_word = vim.fn.matchstr(word, '\\k\\+')
return matched_word ~= '' and matched_word or word
end
return word
elseif item.insertText and item.insertText ~= '' then
return item.insertText
end
@ -365,7 +370,8 @@ function M._convert_results(
elseif curstartbyte ~= nil and curstartbyte ~= server_start_boundary then
server_start_boundary = client_start_boundary
end
local prefix = line:sub((server_start_boundary or client_start_boundary) + 1, cursor_col)
local prefix =
line:sub(math.max(server_start_boundary or 0, client_start_boundary) + 1, cursor_col)
local matches = M._lsp_to_complete_items(result, prefix, client_id)
return matches, server_start_boundary
end
@ -461,7 +467,7 @@ local function trigger(bufnr, clients)
vim.list_extend(matches, client_matches)
end
end
local start_col = (server_start_boundary or word_boundary) + 1
local start_col = math.max(server_start_boundary or 0, word_boundary) + 1
vim.fn.complete(start_col, matches)
end)

View File

@ -218,6 +218,49 @@ describe('vim.lsp.completion: item conversion', function()
eq(expected, result)
end)
it('removes unnecessary symbols in label', function()
local items = {
{
detail = 'colnr_T',
filterText = 'w_virtcol',
insertText = '->w_virtcol',
insertTextFormat = 1,
kind = 5,
label = ' w_virtcol',
score = 0.59581798315048,
sortText = '40e77879w_virtcol',
textEdit = {
newText = '->w_virtcol',
range = {
['end'] = {
character = 0,
line = 0,
},
start = {
character = 0,
line = 0,
},
},
},
},
}
local result = complete('|', items)
result = vim.tbl_map(function(x)
return {
abbr = x.abbr,
word = x.word,
}
end, result.items)
local expected = {
{
abbr = ' w_virtcol',
word = 'w_virtcol',
},
}
eq(expected, result)
end)
it('prefers wordlike components for snippets', function()
-- There are two goals here:
--