英文:
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?
英文:
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?
答案1
得分: 1
一般来说,不能从其他扩展程序中使用语言服务器,因为每个扩展程序都在独立的环境中运行,所以它对您不可用。
但是有一些方法,扩展程序可以_公开_它们自己的API,您的扩展程序可以依赖于它。这将取决于API是否公开了您从其语言服务器中所需的内容。或者,根据您从其语言服务器中所需的内容,您可以使用VS Code的API。例如,如果您想知道文件中的符号(方法、类等),您可以调用commands.executeCommand('vscode.executeDocumentSymbolProvider', ...
。
否则,是的,您应该将语言服务器捆绑到您的扩展程序中。
希望这对您有所帮助。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论