Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tabby-agent doesn't respect the client's insertTextMode for regular textDocument/completion #3330

Open
jwortmann opened this issue Oct 26, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@jwortmann
Copy link

I want to report what I believe is a bug in tabby-agent.

tabby was started via tabby serve --model StarCoder-1B --no-webserver

For testing a LSP client integration, I enabled the regular textDocument/completion request for now. The client declares in initialze that it only supports InsertTextMode.adjustIndentation, which means that

/**
* The editor adjusts leading whitespace of new lines so that
* they match the indentation up to the cursor of the line for
* which the item is accepted.
*/

Using the following Python file

# find max element in array
def findMaxElement(arr):
    

and requesting textDocument/completion at the cursor position shown in the following screenshot, the textEdit of the completion item in the response contains extra (incorrect) indentation; see the JSON payload below.

tabby1

{
    "isIncomplete": true,
    "items": [
        {
            "label": "maxElement = arr[0]\n",
            "labelDetails": {
                "detail": "    for i in range(1, len(arr)):\n",
                "description": "Tabby"
            },
            "kind": 1,
            "documentation": {
                "kind": "markdown",
                "value": "```\n    maxElement = arr[0]\n    for i in range(1, len(arr)):\n        if arr[i] > maxElement:\n            maxElement = arr[i]\n    return maxElement\n```\n ---\nSuggested by Tabby."
            },
            "textEdit": {
                "newText": "maxElement = arr[0]\n    for i in range(1, len(arr)):\n        if arr[i] > maxElement:\n            maxElement = arr[i]\n    return maxElement",
                "range": {
                    "start": {
                        "line": 2,
                        "character": 4
                    },
                    "end": {
                        "line": 2,
                        "character": 4
                    }
                }
            },
            "data": {
                "eventId": {
                    "completionId": "cmpl-e6481dd3-5fc3-4b60-8c43-aefe5d2b8fd1",
                    "choiceIndex": 0
                }
            }
        }
    ]
}

This results in wrong indentation when the completion item gets accepted:

tabby2

The right thing to do for tabby-agent would be to remove leading indentation from the newText as if the code block (cursor position) had no initial indentation.

Note that this is only relevant for textDocument/completion but not for textDocument/inlineCompletion, because afaik indentation in inline completions should always be handled as InsertTextMode.asIs.

@icycodes
Copy link
Member

Thank you for reporting this bug and proposing the detail solution.
Indeed, the tabby-agent does not fully respect all client capabilities regarding the method textDocument/completion, including InsertMode.
I will fix it in the next tabby-agent minor release.

@wsxiaoys wsxiaoys added bug Something isn't working and removed bug-unconfirmed labels Oct 28, 2024
@icycodes icycodes self-assigned this Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants