语言服务器 onCompletion 仅监听字母 [az],如何启用句点 (.)

Coe*_*oen 4 visual-studio-code vscode-extensions language-server-protocol

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

服务器只听字母 [az] 而不是句点 (.) 我已经看到这是用 控制的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
            }
        ];
    }
);
Run Code Online (Sandbox Code Playgroud)

Gam*_*a11 7

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

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

另请参阅:CompletionOptions完成请求