feat(language-server): understand the api binding attribute

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-20 16:49:06 +05:30
co-authored by Claude Opus 5
parent cd0dffa87d
commit 29febb2e0c
4 changed files with 187 additions and 3 deletions
+24 -2
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env node
// WRN editor language server source hash: 70d2454817cc3aa546304c880e0a82313bb73b50051556bf7febd12e6a46c78c
// WRN editor language server source hash: 2e1803dd46a175316931c0390c5af90dc35a5cd2299798014cbe46b075fee15d
// WRN editor language server generator hash: f593a44aaf05495b789ce7a3086bee1eebb951b884d41c0e017bbcfe5f547e72
// @bun @bun-cjs
(function(exports, require, module, __filename, __dirname) {var __create = Object.create;
@@ -196009,6 +196009,9 @@ function getLanguageService(options = defaultLanguageServiceOptions) {
findLinkedEditingRanges
};
}
function newHTMLDataProvider(id, customData) {
return new HTMLDataProvider(id, customData);
}
// packages/language-server/src/html-regions.ts
function viewRegions(text) {
@@ -196098,7 +196101,13 @@ var semanticTokensLegend2 = {
};
// packages/language-server/src/html-service.ts
var service = getLanguageService();
var wrnexusDataProvider = newHTMLDataProvider("wrnexus", {
version: 1,
globalAttributes: [
{ name: "api", description: "Binds this element to a declared `apis { }` entry." }
]
});
var service = getLanguageService({ customDataProviders: [wrnexusDataProvider] });
function htmlDocument(document) {
const virtual = virtualHtmlDocument(document);
return TextDocument2.create(virtual.uri, "html", document.version ?? 1, virtual.text);
@@ -196111,9 +196120,18 @@ function markdown(value) {
}
return;
}
function isApiAttributeValuePosition(document, position) {
const offset = offsetAt2(document.text, position);
if (!isInsideHtml(document, offset))
return false;
const before = document.text.slice(0, offset);
return /\bapi\s*=\s*(["'])(?:(?!\1)[^\n])*$/.test(before);
}
function htmlCompletions(document, position) {
if (!isInsideHtml(document, offsetAt2(document.text, position)))
return [];
if (isApiAttributeValuePosition(document, position))
return [];
const virtual = htmlDocument(document);
const parsed = service.parseHTMLDocument(virtual);
const list = service.doComplete(virtual, position, parsed);
@@ -196419,6 +196437,10 @@ async function handle(message) {
result(message.id, apiCallCompletions(document.text));
break;
}
if (document && isApiAttributeValuePosition(document, params.position)) {
result(message.id, apiCallCompletions(document.text));
break;
}
const wrnexus = [...completionItems(), ...workspaceCompletionItems(workspaceRoot)];
const html = document ? htmlCompletions(document, params.position) : [];
result(message.id, html.length ? mergeCompletions(wrnexus, html) : wrnexus);