Why aren't my custom language server VS Code extension's completions showing?

62 views Asked by At

I have a language server for a custom language I'm making, and I launch it via an vscode-languageclient extension. The language server initializes with these capabilities

{
    "capabilities": {
        "completionProvider": {
            "completionItem": {
                "labelDetailsSupport": false
            },
            "resolveProvider": false,
            "triggerCharacters": [
                "{"
            ]
        },
        "declarationProvider": true,
        "referencesProvider": true,
        "renameProvider": {
            "prepareProvider": true,
            "workDoneProgress": false
        },
        "semanticTokensProvider": {
            "legend": {
                "tokenModifiers": [
                    "declaration"
                ],
                "tokenTypes": [
                    "variable",
                    "type",
                    "operator",
                    "function",
                    "modifier",
                    "variable",
                    "comment",
                    "number",
                    "string",
                    "keyword"
                ]
            },
            "range": true
        },
        "textDocumentSync": {
            "change": 2,
            "openClose": true,
            "save": {
                "includeText": false
            }
        }
    }
}

You'll notice that the completion trigger character for my LSP is a { character.

Let's say I have a file like this

...
23 {
24     Title: ViewBox[0]^^|,
25     Subtitle: ViewBox[1]__|,
26     ArrayDescription: Size[0]__..,
27 }[]
28 
29 ArraySubtext: Paragraph(
30     value: "An `Array` is a fixed-size list of items of a certain type Title"
31 )
...

And I added the completion character

23 {
24     Title: ViewBox[0]^^|,
25     Subtitle: ViewBox[1]__|,
26     ArrayDescription: Size[0]__..,
27 }[]
28 
29 {}
30 
31 ArraySubtext: Paragraph(
32     value: "An `Array` is a fixed-size list of items of a certain type Title"
33 )

VSCode recognizes this completion character

[Trace - 2:05:49 PM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "uri": "file:///home/codeserver/test/test.grz",
        "version": 4
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 28,
                    "character": 0
                },
                "end": {
                    "line": 28,
                    "character": 0
                }
            },
            "rangeLength": 0,
            "text": "{}"
        }
    ]
}


[Trace - 2:05:49 PM] Sending request 'textDocument/completion - (14)'.
Params: {
    "textDocument": {
        "uri": "file:///home/codeserver/test/test.grz"
    },
    "position": {
        "line": 28,
        "character": 1
    },
    "context": {
        "triggerKind": 2,
        "triggerCharacter": "{"
    }
}

And my LSP sends back the completion

[Trace - 2:05:49 PM] Received response 'textDocument/completion - (14)' in 1ms.
Result: [
    {
        "kind": 15,
        "label": "Continue Slide",
        "textEdit": {
            "newText": "{\n    ArrayDescription: Size[0],\n}[]",
            "range": {
                "end": {
                    "character": 2,
                    "line": 28
                },
                "start": {
                    "character": 0,
                    "line": 28
                }
            }
        }
    },
    {
        "kind": 15,
        "label": "New Slide",
        "textEdit": {
            "newText": "{}[]",
            "range": {
                "end": {
                    "character": 2,
                    "line": 28
                },
                "start": {
                    "character": 0,
                    "line": 28
                }
            }
        }
    }
]

But for whatever reason, VSCode does not show any completion dialog

I've tried adding the data parameter to each CompletionItem (just a null), and I've tried checking if the textEdit is valid (it is, and it works in another LSP based text-editor, helix). I'd love to know what I'm doing wrong here, or if there's something I need to add to my VS Code extension.

Manually triggering suggestions with Ctrl+Space shows it, but only if the cursor isn't surrounded by the brackets. Strange behaviour.

0

There are 0 answers