visual studio language extension, how do I call my own functions?

丶灬走出姿态 提交于 2020-01-02 19:29:47

问题


I've implemented my own language server (based on the lsp-sample in the visual studio sample extensions git tree). It does basic language parsing ..etc.

I would like to provide some simple functions in the client side of my extension, that need access to data that is already parsed in the server portion of my extension.

how do I add my own calls to the client/server so I can ask my server for stuff ?

I'm looking to send commands/calls from the client side, to the server side and get an answer back.

I looked around and there is a LanguageClient.registerFeature() is that part of the answer ?

Any help would be greatly appreciated. Especially with sample code.

cdturner


回答1:


You can use the generic sendRequest() / onRequest() with custom method names for this. A simple example based on the lsp-sample could look like this:

(in activate() of client/src/extension.ts)

client.onReady().then(() => {
    client.sendRequest("custom/data", "foo").then(data => console.log(data));
});

(in the onInitialized callback of server/src/server.ts)

connection.onRequest("custom/data", param => "received parameter '" + param + "'");

With those changes, the following output can be observed in the dev console:


Communication in the opposite direction looks very similar - see here for an example of sending a custom notification from the server to the client.



来源:https://stackoverflow.com/questions/51806347/visual-studio-language-extension-how-do-i-call-my-own-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!