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 2 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.1",
"@lezer/common": "^1.2.1",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.4.0",
Expand Down
8 changes: 4 additions & 4 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.1":
version "2.3.0-beta.1"
resolved "https://registry.yarnpkg.com/@dodona/papyros/-/papyros-2.3.0-beta.1.tgz#51471176405a4cdd1c27bde3a3d0c6eac441615d"
integrity sha512-ek2oS9Xu3QG8cNFOlBrwZ4i2b5yLpGJajq57AptYD7UDjwK1FWeJNH4vLcI5NNlRwIdBj9AqE78ZLH/f9U/J7Q==
dependencies:
"@codemirror/autocomplete" "^6.11.1"
"@codemirror/commands" "^6.3.1"
Expand Down