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.