Files
prometeu-studio/tools/vscode-extension/out/externalSources.js
bquarkz ea1cc26fe3
Test / Tests and coverage occurred while executing withChecks step.
Intrepid/Prometeu/Studio/pipeline/pr-master There was a failure building this commit
feat(studio): improve compiler reliability and AI diagnostics
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.
2026-11-10 12:36:25 +00:00

165 lines
7.5 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.ExternalSources = exports.externalScheme = void 0;
const vscode = __importStar(require("vscode"));
exports.externalScheme = "prometeu-source";
/** Immutable virtual documents. No filesystem provider and no content-change events. */
class ExternalSources {
client;
consumerId;
documents = new Map();
available = new Set();
closed = new Set();
status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 10);
refreshStatus() {
const document = vscode.window.activeTextEditor?.document;
if (document?.uri.scheme === exports.externalScheme && !this.canQuery(document)) {
this.status.text = "Prometeu: external source unavailable";
this.status.tooltip = "Reconnect to Studio or navigate again to obtain the current source revision.";
this.status.show();
}
else
this.status.hide();
}
get initializationOptions() {
return this.consumerId ? { prometeuExternalConsumerId: this.consumerId } : {};
}
canQuery(document) {
const uri = document.uri;
if (uri.scheme !== exports.externalScheme)
return true;
const content = this.documents.get(uri.toString());
return !!this.client && this.available.has(uri.toString()) && !!content
&& document.getText().replace(/\r\n?/g, "\n") === content.text.replace(/\r\n?/g, "\n");
}
async connected(client) {
const experimental = client.initializeResult?.capabilities.experimental;
if (!experimental?.prometeuExternalSources)
return;
this.client = client;
this.consumerId = experimental.prometeuExternalConsumerId;
for (const uri of this.closed)
await this.release(uri);
this.closed.clear();
for (const [uri, old] of this.documents) {
try {
const current = await this.request("revalidateExternalSource", uri);
if (current.descriptor.revision === old.descriptor.revision && current.text === old.text)
this.available.add(uri);
}
catch { /* Keep displayed text; fresh navigation is required. */ }
}
this.refreshStatus();
}
disconnected() { this.client = undefined; this.available.clear(); this.refreshStatus(); }
resetSession() { this.disconnected(); this.consumerId = undefined; this.closed.clear(); }
request(operation, uri) {
if (!this.client || !this.consumerId)
return Promise.reject(new Error("External source unavailable: reconnect to Studio."));
return this.client.sendRequest(`prometeu/${operation}`, { consumerId: this.consumerId, uri });
}
async provideTextDocumentContent(uri, token) {
const key = uri.toString();
const old = this.documents.get(key);
if (old)
return old.text;
const content = await this.request("readExternalSource", key);
if (token.isCancellationRequested) {
await this.release(key);
throw new Error("External source read cancelled.");
}
if (!content.descriptor.readOnly || content.descriptor.uri !== key)
throw new Error("Invalid external source descriptor.");
this.documents.set(key, content);
this.available.add(key);
this.refreshStatus();
return content.text;
}
originLenses(document) {
if (!this.canQuery(document))
return [];
const content = this.documents.get(document.uri.toString());
return (content?.descriptor.origins ?? []).map(origin => {
const offset = Buffer.from(document.getText(), "utf8").subarray(0, origin.startOffset).toString("utf8").length;
const position = document.positionAt(offset);
return new vscode.CodeLens(new vscode.Range(position, position), {
title: "Open animation definition in Studio", command: "prometeu.openAnimationOrigin",
arguments: [document.uri, origin.startOffset]
});
});
}
async openAnimationOrigin(uri, byteOffset) {
const document = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString());
if (!document || !this.canQuery(document) || !this.client || !this.consumerId)
throw new Error("Animation source unavailable: navigate again to obtain the current revision.");
await this.client.sendRequest("prometeu/openAnimationOrigin", { consumerId: this.consumerId, uri: uri.toString(), offset: byteOffset });
}
async opened(document) {
if (document.uri.scheme !== exports.externalScheme)
return;
const content = this.documents.get(document.uri.toString());
if (content && content.descriptor.languageId !== document.languageId)
await vscode.languages.setTextDocumentLanguage(document, content.descriptor.languageId);
}
async closeDocument(document) {
const uri = document.uri.toString();
if (!this.documents.has(uri))
return;
// Changing language also fires close/open; retain while VS Code still owns the document.
await new Promise(resolve => setTimeout(resolve, 0));
if (vscode.workspace.textDocuments.some(open => open.uri.toString() === uri && !open.isClosed))
return;
this.documents.delete(uri);
this.available.delete(uri);
if (this.client)
await this.release(uri);
else
this.closed.add(uri);
}
async release(uri) {
if (this.client && this.consumerId)
await this.client.sendRequest("prometeu/releaseExternalSource", { consumerId: this.consumerId, uri });
}
async shutdown() {
if (this.client && this.consumerId)
await this.client.sendRequest("prometeu/releaseExternalSource", { consumerId: this.consumerId, uri: null });
this.resetSession();
this.documents.clear();
}
dispose() { this.disconnected(); this.documents.clear(); this.status.dispose(); }
}
exports.ExternalSources = ExternalSources;
//# sourceMappingURL=externalSources.js.map