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:
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { apiCallCompletions, apiCallHover } from "../src/server.ts";
|
||||
import { apiCallCompletions, apiCallHover, isApiReferenceAt } from "../src/server.ts";
|
||||
|
||||
const SOURCE = `page Search {
|
||||
apis {
|
||||
@@ -71,3 +71,32 @@ test("an ssr {} data block, which the parser now rejects with a ParseError, stil
|
||||
expect(() => apiCallCompletions(legacy)).not.toThrow();
|
||||
expect(apiCallCompletions(legacy)).toEqual([]);
|
||||
});
|
||||
|
||||
test("a bare identifier that merely collides with a block name is not an api reference", () => {
|
||||
// `searchUsers` here is a local variable, not `api.searchUsers` -- hovering it must
|
||||
// not report the API block's method and path.
|
||||
const source = `page Search {
|
||||
apis {
|
||||
searchUsers POST /api/users {
|
||||
response { return data.users }
|
||||
}
|
||||
}
|
||||
|
||||
functions {
|
||||
client function go() {
|
||||
const searchUsers = 1
|
||||
void api.searchUsers({ name: "x" })
|
||||
return searchUsers
|
||||
}
|
||||
}
|
||||
|
||||
view { <main>x</main> }
|
||||
}
|
||||
`;
|
||||
const collision = source.indexOf("const searchUsers") + "const ".length;
|
||||
const reference = source.indexOf("searchUsers POST");
|
||||
|
||||
expect(isApiReferenceAt(source, collision)).toBe(false);
|
||||
expect(isApiReferenceAt(source, source.indexOf("api.searchUsers") + 4)).toBe(true);
|
||||
expect(reference).toBeGreaterThan(-1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user