Skip to content

Commit

Permalink
Panoptes script to replace all embed blocks with debugger.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Apr 2, 2024
1 parent b2c38c0 commit 4808203
Show file tree
Hide file tree
Showing 25 changed files with 412 additions and 207 deletions.
3 changes: 2 additions & 1 deletion ide/packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"entryPoint": "./src/lib.ts"
},
"devDependencies": {
"jsdom": "^22.1.0"
"jsdom": "^22.1.0",
"new-github-issue-url": "^1.0.0"
}
}
69 changes: 69 additions & 0 deletions ide/packages/common/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import newGithubIssueUrl from "new-github-issue-url";
import { unescape } from "querystring";

import {
BodyBundle,
BodyHash,
CharRange,
ExprIdx,
Expand All @@ -15,6 +19,41 @@ export interface ErrorJumpTargetInfo {
hash: ObligationHash;
}

export const ConfigConsts = {
PANOPTES_NAME: "panoptes",
EMBED_NAME: "argus-embed",
};

// ----------------------------------------------------
// Panoptes initial configuration for a single webview

export type PanoptesInitialData = {
data: [Filename, ObligationsInBody[]][];
target?: ErrorJumpTargetInfo;
};

export type SystemSpec = Omit<IssueOptions, "logText">;

export type PanoptesConfig = PanoptesInitialData &
(
| {
type: "VSCODE_BACKING";
spec: SystemSpec;
}
| {
type: "WEB_BUNDLE";
closedSystem: BodyBundle[];
}
);

export function configToString(config: PanoptesConfig) {
return encodeURI(JSON.stringify(config));
}

export function maybeStringToConfig(str?: string): PanoptesConfig | undefined {
return str ? JSON.parse(decodeURI(str)) : undefined;
}

// ----------------------------------------------------
// Interface between the webview and extension

Expand Down Expand Up @@ -180,3 +219,33 @@ export function isPanoMsgRemoveHighlight(
): msg is PanoptesToSystemMsg<"remove-highlight"> {
return msg.command === "remove-highlight";
}

export interface IssueOptions {
osPlatform: string;
osRelease: string;
vscodeVersion: string;
logText: string;
}

export function getArgusIssueUrl(err: string, opts: IssueOptions) {
const bts = "```";
const url = newGithubIssueUrl({
user: "cognitive-engineering-lab",
repo: "argus",
body: `# Problem
<!-- Please describe the problem and how you encountered it. -->
# Logs
<!-- You don't need to add or change anything below this point. -->
**OS:** ${opts.osPlatform} (${opts.osRelease})
**VSCode:** ${opts.vscodeVersion}
**Error message**
${bts}
${err}
${bts}
${opts.logText}`,
});

return url;
}
14 changes: 7 additions & 7 deletions ide/packages/evaluation/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function argusScreenshots(
fs.writeSync(tmpobj.fd, html);
const page = await context.newPage();
await page.goto(`file://${tmpobj.name}`);
await sleep(3000);
await sleep(6000);
await page.screenshot({ path: out, fullPage: false });
};

Expand Down Expand Up @@ -108,12 +108,12 @@ function ensureDir(dir: fs.PathLike) {
// When chumsky is working just read the directory contents
const testCases = [
"axum",
// "bevy",
// "diesel",
// "easy_ml",
// "entrait",
// "nalgebra",
// "uom",
"bevy",
"diesel",
"easy_ml",
"entrait",
"nalgebra",
"uom",
] as const;

async function outputInDir(resultsDir: string) {
Expand Down
30 changes: 16 additions & 14 deletions ide/packages/evaluation/src/page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { BodyBundle, ObligationsInBody } from "@argus/common/bindings";
import { ErrorJumpTargetInfo, Filename } from "@argus/common/lib";
import { BodyBundle } from "@argus/common/bindings";
import {
ConfigConsts,
ErrorJumpTargetInfo,
Filename,
PanoptesConfig,
configToString,
} from "@argus/common/lib";
import _ from "lodash";
import path from "path";

Expand Down Expand Up @@ -700,10 +706,12 @@ export function webHtml(
filename: Filename,
bundles: BodyBundle[]
) {
const target = findErrorTargetInBundles(bundles);
const initialData: [Filename, ObligationsInBody[]][] = [
[filename, bundles.map(b => b.body)],
];
const config: PanoptesConfig = {
type: "WEB_BUNDLE",
target: findErrorTargetInBundles(bundles),
data: [[filename, bundles.map(b => b.body)]],
closedSystem: bundles,
};

const panoptesDir = path.resolve(__dirname, "..", "..", "panoptes");
const scriptUri = path.resolve(panoptesDir, "dist", "panoptes.iife.js");
Expand All @@ -720,6 +728,7 @@ export function webHtml(
const styleUrl = url(styleUri);
const codiconsUrl = url(codiconsUri);
const scriptUrl = url(scriptUri);
const configString = configToString(config);

return `
<!DOCTYPE html>
Expand All @@ -730,16 +739,9 @@ export function webHtml(
<title>${title}</title>
<link rel="stylesheet" type="text/css" href="${styleUrl}">
<link rel="stylesheet" type="text/css" href="${codiconsUrl}">
<script>
(function () {
window.data = ${JSON.stringify(initialData)};
window.target = ${JSON.stringify(target)};
window.createClosedSystem = ${JSON.stringify(bundles)}
})()
</script>
</head>
<body>
<div id="root" style="width: 100%; height: 100%;"></div>
<div id="root" class=${ConfigConsts.EMBED_NAME} style="width: 100%; height: 100%;" data-config=${configString}></div>
<script src="${scriptUrl}"></script>
</body>
</html>
Expand Down
26 changes: 6 additions & 20 deletions ide/packages/extension/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ArgusError } from "@argus/common/lib";
import { ArgusError, getArgusIssueUrl } from "@argus/common/lib";
import cp from "child_process";
import newGithubIssueUrl from "new-github-issue-url";
import open from "open";
import os from "os";
import vscode from "vscode";
Expand All @@ -24,24 +23,11 @@ export const showErrorDialog = async (err: string) => {
log("Failed to call to paste.rs: ", e.toString());
}

const bts = "```";
const logText = logUrl !== null ? `\n**Full log:** ${logUrl}` : ``;
const url = newGithubIssueUrl({
user: "gavinleroy",
repo: "argus",
body: `# Problem
<!-- Please describe the problem and how you encountered it. -->
# Logs
<!-- You don't need to add or change anything below this point. -->
**OS:** ${os.platform()} (${os.release()})
**VSCode:** ${vscode.version}
**Error message**
${bts}
${err}
${bts}
${logText}`,
const url = getArgusIssueUrl(err, {
osPlatform: os.platform(),
osRelease: os.release(),
vscodeVersion: vscode.version,
logText: logUrl !== null ? `\n**Full log:** ${logUrl}` : ``,
});

open(url);
Expand Down
25 changes: 17 additions & 8 deletions ide/packages/extension/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ import {
ObligationsInBody,
} from "@argus/common/bindings";
import {
ConfigConsts,
ErrorJumpTargetInfo,
Filename,
PanoptesConfig,
PanoptesToSystemCmds,
PanoptesToSystemMsg,
SystemToPanoptesCmds,
SystemToPanoptesMsg,
configToString,
isPanoMsgAddHighlight,
isPanoMsgObligations,
isPanoMsgRemoveHighlight,
isPanoMsgTree,
} from "@argus/common/lib";
import { MessageHandlerData } from "@estruyf/vscode";
import _ from "lodash";
import os from "os";
import vscode from "vscode";

import { globals } from "./main";
Expand Down Expand Up @@ -224,6 +228,18 @@ export class View {
)
);

const config: PanoptesConfig = {
type: "VSCODE_BACKING",
data: initialData,
target,
spec: {
osPlatform: os.platform(),
osRelease: os.release(),
vscodeVersion: vscode.version,
},
};
const configStr = configToString(config);

return `
<!DOCTYPE html>
<html lang="en">
Expand All @@ -233,16 +249,9 @@ export class View {
<title>Argus Inspector</title>
<link rel="stylesheet" type="text/css" href=${styleUri}>
<link rel="stylesheet" type="text/css" href=${codiconsUri}>
<script>
(function () {
window.data = ${JSON.stringify(initialData)};
window.target = ${JSON.stringify(target)};
})()
</script>
</head>
<body>
<div id="root"></div>
<div class=${ConfigConsts.EMBED_NAME} data-config=${configStr}></div>
<script src="${scriptUri}"></script>
</body>
</html>
Expand Down
Loading

0 comments on commit 4808203

Please sign in to comment.