Reputation: 5396
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
}
];
}
);
Upvotes: 4
Views: 959
Reputation: 34148
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.
Upvotes: 7