feat(language-server): merge HTML completions and hover into one response

This commit is contained in:
2026-08-18 20:56:17 +05:30
parent d77638131b
commit 97801287f9
5 changed files with 22543 additions and 14 deletions
+14 -4
View File
@@ -19,6 +19,8 @@ import {
htmlToWrn,
type TextDocument,
} from "./index.ts";
import { htmlCompletions, htmlHover, mergeCompletions } from "./html-service.ts";
import { clearHtmlRegionCache } from "./html-regions.ts";
type JsonRpc = { jsonrpc?: string; id?: number | string; method?: string; params?: any };
const documents = new Map<string, TextDocument>();
@@ -111,7 +113,9 @@ async function handle(message: JsonRpc): Promise<void> {
capabilities: {
textDocumentSync: { openClose: true, change: 1, save: true },
documentFormattingProvider: true,
completionProvider: { triggerCharacters: ["<", "@", ":", "."] },
completionProvider: {
triggerCharacters: ["<", "@", ":", ".", " ", "=", '"', "/"],
},
hoverProvider: true,
definitionProvider: true,
referencesProvider: true,
@@ -172,6 +176,7 @@ async function handle(message: JsonRpc): Promise<void> {
case "textDocument/didClose":
clearDiagnosticTimer(params.textDocument.uri);
documents.delete(params.textDocument.uri);
clearHtmlRegionCache(params.textDocument.uri);
send({
jsonrpc: "2.0",
method: "textDocument/publishDiagnostics",
@@ -195,9 +200,13 @@ async function handle(message: JsonRpc): Promise<void> {
);
break;
}
case "textDocument/completion":
result(message.id, [...completionItems(), ...workspaceCompletionItems(workspaceRoot)]);
case "textDocument/completion": {
const document = documents.get(params.textDocument.uri);
const wrnexus = [...completionItems(), ...workspaceCompletionItems(workspaceRoot)];
const html = document ? htmlCompletions(document, params.position) : [];
result(message.id, html.length ? mergeCompletions(wrnexus, html) : wrnexus);
break;
}
case "textDocument/documentSymbol": {
const document = documents.get(params.textDocument.uri);
result(message.id, document ? documentSymbols(document) : []);
@@ -210,7 +219,8 @@ async function handle(message: JsonRpc): Promise<void> {
}
case "textDocument/hover": {
const document = documents.get(params.textDocument.uri);
result(message.id, document ? hover(document, params.position) : null);
const html = document ? htmlHover(document, params.position) : null;
result(message.id, html ?? (document ? hover(document, params.position) : null));
break;
}
case "textDocument/definition": {