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 `.`.
This commit is contained in:
Lajos Koszti 2022-02-11 14:04:15 +01:00 committed by GitHub
parent b981c231e2
commit f6329ea137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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