fix(language-server): gate api hover to actual api.<name> references
Hover fired on whatever word was under the cursor, so a local variable colliding with a declared block name reported the block's method and path instead of its own hover info. Completion was already gated this way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -103,6 +103,18 @@ function isApiCallPosition(text: string, offset: number): boolean {
|
||||
return /\bapi\.\w*$/.test(before);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the identifier containing `offset` is the `<name>` of an `api.<name>`
|
||||
* reference. Hover fires on whatever word is under the cursor, so without this a local
|
||||
* variable that merely collides with a block name would report the block's method and
|
||||
* path instead of its own hover info.
|
||||
*/
|
||||
export function isApiReferenceAt(text: string, offset: number): boolean {
|
||||
let start = offset;
|
||||
while (start > 0 && /\w/.test(text[start - 1]!)) start--;
|
||||
return /\bapi\.$/.test(text.slice(0, start));
|
||||
}
|
||||
|
||||
type JsonRpc = { jsonrpc?: string; id?: number | string; method?: string; params?: any };
|
||||
const documents = new Map<string, TextDocument>();
|
||||
const diagnosticTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
||||
@@ -311,7 +323,10 @@ async function handle(message: JsonRpc): Promise<void> {
|
||||
case "textDocument/hover": {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
const word = document ? wordAt(document.text, params.position)?.word : undefined;
|
||||
const apiHover = word ? apiCallHover(document!.text, word) : undefined;
|
||||
const apiHover =
|
||||
word && isApiReferenceAt(document!.text, offsetAt(document!.text, params.position))
|
||||
? apiCallHover(document!.text, word)
|
||||
: undefined;
|
||||
if (apiHover) {
|
||||
result(message.id, { contents: apiHover });
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user