在LSP中徘徊时,如何在光标下方获取单词?

发布于 2025-01-23 21:50:57 字数 976 浏览 4 评论 0原文

我正在为编程语言制作VSCODE扩展。起初,我使用扩展API进行了所有工作。现在我想切换LSP。我实施的功能是显示了悬停在内置功能的定义。

这是代码:

vscode.languages.registerHoverProvider("lc", {
        provideHover(document, position) {
            const word = document.getText(
                document.getWordRangeAtPosition(position, /\b\w+(?=\(.*\))/)
            );
            if (builtin_funcs[word] != undefined) {
                return new vscode.Hover(
                    new vscode.MarkdownString(`${builtin_funcs[word]}`)
                );
            } else {
                return null;
            }
        },
    });

我使用getWordRangeAtposition使用Regex /\ b \ w+(?= \(。*\))/来匹配函数。获取功能名称后,我在indentin_funcs数组中搜索了它,然后返回了定义。

,我想将其移植到LSP,但是我找不到getWordRangeatPosition函数等效。

I am making a vscode extension for a programming language. At first i was doing all of the work using the extension api. Now i want to switch LSP. The feature I had implemented was that show the definition of builtin functions on hover.

This was the code:

vscode.languages.registerHoverProvider("lc", {
        provideHover(document, position) {
            const word = document.getText(
                document.getWordRangeAtPosition(position, /\b\w+(?=\(.*\))/)
            );
            if (builtin_funcs[word] != undefined) {
                return new vscode.Hover(
                    new vscode.MarkdownString(`${builtin_funcs[word]}`)
                );
            } else {
                return null;
            }
        },
    });

i was using the getWordRangeAtPosition function with the regex /\b\w+(?=\(.*\))/ to match functions. After getting the function name i searched it in the builtin_funcs array and returned the definition.
function definition when hovering

Now i want to port this to LSP but i can't find getWordRangeAtPosition function equivalent.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文