4

The lsp-sample in repository https://github.com/microsoft/vscode-extension-samples/tree/master/lsp-sample shows how to implement onCompletion

the server only listens to letters [a-z] and not to a period (.) I have seen that this is controlled with triggerCharacters, but it is not clear to me where to set these. It seems logical that this needs to be done in the client part, but it seems I can only register another onCompletion handler. Can anybody shed some light?

This is the server side code:

// This handler provides the initial list of the completion items.
connection.onCompletion(
    (_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
        // The pass parameter contains the position of the text document in
        // which code complete got requested. For the example we ignore this
        // info and always provide the same completion items.
        return [
            {
                label: 'TypeScript',
                kind: CompletionItemKind.Text,
                data: 1
            },
            {
                label: 'JavaScript',
                kind: CompletionItemKind.Text,
                data: 2
            }
        ];
    }
);

1 Answer 1

7

The trigger characters are specified in the ServerCapabilities of the Initialize response:

connection.onInitialize((params: InitializeParams) => {
    // ...
    return {
        capabilities: {
            // ...
            completionProvider: {
                triggerCharacters: ["."]
            }
        }
    };
});

See also: CompletionOptions of the Completion Request.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.