语言服务器 onCompletion 只听字母 [a-z],如何启用句点 (.)

language server onCompletion is only listening to letters [a-z], how do I enable a period (.)

存储库 https://github.com/microsoft/vscode-extension-samples/tree/master/lsp-sample 中的 lsp-sample 展示了如何实现 onCompletion

服务器只听字母 [a-z] 而不是句点 (.) 我已经看到这是用 triggerCharacters 控制的,但我不清楚在哪里设置这些。 这似乎合乎逻辑,这需要在客户端部分完成,但似乎我只能注册另一个 onCompletion 处理程序。 有人能解释一下吗?

这是服务器端代码:

// 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
            }
        ];
    }
);

触发字符在 Initialize 响应的 ServerCapabilities 中指定:

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

另请参阅:Completion RequestCompletionOptions