-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.ts
More file actions
46 lines (42 loc) · 1.75 KB
/
main.ts
File metadata and controls
46 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as vscode from 'vscode';
import { startBackend } from './backend/backend';
import * as FileHandler from './FileHandler';
import { Md5 } from 'ts-md5';
import { startFrontend } from './frontend/frontend';
import { traceAlreadyExists } from './trace_cache';
export function getProgFlowVizCallback(context: vscode.ExtensionContext, outChannel: vscode.OutputChannel): () => Promise<void> {
return async () => {
try {
const file = vscode.window.activeTextEditor ?
vscode.window.activeTextEditor.document.uri :
undefined;
if (!file) {
vscode.window.showWarningMessage('No file is open');
return;
}
if (!file.fsPath.endsWith('.py')) {
vscode.window.showWarningMessage('Not a Python file');
return;
}
await vscode.window.activeTextEditor?.document.save();
const content = await FileHandler.getContentOf(file);
const fileHash = Md5.hashStr(content);
let tracePort = null;
if (!(await traceAlreadyExists(context, fileHash))) {
tracePort = startBackend(context, file, outChannel);
}
const result = await startFrontend(context, file.fsPath, fileHash, tracePort);
if (result) {
await vscode.window.showErrorMessage("Error ProgramFlow-Visualization: " + result.errorMessage);
return;
}
} catch (e: any) {
if (e instanceof Error) {
outChannel.appendLine(e.stack?.toString() ?? "Error: <stack undefined>");
} else {
outChannel.appendLine(e);
}
outChannel.show(true);
}
};
}