fix(lsp): enable insertReplaceSupport for use in adjust_start_col #36569

Problem:
With the typescript LSes typescript-language-server and vtsls,
omnicompletion on partial tokens for certain types, such as array
methods, and functions that are attached as attributes to other
functions, either results in no entries populated in the completion menu
(typescript-language-server), or an unfiltered completion menu with all
array methods included, even if they don't share the same prefix as the
partial token being completed (vtsls).

Solution:
Enable insertReplaceSupport and uses the insert portion of the lsp
completion response in adjust_start_col if it's included in the
response.

Completion results are still filtered client side.
This commit is contained in:
Jeff Martin
2025-11-18 23:03:40 -08:00
committed by GitHub
parent b65aadc03e
commit ff792f8e69
3 changed files with 60 additions and 35 deletions

View File

@@ -301,7 +301,7 @@ function M._lsp_to_complete_items(result, prefix, client_id)
return match_item_by_value(item.filterText, prefix)
end
if item.textEdit then
if item.textEdit and not item.textEdit.newText then
-- server took care of filtering
return true
end
@@ -370,11 +370,18 @@ end
local function adjust_start_col(lnum, line, items, encoding)
local min_start_char = nil
for _, item in pairs(items) do
if item.textEdit and item.textEdit.range and item.textEdit.range.start.line == lnum then
if min_start_char and min_start_char ~= item.textEdit.range.start.character then
return nil
if item.textEdit then
if item.textEdit.range and item.textEdit.range.start.line == lnum then
if min_start_char and min_start_char ~= item.textEdit.range.start.character then
return nil
end
min_start_char = item.textEdit.range.start.character
elseif item.textEdit.insert and item.textEdit.insert.start.line == lnum then
if min_start_char and min_start_char ~= item.textEdit.insert.start.character then
return nil
end
min_start_char = item.textEdit.insert.start.character
end
min_start_char = item.textEdit.range.start.character
end
end
if min_start_char then