mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
Compare commits
3 Commits
61c1131161
...
c452a090f1
Author | SHA1 | Date | |
---|---|---|---|
|
c452a090f1 | ||
|
a2ed5f1013 | ||
|
c4445917c3 |
@ -154,8 +154,13 @@ local function get_completion_word(item)
|
|||||||
return item.label
|
return item.label
|
||||||
end
|
end
|
||||||
elseif item.textEdit then
|
elseif item.textEdit then
|
||||||
local word = item.textEdit.newText
|
local word = item.textEdit.newText:gsub('%s+$', '')
|
||||||
return word:match('^(%S*)') or word
|
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
|
elseif item.insertText and item.insertText ~= '' then
|
||||||
return item.insertText
|
return item.insertText
|
||||||
end
|
end
|
||||||
@ -365,7 +370,8 @@ function M._convert_results(
|
|||||||
elseif curstartbyte ~= nil and curstartbyte ~= server_start_boundary then
|
elseif curstartbyte ~= nil and curstartbyte ~= server_start_boundary then
|
||||||
server_start_boundary = client_start_boundary
|
server_start_boundary = client_start_boundary
|
||||||
end
|
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)
|
local matches = M._lsp_to_complete_items(result, prefix, client_id)
|
||||||
return matches, server_start_boundary
|
return matches, server_start_boundary
|
||||||
end
|
end
|
||||||
@ -461,7 +467,7 @@ local function trigger(bufnr, clients)
|
|||||||
vim.list_extend(matches, client_matches)
|
vim.list_extend(matches, client_matches)
|
||||||
end
|
end
|
||||||
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)
|
vim.fn.complete(start_col, matches)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -218,6 +218,49 @@ describe('vim.lsp.completion: item conversion', function()
|
|||||||
eq(expected, result)
|
eq(expected, result)
|
||||||
end)
|
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()
|
it('prefers wordlike components for snippets', function()
|
||||||
-- There are two goals here:
|
-- There are two goals here:
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user