Search code examples
visual-studio-codevscode-extensionslanguage-server-protocol

Could VsCode extension get any language server's completion items?


As the title, I want to get typescript language server's completion items in my own extension. How should I do?

If there is another way except running the language server by myself?


Solution

  • You can use the vscode.executeCompletionItemProvider built-in command for this:

    const list = await vscode.commands.executeCommand('vscode.executeCompletionItemProvider',
        vscode.Uri.file('/path/to/file.ts'),
        new vscode.Position(line, character))
    

    Similar commands exist for other functionality, such as listing references.