Preserve structured diagnostics, source attribution, phase outcomes and revision context through compiler, Studio, LSP, MCP and JavaFX. Add project service discovery and resilient VS Code reconnection. Correct all eight reproduced PBS production failures in expression context, sibling executable bindings and nominal owner identity. Consolidate specs, lessons, immutable baseline evidence and the maintained source-to-guest qualification runner. Validation: required Gradle gate recorded 724 tests, with 711 passed and 13 skipped. Full corpus passed 168 compilation observations and 108 guest runs (104 successes and four deliberate faults); supplemental controls passed 42 compilations and 16 guest runs. TypeScript compilation, two Node discovery tests and discussion validation passed.
482 lines
20 KiB
JavaScript
482 lines
20 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.activate = activate;
|
|
exports.deactivate = deactivate;
|
|
const node_fs_1 = require("node:fs");
|
|
const discovery_1 = require("./discovery");
|
|
const net = __importStar(require("node:net"));
|
|
const vscode = __importStar(require("vscode"));
|
|
const externalSources_1 = require("./externalSources");
|
|
const node_1 = require("vscode-languageclient/node");
|
|
let client;
|
|
let output;
|
|
let reconnectTimer;
|
|
let reconnectContext;
|
|
let stoppingClient = false;
|
|
let lastAppliedThemeSignature;
|
|
const externalSources = new externalSources_1.ExternalSources();
|
|
let reconnectAttempt = 0;
|
|
let connectionStatus;
|
|
let lastStatus = "";
|
|
let startPromise;
|
|
let restartQueue = Promise.resolve();
|
|
let disposed = false;
|
|
let endpointKey;
|
|
let endpointSession;
|
|
function status(message) {
|
|
connectionStatus.text = `$(plug) Prometeu: ${message}`;
|
|
connectionStatus.tooltip = message;
|
|
connectionStatus.show();
|
|
if (message !== lastStatus) {
|
|
output.appendLine(message);
|
|
lastStatus = message;
|
|
}
|
|
}
|
|
function restart(context) {
|
|
restartQueue = restartQueue.then(async () => {
|
|
await stopClient();
|
|
reconnectAttempt = 0;
|
|
if (!disposed)
|
|
await startClient(context);
|
|
}).catch(error => { status(String(error)); scheduleReconnect(); });
|
|
return restartQueue;
|
|
}
|
|
// The reconnect controller owns availability feedback; avoid languageclient's
|
|
// forced error notifications for expected offline/obsolete discovery endpoints.
|
|
class StudioLanguageClient extends node_1.LanguageClient {
|
|
async stop(timeout) {
|
|
// languageclient 9 invokes stop before its failed initialize has left
|
|
// Starting. Wait for that start to settle before disposing the transport.
|
|
if (this.state === node_1.State.Starting)
|
|
await this.start().catch(() => undefined);
|
|
await super.stop(timeout);
|
|
}
|
|
error(message, _data, _showNotification) {
|
|
status(`Studio unavailable: ${message}`);
|
|
}
|
|
}
|
|
const VSCODE_HOST_ID = "vscode";
|
|
function activate(context) {
|
|
disposed = false;
|
|
reconnectContext = context;
|
|
connectionStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
|
connectionStatus.command = "prometeu.restartStudioLsp";
|
|
const watcher = vscode.workspace.createFileSystemWatcher("**/.studio/lsp.json");
|
|
const changed = () => { void restart(context); };
|
|
context.subscriptions.push(connectionStatus, watcher, watcher.onDidCreate(changed), watcher.onDidChange(changed), watcher.onDidDelete(changed), vscode.workspace.onDidChangeWorkspaceFolders(changed), vscode.workspace.onDidChangeConfiguration(event => {
|
|
if (event.affectsConfiguration("prometeu.studio"))
|
|
changed();
|
|
}));
|
|
output = vscode.window.createOutputChannel("Prometeu LSP");
|
|
output.appendLine("Prometeu VS Code extension activated.");
|
|
context.subscriptions.push(externalSources, vscode.languages.registerCodeLensProvider({ scheme: externalSources_1.externalScheme, language: "pbs" }, {
|
|
provideCodeLenses: document => externalSources.originLenses(document)
|
|
}), vscode.commands.registerCommand("prometeu.openAnimationOrigin", async (uri, byteOffset) => {
|
|
try {
|
|
await externalSources.openAnimationOrigin(uri, byteOffset);
|
|
}
|
|
catch (error) {
|
|
void vscode.window.showErrorMessage(String(error));
|
|
}
|
|
}), vscode.workspace.registerTextDocumentContentProvider(externalSources_1.externalScheme, externalSources), vscode.window.onDidChangeActiveTextEditor(() => externalSources.refreshStatus()), vscode.workspace.onDidOpenTextDocument(document => void externalSources.opened(document)), vscode.workspace.onDidCloseTextDocument(document => void externalSources.closeDocument(document)));
|
|
const connectCommand = vscode.commands.registerCommand("prometeu.connectStudioLsp", async () => {
|
|
reconnectAttempt = 0;
|
|
await startClient(context);
|
|
});
|
|
const restartCommand = vscode.commands.registerCommand("prometeu.restartStudioLsp", async () => {
|
|
await restart(context);
|
|
});
|
|
context.subscriptions.push(output, connectCommand, restartCommand);
|
|
void startClient(context);
|
|
}
|
|
async function deactivate() {
|
|
disposed = true;
|
|
reconnectContext = undefined;
|
|
clearReconnectTimer();
|
|
await restartQueue;
|
|
try {
|
|
await externalSources.shutdown();
|
|
}
|
|
finally {
|
|
await stopClient();
|
|
}
|
|
}
|
|
async function startClient(context) {
|
|
if (disposed)
|
|
return;
|
|
if (startPromise)
|
|
return startPromise;
|
|
startPromise = startClientOnce(context).finally(() => { startPromise = undefined; });
|
|
return startPromise;
|
|
}
|
|
async function startClientOnce(context) {
|
|
clearReconnectTimer();
|
|
if (client) {
|
|
output.appendLine("Prometeu LSP client is already running.");
|
|
return;
|
|
}
|
|
const folders = vscode.workspace.workspaceFolders;
|
|
if (!folders || folders.length !== 1 || folders[0].uri.scheme !== "file") {
|
|
status("Open one local Prometeu project folder.");
|
|
return;
|
|
}
|
|
const folder = folders[0];
|
|
const config = vscode.workspace.getConfiguration("prometeu.studio", folder.uri);
|
|
let host;
|
|
let port;
|
|
let root;
|
|
let session;
|
|
try {
|
|
root = (0, node_fs_1.realpathSync)(folder.uri.fsPath);
|
|
if (config.get("connectionMode", "auto") === "manual") {
|
|
host = config.get("host", "127.0.0.1");
|
|
port = config.get("port", 7775);
|
|
}
|
|
else {
|
|
const endpoint = (0, discovery_1.readEndpoint)(root);
|
|
if (!endpoint) {
|
|
status("Waiting for Studio — open this project in Studio.");
|
|
scheduleReconnect();
|
|
return;
|
|
}
|
|
({ host, port } = endpoint);
|
|
session = endpoint.sessionId;
|
|
}
|
|
}
|
|
catch (error) {
|
|
status(error instanceof Error ? error.message : String(error));
|
|
scheduleReconnect();
|
|
return;
|
|
}
|
|
const key = `${root}:${host}:${port}`;
|
|
if (endpointKey !== key || (session !== undefined && endpointSession !== session)) {
|
|
externalSources.resetSession();
|
|
}
|
|
endpointKey = key;
|
|
if (session !== undefined)
|
|
endpointSession = session;
|
|
status(`Connecting to ${host}:${port}`);
|
|
const serverOptions = async () => {
|
|
return new Promise((resolve, reject) => {
|
|
const socket = net.createConnection({ host, port });
|
|
let settled = false;
|
|
const connectTimeout = setTimeout(() => {
|
|
if (settled) {
|
|
return;
|
|
}
|
|
settled = true;
|
|
socket.destroy();
|
|
reject(new Error("Connection timed out."));
|
|
}, 3000);
|
|
socket.once("connect", () => {
|
|
if (settled) {
|
|
return;
|
|
}
|
|
settled = true;
|
|
clearTimeout(connectTimeout);
|
|
output.appendLine("TCP connection established with Prometeu Studio.");
|
|
resolve({
|
|
reader: socket,
|
|
writer: socket
|
|
});
|
|
});
|
|
socket.once("error", (error) => {
|
|
if (settled) {
|
|
return;
|
|
}
|
|
settled = true;
|
|
clearTimeout(connectTimeout);
|
|
reject(error);
|
|
});
|
|
});
|
|
};
|
|
const clientOptions = {
|
|
workspaceFolder: { ...folder, uri: vscode.Uri.file(root) },
|
|
documentSelector: [
|
|
{
|
|
scheme: "file",
|
|
language: "pbs"
|
|
}, { scheme: externalSources_1.externalScheme, language: "pbs" }
|
|
],
|
|
synchronize: {
|
|
fileEvents: [
|
|
vscode.workspace.createFileSystemWatcher("**/*.pbs")
|
|
]
|
|
},
|
|
initializationOptions: {
|
|
...externalSources.initializationOptions,
|
|
clientKind: "vscode",
|
|
prometeuClientVersion: context.extension.packageJSON.version
|
|
},
|
|
outputChannel: output,
|
|
revealOutputChannelOn: node_1.RevealOutputChannelOn.Never,
|
|
initializationFailedHandler: () => false,
|
|
middleware: {
|
|
prepareRename: (document, position, token, next) => document.uri.scheme === externalSources_1.externalScheme ? null : next(document, position, token),
|
|
provideRenameEdits: (document, position, name, token, next) => document.uri.scheme === externalSources_1.externalScheme ? null : next(document, position, name, token),
|
|
provideDocumentFormattingEdits: (document, options, token, next) => document.uri.scheme === externalSources_1.externalScheme ? [] : next(document, options, token),
|
|
provideCodeActions: (document, range, context, token, next) => document.uri.scheme === externalSources_1.externalScheme ? [] : next(document, range, context, token),
|
|
provideHover: (document, position, token, next) => externalSources.canQuery(document) ? next(document, position, token) : null,
|
|
provideDefinition: (document, position, token, next) => externalSources.canQuery(document) ? next(document, position, token) : null,
|
|
provideDocumentSemanticTokens: (document, token, next) => externalSources.canQuery(document) ? next(document, token) : null
|
|
},
|
|
errorHandler: {
|
|
error: (error) => {
|
|
output.appendLine(`Prometeu LSP transport error: ${error.message}`);
|
|
return { action: node_1.ErrorAction.Continue };
|
|
},
|
|
closed: () => {
|
|
status("Waiting for Studio — connection closed.");
|
|
return { action: node_1.CloseAction.DoNotRestart, handled: true };
|
|
}
|
|
}
|
|
};
|
|
const nextClient = new StudioLanguageClient("prometeuStudioLsp", "Prometeu Studio LSP", serverOptions, clientOptions);
|
|
client = nextClient;
|
|
nextClient.registerFeature({
|
|
fillClientCapabilities(capabilities) {
|
|
capabilities.experimental = { ...capabilities.experimental, prometeuExternalSources: true };
|
|
},
|
|
initialize() { }, clear() { }, getState() { return { kind: "static" }; }
|
|
});
|
|
nextClient.onDidChangeState((event) => {
|
|
if (event.newState !== node_1.State.Stopped) {
|
|
return;
|
|
}
|
|
externalSources.disconnected();
|
|
if (client === nextClient) {
|
|
client = undefined;
|
|
}
|
|
if (!stoppingClient) {
|
|
scheduleReconnect();
|
|
}
|
|
});
|
|
try {
|
|
await nextClient.start();
|
|
await externalSources.connected(nextClient);
|
|
await applyPrometeuVisualTheme(nextClient.initializeResult);
|
|
reconnectAttempt = 0;
|
|
status(`Connected to Studio at ${host}:${port}`);
|
|
}
|
|
catch (error) {
|
|
externalSources.resetSession();
|
|
if (client === nextClient) {
|
|
client = undefined;
|
|
}
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
status(`Studio unavailable: ${message}`);
|
|
try {
|
|
await nextClient.dispose();
|
|
}
|
|
catch { /* transport already stopped */ }
|
|
scheduleReconnect();
|
|
}
|
|
}
|
|
async function stopClient() {
|
|
clearReconnectTimer();
|
|
stoppingClient = true;
|
|
if (startPromise)
|
|
await startPromise;
|
|
clearReconnectTimer();
|
|
if (!client) {
|
|
stoppingClient = false;
|
|
return;
|
|
}
|
|
const currentClient = client;
|
|
client = undefined;
|
|
stoppingClient = true;
|
|
output.appendLine("Stopping Prometeu Studio LSP client...");
|
|
try {
|
|
await currentClient.stop();
|
|
output.appendLine("Prometeu Studio LSP client stopped.");
|
|
}
|
|
catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
output.appendLine(`Failed to stop Prometeu LSP client cleanly: ${message}`);
|
|
}
|
|
finally {
|
|
stoppingClient = false;
|
|
}
|
|
}
|
|
function scheduleReconnect() {
|
|
if (!reconnectContext || disposed || stoppingClient) {
|
|
return;
|
|
}
|
|
if (reconnectTimer || client) {
|
|
return;
|
|
}
|
|
const delay = (0, discovery_1.reconnectDelay)(reconnectAttempt++);
|
|
reconnectTimer = setTimeout(() => {
|
|
reconnectTimer = undefined;
|
|
void startClient(reconnectContext);
|
|
}, delay);
|
|
}
|
|
function clearReconnectTimer() {
|
|
if (!reconnectTimer) {
|
|
return;
|
|
}
|
|
clearTimeout(reconnectTimer);
|
|
reconnectTimer = undefined;
|
|
}
|
|
async function applyPrometeuVisualTheme(initializeResult) {
|
|
const visualThemesPayload = extractPrometeuVisualThemesPayload(initializeResult);
|
|
if (!visualThemesPayload) {
|
|
output.appendLine("Prometeu visual theme payload not present in initialize result.");
|
|
return;
|
|
}
|
|
const semanticProjectionPayload = extractPrometeuSemanticHostProjectionsPayload(initializeResult);
|
|
const vscodeProjection = selectHostProjection(semanticProjectionPayload, VSCODE_HOST_ID);
|
|
if (!semanticProjectionPayload) {
|
|
output.appendLine("Prometeu semantic host projection payload not present in initialize result.");
|
|
}
|
|
else if (!vscodeProjection) {
|
|
output.appendLine("Prometeu semantic host projection payload does not declare a vscode projection.");
|
|
}
|
|
const activeTheme = visualThemesPayload.visualThemes.find((theme) => theme.themeId === visualThemesPayload.activeVisualThemeId);
|
|
if (!activeTheme) {
|
|
output.appendLine(`Prometeu visual theme '${visualThemesPayload.activeVisualThemeId}' was not declared by the server.`);
|
|
return;
|
|
}
|
|
const themeSignature = JSON.stringify({
|
|
languageId: visualThemesPayload.frontendLanguageId,
|
|
themeId: activeTheme.themeId,
|
|
editorPalette: activeTheme.editorPalette,
|
|
tokenStyles: activeTheme.tokenStyles,
|
|
semanticProjection: vscodeProjection ?? null
|
|
});
|
|
if (themeSignature === lastAppliedThemeSignature) {
|
|
output.appendLine(`Prometeu visual theme '${activeTheme.themeId}' is already applied.`);
|
|
return;
|
|
}
|
|
const configurationTarget = vscode.workspace.workspaceFolders?.length
|
|
? vscode.ConfigurationTarget.Workspace
|
|
: vscode.ConfigurationTarget.Global;
|
|
const configuration = vscode.workspace.getConfiguration();
|
|
const existingSemanticCustomizations = configuration.get("editor.semanticTokenColorCustomizations") ?? {};
|
|
const semanticRules = {
|
|
...(readObject(existingSemanticCustomizations.rules)),
|
|
...buildSemanticTokenRules(visualThemesPayload.frontendLanguageId, activeTheme, vscodeProjection)
|
|
};
|
|
await configuration.update("editor.semanticTokenColorCustomizations", {
|
|
...existingSemanticCustomizations,
|
|
enabled: true,
|
|
rules: semanticRules
|
|
}, configurationTarget);
|
|
const existingWorkbenchColors = configuration.get("workbench.colorCustomizations") ?? {};
|
|
await configuration.update("workbench.colorCustomizations", {
|
|
...existingWorkbenchColors,
|
|
"editor.foreground": activeTheme.editorPalette.baseForeground,
|
|
"editor.selectionBackground": activeTheme.editorPalette.selectionBackground,
|
|
"editorLineNumber.foreground": activeTheme.editorPalette.lineNumberForeground
|
|
}, configurationTarget);
|
|
lastAppliedThemeSignature = themeSignature;
|
|
output.appendLine(`Applied Prometeu visual theme '${activeTheme.themeId}' for language '${visualThemesPayload.frontendLanguageId}'.`);
|
|
}
|
|
function extractPrometeuVisualThemesPayload(initializeResult) {
|
|
if (!initializeResult || typeof initializeResult !== "object") {
|
|
return undefined;
|
|
}
|
|
const capabilities = readObject(initializeResult.capabilities);
|
|
const experimental = readObject(capabilities.experimental);
|
|
const payload = readObject(experimental.prometeuVisualThemes);
|
|
if (typeof payload.frontendLanguageId !== "string" || typeof payload.activeVisualThemeId !== "string") {
|
|
return undefined;
|
|
}
|
|
if (!Array.isArray(payload.visualThemes)) {
|
|
return undefined;
|
|
}
|
|
return payload;
|
|
}
|
|
function extractPrometeuSemanticHostProjectionsPayload(initializeResult) {
|
|
if (!initializeResult || typeof initializeResult !== "object") {
|
|
return undefined;
|
|
}
|
|
const capabilities = readObject(initializeResult.capabilities);
|
|
const experimental = readObject(capabilities.experimental);
|
|
const payload = readObject(experimental.prometeuSemanticHostProjections);
|
|
if (typeof payload.frontendLanguageId !== "string" || !Array.isArray(payload.semanticKeys) || !Array.isArray(payload.hostProjections)) {
|
|
return undefined;
|
|
}
|
|
return payload;
|
|
}
|
|
function selectHostProjection(payload, hostId) {
|
|
if (!payload) {
|
|
return undefined;
|
|
}
|
|
return payload.hostProjections.find((projection) => projection.hostId === hostId);
|
|
}
|
|
function buildSemanticTokenRules(languageId, theme, hostProjection) {
|
|
const rules = {};
|
|
const projectionBySemanticKey = new Map((hostProjection?.tokenProjections ?? []).map((projection) => [projection.semanticKey, projection]));
|
|
for (const tokenStyle of theme.tokenStyles) {
|
|
const styleValue = !tokenStyle.italic && !tokenStyle.bold && !tokenStyle.underline
|
|
? tokenStyle.foreground
|
|
: {
|
|
foreground: tokenStyle.foreground,
|
|
...(tokenStyle.italic ? { italic: true } : {}),
|
|
...(tokenStyle.bold ? { bold: true } : {}),
|
|
...(tokenStyle.underline ? { underline: true } : {})
|
|
};
|
|
rules[`${tokenStyle.semanticKey}:${languageId}`] = styleValue;
|
|
const projection = projectionBySemanticKey.get(tokenStyle.semanticKey);
|
|
if (!projection) {
|
|
continue;
|
|
}
|
|
const projectedSelector = buildSemanticSelector(languageId, projection.hostTokenType, projection.hostTokenModifiers);
|
|
if (!(projectedSelector in rules)) {
|
|
rules[projectedSelector] = styleValue;
|
|
}
|
|
const fallbackSelector = buildSemanticSelector(languageId, projection.fallbackTokenType, projection.fallbackTokenModifiers);
|
|
if (!(fallbackSelector in rules)) {
|
|
rules[fallbackSelector] = styleValue;
|
|
}
|
|
}
|
|
return rules;
|
|
}
|
|
function buildSemanticSelector(languageId, tokenType, modifiers) {
|
|
const normalizedModifiers = [...modifiers].sort();
|
|
if (normalizedModifiers.length === 0) {
|
|
return `${tokenType}:${languageId}`;
|
|
}
|
|
return `${tokenType}.${normalizedModifiers.join(".")}:${languageId}`;
|
|
}
|
|
function readObject(value) {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
return {};
|
|
}
|
|
return value;
|
|
}
|
|
//# sourceMappingURL=extension.js.map
|