Visual Studio 语言扩展,如何调用自己的函数? [英] visual studio language extension, how do I call my own functions?

查看:33
本文介绍了Visual Studio 语言扩展,如何调用自己的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了我自己的语言服务器(基于 Visual Studio 示例扩展 git 树中的 lsp-sample).它进行基本的语言解析..等

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.

我环顾四周,有一个 LanguageClient.registerFeature() 是答案的一部分吗?

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

推荐答案

您可以使用具有自定义方法名称的通用 sendRequest()/onRequest() 来实现此目的.基于 lsp-sample 的简单示例可能如下所示:

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:

(在client/src/extension.tsactivate()中)

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

(在server/src/server.tsonInitialized回调中)

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.

这篇关于Visual Studio 语言扩展,如何调用自己的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆