Skip to content

Commit

Permalink
Merge pull request #5366 from dodona-edu/enhance/improve-debug-state
Browse files Browse the repository at this point in the history
Add debug state to papyros editor
  • Loading branch information
jorg-vr authored Feb 21, 2024
2 parents 32ad62a + c60c914 commit e8626db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
28 changes: 9 additions & 19 deletions app/assets/javascripts/coding_scratchpad.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { BackendManager, CodeEditor, InputMode, Papyros, ProgrammingLanguage } from "@dodona/papyros";
import { CodeEditor, InputMode, Papyros, ProgrammingLanguage } from "@dodona/papyros";
import { themeState } from "state/Theme";
import { EditorView } from "@codemirror/view";
import { rougeStyle, setCode } from "editor";
import { syntaxHighlighting } from "@codemirror/language";
import { i18n } from "i18n/i18n";
import { BackendEventType } from "@dodona/papyros/dist/BackendEvent";
import { Tab } from "bootstrap";

/** Identifiers used in HTML for relevant elements */
Expand Down Expand Up @@ -96,26 +95,17 @@ export async function initPapyros(programmingLanguage: ProgrammingLanguage): Pro
fallback: true
})]);

// Hide Trace tab when a new run is started
BackendManager.subscribe(BackendEventType.Start, () => {
papyros.codeRunner.addEventListener("debug-mode", (event: CustomEvent<boolean>) => {
const debugMode = event.detail;
const traceTab = document.getElementById(TRACE_TAB_ID);
if (traceTab) {
traceTab.classList.add("hidden");
const descriptionTab = document.getElementById(DESCRIPTION_TAB_ID);
if (descriptionTab) {
const tabTrigger = new Tab(descriptionTab.querySelector("a"));
tabTrigger.show();
}
}
});

// Show Trace tab when a new frame is added
BackendManager.subscribe(BackendEventType.Frame, () => {
const traceTab = document.getElementById(TRACE_TAB_ID);
if (traceTab) {
traceTab.classList.remove("hidden");
traceTab.classList.toggle("hidden", !debugMode);
if (debugMode) {
const tabTrigger = new Tab(traceTab.querySelector("a"));
tabTrigger.show();
} else {
const descriptionTab = document.getElementById(DESCRIPTION_TAB_ID);
const tabTrigger = new Tab(descriptionTab.querySelector("a"));
tabTrigger.show();
}
});
}
Expand Down
10 changes: 1 addition & 9 deletions app/assets/javascripts/tutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ export function initTutor(submissionCode: string): void {
async function loadTutor(exerciseId: string, studentCode: string, statements: string, stdin: string, inlineFiles: Record<string, string>, hrefFiles: Record<string, string>): Promise<void> {
const papyros = await initPapyros(ProgrammingLanguage.Python);

if (papyros.codeRunner.getState() !== RunState.Ready && papyros.codeRunner.getState() !== RunState.Loading) {
// stop the code runner if it is running
await papyros.codeRunner.stop();

// wait to make sure the code runner is stopped
while (papyros.codeRunner.getState() === RunState.Stopping) {
await new Promise(resolve => setTimeout(resolve, 100));
}
}
await papyros.codeRunner.reset();

papyros.setCode(studentCode);
papyros.codeRunner.inputManager.setInputMode(InputMode.Batch);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@codemirror/language-data": "^6.4.1",
"@codemirror/state": "^6.3.3",
"@codemirror/view": "^6.24.0",
"@dodona/papyros": "2.2.0",
"@dodona/papyros": "2.3.2",
"@lezer/common": "^1.2.1",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.4.0",
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1327,10 +1327,10 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@dodona/papyros@2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@dodona/papyros/-/papyros-2.2.0.tgz#eb80c8d9263c7e8cefbf55661b884736f02bf892"
integrity sha512-DGXKWegvOMWEGhxNoYVwNkWwF3Y+odWc8is6qiLlETKCh78rvw5fUlb0mGhWRw7VPZANxAOqXa4O9royJnp5YQ==
"@dodona/papyros@2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@dodona/papyros/-/papyros-2.3.2.tgz#4572f1a7a70a4c0b731bc5d0d116e364e198af34"
integrity sha512-rCQYQxggtlWEPkj8srGYlJFX+dKH4JTJAEUeU4N+35bN3VfATdscLaqHd/kLRoM6fUsbl9IZRWsn7GIRSjI4OQ==
dependencies:
"@codemirror/autocomplete" "^6.11.1"
"@codemirror/commands" "^6.3.1"
Expand All @@ -1349,7 +1349,7 @@
comsync "^0.0.9"
escape-html "^1.0.3"
file-loader "^6.2.0"
i18n-js "4.4.0"
i18n-js "4.4.3"
pyodide "^0.22.0"
pyodide-worker-runner "1.3.2"
sync-message "^0.0.12"
Expand Down Expand Up @@ -4858,10 +4858,10 @@ human-signals@^1.1.1:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==

i18n-js@4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-4.4.0.tgz#fddb46ea7dec8fbdb20176a7d89f0b2dba5035d5"
integrity sha512-nAOY1z+lPX4dCEUbl9Uw7JtrJFRDjQm7XLk5Lf8iQYFOwZ0yA//jzp42r+OwOt7SazUkYr55R6Dt9ziQGUlxFQ==
i18n-js@4.4.3:
version "4.4.3"
resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-4.4.3.tgz#09744ddd377261f614502cc5622ce6981026ea4a"
integrity sha512-QIIyvJ+wOKdigL4BlgwiFFrpoXeGdlC8EYgori64YSWm1mnhNYYjIfRu5wETFrmiNP2fyD6xIjVG8dlzaiQr/A==
dependencies:
bignumber.js "*"
lodash "*"
Expand Down

0 comments on commit e8626db

Please sign in to comment.