From f6329ea137730e571671ee31309ec1b7dc6ec85e Mon Sep 17 00:00:00 2001 From: Lajos Koszti Date: Fri, 11 Feb 2022 14:04:15 +0100 Subject: fix(lsp): correct prefix when filterText is present (#17051) LSP server might return an item which would replace a token to another. For example in typescript for a `jest.Mock` object `getProductsMock.` text I get the following response: ``` { commitCharacters = { ".", ",", "(" }, data = { entryNames = { "Symbol" }, file = "/foo/bar/baz.service.spec.ts", line = 268, offset = 17 }, filterText = ".Symbol", kind = 6, label = "Symbol", sortText = "11", textEdit = { newText = "[Symbol]", range = { end = { character = 16, line = 267 }, start = { character = 15, line = 267 } } } }, ``` In `lsp.omnifunc` to get a `prefix` we call the `adjust_start_col` which then returns the `textEdit.range.start.character`. Th `prefix` then be the `.` character. Then when filter the items with `remove_unmatch_completion_items`, every item will be filtered out, since no completion word starts `.`. To fix we return the `end.character`, which in that particular case will be the position after the `.`. --- runtime/lua/vim/lsp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 37e222a5ce..8d11b4621c 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -1598,7 +1598,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 - 1 then + if item.filterText == nil and item.textEdit and item.textEdit.range.start.line == lnum - 1 then if min_start_char and min_start_char ~= item.textEdit.range.start.character then return nil end -- cgit