@dodona/papyros
Version:
Scratchpad for multiple programming languages in the browser.
122 lines • 4.4 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { BackendManager } from "../../communication/BackendManager";
import { BackendEventType } from "../../communication/BackendEvent";
import { State, stateProperty } from "@dodona/lit-state";
import { CODE_TAB, parseFileEntries } from "./InputOutput";
export class Debugger extends State {
set activeFrame(value) {
this._activeFrame = value;
this.validateActiveTab();
}
get activeFrame() {
return this._activeFrame;
}
set active(active) {
this._active = active;
this.reset();
}
get active() {
return this._active;
}
constructor(papyros) {
super();
this.frameStates = [];
this._activeFrame = undefined;
this.trace = [];
this._active = false;
this.fileHistory = [];
this.papyros = papyros;
this.reset();
BackendManager.subscribe(BackendEventType.Start, () => {
this.reset();
});
BackendManager.subscribe(BackendEventType.Files, (e) => {
if (this._active) {
this.fileHistory = [...this.fileHistory, parseFileEntries(e.data, e.contentType)];
}
});
BackendManager.subscribe(BackendEventType.Frame, (e) => {
var _a;
(_a = this.activeFrame) !== null && _a !== void 0 ? _a : (this.activeFrame = 0);
const frame = JSON.parse(e.data);
const frameState = {
line: frame.line,
outputs: this.papyros.io.output.length,
inputs: this.papyros.io.inputs.length,
files: this.fileHistory.length,
};
this.frameStates = [...this.frameStates, frameState];
this.trace = [...this.trace, frame];
if (this.frameStates.length >= this.papyros.constants.maxDebugFrames) {
this.papyros.runner.stop();
}
});
}
reset() {
this.frameStates = [];
this.currentOutputs = 0;
this.currentInputs = 0;
this._activeFrame = undefined;
this.trace = [];
this.fileHistory = [];
}
validateActiveTab() {
const tab = this.papyros.io.activeEditorTab;
if (tab !== CODE_TAB && !this.debugFiles.some((f) => f.name === tab)) {
this.papyros.io.activeEditorTab = CODE_TAB;
}
}
get activeFrameState() {
if (this.activeFrame === undefined) {
return undefined;
}
return this.frameStates[this.activeFrame];
}
get debugLine() {
var _a;
return (_a = this.activeFrameState) === null || _a === void 0 ? void 0 : _a.line;
}
get debugOutputs() {
var _a;
return (_a = this.activeFrameState) === null || _a === void 0 ? void 0 : _a.outputs;
}
get debugUsedInputs() {
var _a;
return (_a = this.activeFrameState) === null || _a === void 0 ? void 0 : _a.inputs;
}
get debugFiles() {
var _a, _b;
const idx = (_a = this.activeFrameState) === null || _a === void 0 ? void 0 : _a.files;
if (idx === undefined || idx === 0) {
return [];
}
return (_b = this.fileHistory[idx - 1]) !== null && _b !== void 0 ? _b : [];
}
}
__decorate([
stateProperty
], Debugger.prototype, "frameStates", void 0);
__decorate([
stateProperty
], Debugger.prototype, "_activeFrame", void 0);
__decorate([
stateProperty
], Debugger.prototype, "activeFrame", null);
__decorate([
stateProperty
], Debugger.prototype, "trace", void 0);
__decorate([
stateProperty
], Debugger.prototype, "_active", void 0);
__decorate([
stateProperty
], Debugger.prototype, "fileHistory", void 0);
__decorate([
stateProperty
], Debugger.prototype, "active", null);
//# sourceMappingURL=Debugger.js.map