release: WRNexusJS 0.8.0
This commit is contained in:
@@ -36,11 +36,33 @@ function send(value: unknown): void {
|
||||
function result(id: JsonRpc["id"], value: unknown): void {
|
||||
send({ jsonrpc: "2.0", id, result: value });
|
||||
}
|
||||
function internalDiagnostic(document: TextDocument, error: unknown) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 1 } },
|
||||
severity: 1,
|
||||
code: "WRN-LSP-INTERNAL",
|
||||
source: "wrnexus",
|
||||
message: `WRNexus language analysis failed safely: ${message}`,
|
||||
};
|
||||
}
|
||||
|
||||
function safeDocumentDiagnostics(document: TextDocument) {
|
||||
try {
|
||||
return documentDiagnostics(document);
|
||||
} catch (error) {
|
||||
process.stderr.write(
|
||||
`[wrnexus-lsp] diagnostics failed for ${document.uri}: ${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`,
|
||||
);
|
||||
return [internalDiagnostic(document, error)];
|
||||
}
|
||||
}
|
||||
|
||||
function publish(document: TextDocument): void {
|
||||
send({
|
||||
jsonrpc: "2.0",
|
||||
method: "textDocument/publishDiagnostics",
|
||||
params: { uri: document.uri, diagnostics: documentDiagnostics(document) },
|
||||
params: { uri: document.uri, diagnostics: safeDocumentDiagnostics(document) },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,7 +102,7 @@ async function handle(message: JsonRpc): Promise<void> {
|
||||
case "initialize":
|
||||
workspaceRoot = params.rootPath ?? rootFromUri(params.rootUri);
|
||||
result(message.id, {
|
||||
serverInfo: { name: "WRNexus Language Server", version: "0.8.0" },
|
||||
serverInfo: { name: "WRNexus Language Server", version: "0.8.3" },
|
||||
capabilities: {
|
||||
textDocumentSync: 1,
|
||||
documentFormattingProvider: true,
|
||||
@@ -195,7 +217,7 @@ async function handle(message: JsonRpc): Promise<void> {
|
||||
result(message.id, []);
|
||||
break;
|
||||
}
|
||||
const actions: any[] = documentDiagnostics(document)
|
||||
const actions: any[] = safeDocumentDiagnostics(document)
|
||||
.filter((item) => item.code === "WRNA11Y001")
|
||||
.map((item) => ({
|
||||
title: "Add empty alt attribute",
|
||||
@@ -268,11 +290,36 @@ function consume(): void {
|
||||
if (buffer.length < bodyStart + length) return;
|
||||
const body = buffer.subarray(bodyStart, bodyStart + length).toString();
|
||||
buffer = buffer.subarray(bodyStart + length);
|
||||
void handle(JSON.parse(body));
|
||||
let message: JsonRpc;
|
||||
try {
|
||||
message = JSON.parse(body) as JsonRpc;
|
||||
} catch (error) {
|
||||
process.stderr.write(
|
||||
`[wrnexus-lsp] invalid JSON-RPC payload: ${error instanceof Error ? error.message : String(error)}\n`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
void handle(message).catch((error) => {
|
||||
const detail = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
||||
process.stderr.write(`[wrnexus-lsp] request failed: ${detail}\n`);
|
||||
if (message.id !== undefined) {
|
||||
send({
|
||||
jsonrpc: "2.0",
|
||||
id: message.id,
|
||||
error: { code: -32603, message: "WRNexus language server request failed", data: detail },
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
process.stdin.on("data", (chunk) => {
|
||||
buffer = Buffer.concat([buffer, Buffer.from(chunk)]);
|
||||
consume();
|
||||
try {
|
||||
buffer = Buffer.concat([buffer, Buffer.from(chunk)]);
|
||||
consume();
|
||||
} catch (error) {
|
||||
process.stderr.write(
|
||||
`[wrnexus-lsp] input processing failed: ${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`,
|
||||
);
|
||||
}
|
||||
});
|
||||
process.stdin.resume();
|
||||
|
||||
Reference in New Issue
Block a user