vscode-extensionspython-language-server

Use existing language server from VS Code extension


I am writing a VS Code extension that will use functionality provided by a language server.

Am I required to bundle the language server into my extension?

Is there any way to use language servers already installed in my user's VS Code environment? For example, if my users have the Pyright extension installed, could I connect to it somehow?


Solution

  • Generally speaking no, you can't use the language server from other extension, because each extension runs isolated from each other, so it wouldn't be available to you.

    But there are some ways, as extensions can expose their own API, and your extension could rely on it. It would be a matter of the API exposes what you need from their language server. Or, depending on what you need from their language server, you could use VS Code APIs. For instance, if you would like to know the symbols (methods, classes, etc) from a file, you could call commands.executeCommand('vscode.executeDocumentSymbolProvider',....

    Otherwise yes, you should bundle the language server on your extension.

    Hope this helps