Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug state to papyros editor #5366

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";

Check warning on line 1 in app/assets/javascripts/coding_scratchpad.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/coding_scratchpad.ts#L1

Added line #L1 was not covered by tests
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 @@
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 @@
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();

Check warning on line 52 in app/assets/javascripts/tutor.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/tutor.ts#L52

Added line #L52 was not covered by tests

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.0-beta.5",
"@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.0-beta.5":
version "2.3.0-beta.5"
resolved "https://registry.yarnpkg.com/@dodona/papyros/-/papyros-2.3.0-beta.5.tgz#61b6401a1983e6cf41992327fc3381cec8a529db"
integrity sha512-3qedP+GpV23nU1c63mApsNqCPwjK7p5YwNRMZRjVNF0CV/39+tWrRNGXSqF4Fgq6qWGCR8dhWBanuo0dKZUvEA==
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