Skip to content

completion returns wrong and according to the spec invalid results #2762

Closed
@max397574

Description

@max397574

How are you using the lua-language-server?

NeoVim

Which OS are you using?

MacOS

What is the issue affecting?

Completion

Expected Behaviour

Get back a completion item which does nothing which is explicitly forbidden in the spec and actually is correct

Actual Behaviour

Returns a completion item with a textEdit which makes no sense and additionalTextEdits which wouldn't even be allowed by the spec

Reproduction steps

I completed with the following context (notice that the cursor position uses different based indexing because neovim being like it is)

local entry_context = {
    bufnr = 1,
    cursor = { col = 35, row = 1 },
    line = "    completion_item.textEdit.range.",
    line_before_cursor = "    completion_item.textEdit.range.",
    previous = nil,
    reason = 1,
}

I get back an entry like this

local completion_item = {
    additionalTextEdits = {
        {
            newText = "",
            range = {
                ["end"] = { character = 35, line = 69 },
                start = { character = 34, line = 69 },
            },
        },
    },
    data = { id = 119, uri = "not relevant" },
    detail = "lsp.Position",
    documentation = { kind = "markdown", value = "not relevant" },
    insertTextFormat = 2,
    kind = 5,
    label = '"end"',
    sortText = "0001",
    textEdit = {
        newText = '["end"]',
        range = {
            ["end"] = { character = 35, line = 69 },
            start = { character = 4, line = 71 },
        },
    },
}

Additional Notes

I have no idea why the text edit would modify 3 different lines when just a single statement would have to be inserted.
About additionalTextEdits from the lsp specification:

/**
* An optional array of additional text edits that are applied when
* selecting this completion. Edits must not overlap (including the same
* insert position) with the main edit nor with themselves.
*
* Additional text edits should be used to change text unrelated to the
* current cursor position (for example adding an import statement at the
* top of the file if the completion item will insert an unqualified type).
*/

In this case the additionalTextEdit overlaps with the edit and also doesn't what's it intended for (2nd paragraph)

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions