在LSP中徘徊时,如何在光标下方获取单词?
我正在为编程语言制作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.
Now i want to port this to LSP but i can't find getWordRangeAtPosition
function equivalent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论