diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua index d905337abb..60574a94cd 100644 --- a/runtime/lua/vim/lsp/completion.lua +++ b/runtime/lua/vim/lsp/completion.lua @@ -370,7 +370,7 @@ 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.start.line == lnum then + 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 end diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index 7772a47589..af4e7d401e 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -618,24 +618,53 @@ describe('vim.lsp.completion: item conversion', function() }, }, }, + { + label = 'insert_replace_edit', + kind = 9, + textEdit = { + newText = 'foobar', + insert = { + start = { line = 0, character = 7 }, + ['end'] = { line = 0, character = 11 }, + }, + replace = { + start = { line = 0, character = 0 }, + ['end'] = { line = 0, character = 0 }, + }, + }, + }, }, } local expected = { - abbr = ' this_thread', - dup = 1, - empty = 1, - icase = 1, - info = '', - kind = 'Module', - menu = '', - abbr_hlgroup = '', - word = 'this_thread', + { + abbr = ' this_thread', + dup = 1, + empty = 1, + icase = 1, + info = '', + kind = 'Module', + menu = '', + abbr_hlgroup = '', + word = 'this_thread', + }, + { + abbr = 'insert_replace_edit', + dup = 1, + empty = 1, + icase = 1, + info = '', + kind = 'Module', + menu = '', + abbr_hlgroup = '', + word = 'foobar', + }, } local result = complete(' std::this|', completion_list) eq(7, result.server_start_boundary) - local item = result.items[1] - item.user_data = nil - eq(expected, item) + for _, item in ipairs(result.items) do + item.user_data = nil + end + eq(expected, result.items) end) it('should search from start boundary to cursor position', function()