-
Notifications
You must be signed in to change notification settings - Fork 9
/
errors.ts
38 lines (33 loc) · 1.07 KB
/
errors.ts
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
import * as vscode from "vscode";
import { debug } from "./utils";
import { Execution } from "./primitives";
/**
* Check if the execution failed and show relevant error.
* Run after preRun.
*
* @param code Code to compile
* @param path Path of the problem
* @param execution Execution result
*/
export function onCompilationError(code: string, execution: Execution) {
debug("compile-error", `Compilation error ${code}`);
vscode.window.showErrorMessage(`Compilation Error. ${code}`);
showCompileError(execution.stderr().toString("utf8"));
}
export function showCompileError(compileError: string) {
const writeEmitter = new vscode.EventEmitter<string>();
const pty = {
onDidWrite: writeEmitter.event,
open: () => writeEmitter.fire(`${compileError.replace(/\n/g, "\n\r")}`),
};
vscode.window.terminals.forEach((value) => {
if (value.name === "CompileError") {
value.dispose();
}
});
const target = (<any>vscode.window).createTerminal({
name: "CompileError",
pty,
});
target.show();
}