Public dry run dryrun-309831e1e021
Source commit: 309831e1e021f962c118452336776fd9a94025f9 Public tree identity: sha256:6fa95c1745579bd6256dbeb3d476db0b07c2f24aa9213b0f7783ce1adfc8aca5
This commit is contained in:
commit
f22d0a5791
113 changed files with 39348 additions and 0 deletions
414
vscode-extension/extension.js
Normal file
414
vscode-extension/extension.js
Normal file
|
|
@ -0,0 +1,414 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const childProcess = require("child_process");
|
||||
|
||||
const DEFAULT_OPERATOR_ENDPOINT = "https://disasmer.michelpaulissen.com:9443";
|
||||
|
||||
let vscode = null;
|
||||
try {
|
||||
vscode = require("vscode");
|
||||
} catch (_) {
|
||||
vscode = null;
|
||||
}
|
||||
|
||||
function discoverEnvironmentNames(projectRoot) {
|
||||
const envsDir = path.join(projectRoot, "envs");
|
||||
if (!fs.existsSync(envsDir)) return [];
|
||||
|
||||
return fs
|
||||
.readdirSync(envsDir, { withFileTypes: true })
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.map((entry) => entry.name)
|
||||
.filter((name) => {
|
||||
const dir = path.join(envsDir, name);
|
||||
return (
|
||||
fs.existsSync(path.join(dir, "Containerfile")) ||
|
||||
fs.existsSync(path.join(dir, "Dockerfile"))
|
||||
);
|
||||
})
|
||||
.sort();
|
||||
}
|
||||
|
||||
function findEnvReferences(text) {
|
||||
const references = [];
|
||||
const pattern = /env!\(\s*"([^"]+)"\s*\)/g;
|
||||
let match;
|
||||
while ((match = pattern.exec(text)) !== null) {
|
||||
references.push({
|
||||
name: match[1],
|
||||
start: match.index,
|
||||
end: pattern.lastIndex
|
||||
});
|
||||
}
|
||||
return references;
|
||||
}
|
||||
|
||||
function diagnoseEnvReferences(text, environmentNames) {
|
||||
const known = new Set(environmentNames);
|
||||
return findEnvReferences(text)
|
||||
.filter((reference) => !known.has(reference.name))
|
||||
.map((reference) => ({
|
||||
...reference,
|
||||
message: `Missing Disasmer environment "${reference.name}". Add envs/${reference.name}/Containerfile or envs/${reference.name}/Dockerfile.`
|
||||
}));
|
||||
}
|
||||
|
||||
function binaryCandidates(projectRoot, name) {
|
||||
const names = process.platform === "win32" ? [name, `${name}.exe`] : [name];
|
||||
return names.map((candidate) => path.join(projectRoot, candidate));
|
||||
}
|
||||
|
||||
function executableWorkspaceBinary(projectRoot, name) {
|
||||
if (!projectRoot) return null;
|
||||
return binaryCandidates(projectRoot, name).find((candidate) => {
|
||||
try {
|
||||
return fs.statSync(candidate).isFile();
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}) || null;
|
||||
}
|
||||
|
||||
function hasCargoWorkspace(root) {
|
||||
return fs.existsSync(path.join(root, "Cargo.toml"));
|
||||
}
|
||||
|
||||
function resolveProjectPath(folder, value) {
|
||||
const workspaceRoot = folder && folder.uri && folder.uri.fsPath;
|
||||
if (!value || value === "${workspaceFolder}") return workspaceRoot;
|
||||
if (workspaceRoot && typeof value === "string") {
|
||||
return value.replace(/\$\{workspaceFolder\}/g, workspaceRoot);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function bundleInspectCommand(projectRoot, adapterWorkspace = path.resolve(__dirname, "..")) {
|
||||
const workspaceCli = executableWorkspaceBinary(projectRoot, "disasmer");
|
||||
if (workspaceCli) {
|
||||
return {
|
||||
command: workspaceCli,
|
||||
args: ["bundle", "inspect", "--project", projectRoot],
|
||||
options: {
|
||||
cwd: projectRoot,
|
||||
encoding: "utf8"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
command: "cargo",
|
||||
args: [
|
||||
"run",
|
||||
"-q",
|
||||
"-p",
|
||||
"disasmer-cli",
|
||||
"--bin",
|
||||
"disasmer",
|
||||
"--",
|
||||
"bundle",
|
||||
"inspect",
|
||||
"--project",
|
||||
projectRoot
|
||||
],
|
||||
options: {
|
||||
cwd: adapterWorkspace,
|
||||
encoding: "utf8"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function refreshBundleBeforeLaunch(
|
||||
projectRoot,
|
||||
adapterWorkspace = path.resolve(__dirname, ".."),
|
||||
runner = childProcess.spawnSync
|
||||
) {
|
||||
const command = bundleInspectCommand(projectRoot, adapterWorkspace);
|
||||
const result = runner(command.command, command.args, command.options);
|
||||
if (result.error) {
|
||||
throw new Error(`Disasmer bundle refresh failed: ${result.error.message}`);
|
||||
}
|
||||
if (result.status !== 0) {
|
||||
const detail = (result.stderr || result.stdout || "").trim();
|
||||
throw new Error(
|
||||
`Disasmer bundle refresh failed before debug launch${detail ? `: ${detail}` : "."}`
|
||||
);
|
||||
}
|
||||
|
||||
let inspection;
|
||||
try {
|
||||
inspection = JSON.parse(result.stdout);
|
||||
} catch (error) {
|
||||
throw new Error(`Disasmer bundle refresh returned invalid metadata: ${error.message}`);
|
||||
}
|
||||
if (!inspection.metadata || !inspection.metadata.identity) {
|
||||
throw new Error("Disasmer bundle refresh did not return a bundle identity.");
|
||||
}
|
||||
return inspection;
|
||||
}
|
||||
|
||||
function disasmerViewDescriptors() {
|
||||
return [
|
||||
{ id: "disasmer.nodes", emptyLabel: "No attached nodes" },
|
||||
{ id: "disasmer.processes", emptyLabel: "No virtual processes" },
|
||||
{ id: "disasmer.logs", emptyLabel: "No log streams" },
|
||||
{ id: "disasmer.artifacts", emptyLabel: "No artifacts" },
|
||||
{ id: "disasmer.inspector", emptyLabel: "No inspector state" }
|
||||
];
|
||||
}
|
||||
|
||||
function disasmerViewStatePath(projectRoot) {
|
||||
return path.join(projectRoot, ".disasmer", "views.json");
|
||||
}
|
||||
|
||||
function emptyDisasmerViewState() {
|
||||
return {
|
||||
nodes: [],
|
||||
processes: [],
|
||||
logs: [],
|
||||
artifacts: [],
|
||||
inspector: []
|
||||
};
|
||||
}
|
||||
|
||||
function asArray(value) {
|
||||
return Array.isArray(value) ? value : [];
|
||||
}
|
||||
|
||||
function loadDisasmerViewState(projectRoot, reader = fs.readFileSync) {
|
||||
const statePath = disasmerViewStatePath(projectRoot);
|
||||
if (!fs.existsSync(statePath)) {
|
||||
return emptyDisasmerViewState();
|
||||
}
|
||||
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(reader(statePath, "utf8"));
|
||||
} catch (error) {
|
||||
return {
|
||||
...emptyDisasmerViewState(),
|
||||
inspector: [
|
||||
{
|
||||
label: "View state error",
|
||||
value: error.message
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
nodes: asArray(parsed.nodes),
|
||||
processes: asArray(parsed.processes),
|
||||
logs: asArray(parsed.logs),
|
||||
artifacts: asArray(parsed.artifacts),
|
||||
inspector: asArray(parsed.inspector)
|
||||
};
|
||||
}
|
||||
|
||||
function item(label, description = "") {
|
||||
return {
|
||||
label: String(label || ""),
|
||||
description: String(description || "")
|
||||
};
|
||||
}
|
||||
|
||||
function disasmerViewItems(state, viewId) {
|
||||
switch (viewId) {
|
||||
case "disasmer.nodes":
|
||||
return state.nodes.map((node) =>
|
||||
item(node.id || node.name || "node", [node.status, node.capabilities].filter(Boolean).join(" "))
|
||||
);
|
||||
case "disasmer.processes":
|
||||
return state.processes.map((process) =>
|
||||
item(process.id || process.process || "process", [process.status, process.entry].filter(Boolean).join(" "))
|
||||
);
|
||||
case "disasmer.logs":
|
||||
return state.logs.map((log) =>
|
||||
item(log.task || log.stream || "log", [log.message, log.bytes].filter(Boolean).join(" "))
|
||||
);
|
||||
case "disasmer.artifacts":
|
||||
return state.artifacts.map((artifact) =>
|
||||
item(artifact.path || artifact.id || "artifact", [artifact.status, artifact.size].filter(Boolean).join(" "))
|
||||
);
|
||||
case "disasmer.inspector":
|
||||
return state.inspector.map((entry) =>
|
||||
item(entry.label || entry.name || "inspector", entry.value || entry.detail || "")
|
||||
);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function treeItemsForView(projectRoot, descriptor) {
|
||||
const state = projectRoot ? loadDisasmerViewState(projectRoot) : emptyDisasmerViewState();
|
||||
const items = disasmerViewItems(state, descriptor.id);
|
||||
return items.length > 0 ? items : [item(descriptor.emptyLabel)];
|
||||
}
|
||||
|
||||
function toVsCodeTreeItem(viewItem) {
|
||||
const treeItem = new vscode.TreeItem(
|
||||
viewItem.label,
|
||||
vscode.TreeItemCollapsibleState.None
|
||||
);
|
||||
treeItem.description = viewItem.description;
|
||||
return treeItem;
|
||||
}
|
||||
|
||||
function resolveDisasmerDebugConfiguration(folder, config = {}) {
|
||||
const project = resolveProjectPath(folder, config.project);
|
||||
return {
|
||||
...config,
|
||||
name: config.name || "Disasmer: Launch Virtual Process",
|
||||
type: "disasmer",
|
||||
request: "launch",
|
||||
entry: config.entry || "build",
|
||||
project,
|
||||
runtimeBackend: config.runtimeBackend || "local-services",
|
||||
operatorEndpoint: config.operatorEndpoint || DEFAULT_OPERATOR_ENDPOINT
|
||||
};
|
||||
}
|
||||
|
||||
function defaultOperatorEndpoint() {
|
||||
return DEFAULT_OPERATOR_ENDPOINT;
|
||||
}
|
||||
|
||||
function debugAdapterExecutableSpec(
|
||||
projectRoot,
|
||||
adapterWorkspace = path.resolve(__dirname, "..")
|
||||
) {
|
||||
const workspaceAdapter = executableWorkspaceBinary(projectRoot, "disasmer-debug-dap");
|
||||
if (workspaceAdapter) {
|
||||
return {
|
||||
command: workspaceAdapter,
|
||||
args: [],
|
||||
options: { cwd: projectRoot }
|
||||
};
|
||||
}
|
||||
|
||||
if (!hasCargoWorkspace(adapterWorkspace)) {
|
||||
return {
|
||||
command: "disasmer-debug-dap",
|
||||
args: [],
|
||||
options: { cwd: projectRoot || process.cwd() }
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
command: "cargo",
|
||||
args: ["run", "-q", "-p", "disasmer-dap", "--bin", "disasmer-debug-dap"],
|
||||
options: { cwd: adapterWorkspace }
|
||||
};
|
||||
}
|
||||
|
||||
function registerDisasmerViews(context) {
|
||||
if (!vscode) return;
|
||||
const workspaceRoot =
|
||||
vscode.workspace.workspaceFolders &&
|
||||
vscode.workspace.workspaceFolders[0] &&
|
||||
vscode.workspace.workspaceFolders[0].uri.fsPath;
|
||||
const emitters = [];
|
||||
for (const descriptor of disasmerViewDescriptors()) {
|
||||
const emitter = new vscode.EventEmitter();
|
||||
emitters.push(emitter);
|
||||
context.subscriptions.push(
|
||||
vscode.window.registerTreeDataProvider(descriptor.id, {
|
||||
onDidChangeTreeData: emitter.event,
|
||||
getTreeItem(item) {
|
||||
return item;
|
||||
},
|
||||
getChildren() {
|
||||
return treeItemsForView(workspaceRoot, descriptor).map(toVsCodeTreeItem);
|
||||
}
|
||||
}),
|
||||
emitter
|
||||
);
|
||||
}
|
||||
if (workspaceRoot && vscode.workspace.createFileSystemWatcher) {
|
||||
const watcher = vscode.workspace.createFileSystemWatcher(
|
||||
new vscode.RelativePattern(workspaceRoot, ".disasmer/views.json")
|
||||
);
|
||||
const refresh = () => emitters.forEach((emitter) => emitter.fire());
|
||||
context.subscriptions.push(
|
||||
watcher,
|
||||
watcher.onDidChange(refresh),
|
||||
watcher.onDidCreate(refresh),
|
||||
watcher.onDidDelete(refresh)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function activate(context) {
|
||||
if (!vscode) return;
|
||||
|
||||
const diagnostics = vscode.languages.createDiagnosticCollection("disasmer");
|
||||
context.subscriptions.push(diagnostics);
|
||||
registerDisasmerViews(context);
|
||||
|
||||
const refresh = (document) => {
|
||||
if (document.languageId !== "rust") return;
|
||||
const folder = vscode.workspace.getWorkspaceFolder(document.uri);
|
||||
if (!folder) return;
|
||||
const environmentNames = discoverEnvironmentNames(folder.uri.fsPath);
|
||||
const items = diagnoseEnvReferences(document.getText(), environmentNames).map((diagnostic) => {
|
||||
const start = document.positionAt(diagnostic.start);
|
||||
const end = document.positionAt(diagnostic.end);
|
||||
return new vscode.Diagnostic(
|
||||
new vscode.Range(start, end),
|
||||
diagnostic.message,
|
||||
vscode.DiagnosticSeverity.Error
|
||||
);
|
||||
});
|
||||
diagnostics.set(document.uri, items);
|
||||
};
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.workspace.onDidOpenTextDocument(refresh),
|
||||
vscode.workspace.onDidChangeTextDocument((event) => refresh(event.document)),
|
||||
vscode.workspace.onDidSaveTextDocument(refresh),
|
||||
vscode.debug.registerDebugAdapterDescriptorFactory("disasmer", {
|
||||
createDebugAdapterDescriptor(session) {
|
||||
const folder = session.workspaceFolder;
|
||||
const project = session.configuration.project || (folder && folder.uri.fsPath);
|
||||
if (!project) {
|
||||
throw new Error("Disasmer debug launch requires a workspace folder or project path.");
|
||||
}
|
||||
const adapterWorkspace = path.resolve(__dirname, "..");
|
||||
refreshBundleBeforeLaunch(project, adapterWorkspace);
|
||||
const spec = debugAdapterExecutableSpec(project, adapterWorkspace);
|
||||
return new vscode.DebugAdapterExecutable(
|
||||
spec.command,
|
||||
spec.args,
|
||||
spec.options
|
||||
);
|
||||
}
|
||||
}),
|
||||
vscode.debug.registerDebugConfigurationProvider("disasmer", {
|
||||
resolveDebugConfiguration(folder, config) {
|
||||
return resolveDisasmerDebugConfiguration(folder, config);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
for (const document of vscode.workspace.textDocuments) {
|
||||
refresh(document);
|
||||
}
|
||||
}
|
||||
|
||||
function deactivate() {}
|
||||
|
||||
module.exports = {
|
||||
activate,
|
||||
deactivate,
|
||||
bundleInspectCommand,
|
||||
debugAdapterExecutableSpec,
|
||||
defaultOperatorEndpoint,
|
||||
diagnoseEnvReferences,
|
||||
disasmerViewDescriptors,
|
||||
disasmerViewItems,
|
||||
disasmerViewStatePath,
|
||||
discoverEnvironmentNames,
|
||||
findEnvReferences,
|
||||
loadDisasmerViewState,
|
||||
registerDisasmerViews,
|
||||
refreshBundleBeforeLaunch,
|
||||
resolveDisasmerDebugConfiguration
|
||||
};
|
||||
136
vscode-extension/package.json
Normal file
136
vscode-extension/package.json
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
{
|
||||
"name": "disasmer-vscode",
|
||||
"displayName": "Disasmer",
|
||||
"description": "VS Code support for Disasmer build programs, environments, and debugging.",
|
||||
"version": "0.1.0",
|
||||
"publisher": "disasmer",
|
||||
"engines": {
|
||||
"vscode": "^1.80.0"
|
||||
},
|
||||
"categories": [
|
||||
"Debuggers",
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onLanguage:rust",
|
||||
"onDebugResolve:disasmer",
|
||||
"onView:disasmer.nodes",
|
||||
"onView:disasmer.processes",
|
||||
"onView:disasmer.logs",
|
||||
"onView:disasmer.artifacts",
|
||||
"onView:disasmer.inspector",
|
||||
"workspaceContains:envs/*/Containerfile",
|
||||
"workspaceContains:envs/*/Dockerfile"
|
||||
],
|
||||
"main": "./extension.js",
|
||||
"contributes": {
|
||||
"viewsContainers": {
|
||||
"activitybar": [
|
||||
{
|
||||
"id": "disasmer",
|
||||
"title": "Disasmer",
|
||||
"icon": "resources/disasmer.svg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"debuggers": [
|
||||
{
|
||||
"type": "disasmer",
|
||||
"label": "Disasmer",
|
||||
"languages": [
|
||||
"rust"
|
||||
],
|
||||
"configurationAttributes": {
|
||||
"launch": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"request",
|
||||
"type",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"default": "Disasmer: Launch Virtual Process"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"default": "disasmer"
|
||||
},
|
||||
"request": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"launch"
|
||||
],
|
||||
"default": "launch"
|
||||
},
|
||||
"entry": {
|
||||
"type": "string",
|
||||
"description": "Disasmer entrypoint such as build, test, package, or release."
|
||||
},
|
||||
"project": {
|
||||
"type": "string",
|
||||
"description": "Project directory. Defaults to the current workspace folder."
|
||||
},
|
||||
"sourcePath": {
|
||||
"type": "string",
|
||||
"description": "Source file shown in the Disasmer virtual stack. Defaults to src/build.rs or src/main.rs."
|
||||
},
|
||||
"runtimeBackend": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"local-services",
|
||||
"live-services",
|
||||
"simulated"
|
||||
],
|
||||
"default": "local-services",
|
||||
"description": "Runtime backend used by the debug adapter. F5 defaults to local coordinator/node services; live-services uses the configured operator and an attached node."
|
||||
},
|
||||
"operatorEndpoint": {
|
||||
"type": "string",
|
||||
"default": "https://disasmer.michelpaulissen.com:9443",
|
||||
"description": "Default hosted operator endpoint used when a dry-run or hosted launch selects the public operator."
|
||||
},
|
||||
"tenant": {
|
||||
"type": "string",
|
||||
"description": "Tenant identity used when the DAP talks to a live operator."
|
||||
},
|
||||
"projectId": {
|
||||
"type": "string",
|
||||
"description": "Coordinator project identity used when the DAP talks to a live operator."
|
||||
},
|
||||
"actorUser": {
|
||||
"type": "string",
|
||||
"description": "User identity used for coordinator inspection requests."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"views": {
|
||||
"disasmer": [
|
||||
{
|
||||
"id": "disasmer.nodes",
|
||||
"name": "Disasmer Nodes"
|
||||
},
|
||||
{
|
||||
"id": "disasmer.processes",
|
||||
"name": "Disasmer Processes"
|
||||
},
|
||||
{
|
||||
"id": "disasmer.logs",
|
||||
"name": "Disasmer Logs"
|
||||
},
|
||||
{
|
||||
"id": "disasmer.artifacts",
|
||||
"name": "Disasmer Artifacts"
|
||||
},
|
||||
{
|
||||
"id": "disasmer.inspector",
|
||||
"name": "Disasmer Inspector"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
3
vscode-extension/resources/disasmer.svg
Normal file
3
vscode-extension/resources/disasmer.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M5 3h6.2C16 3 20 7 20 12s-4 9-8.8 9H5V3Zm4 4v10h2.1c2.7 0 4.9-2.2 4.9-5s-2.2-5-4.9-5H9Z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 213 B |
Loading…
Add table
Add a link
Reference in a new issue