Skip to content

Commit

Permalink
FIX: CSE machine does not trigger (#2876)
Browse files Browse the repository at this point in the history
* Initial fix

* Fix test
  • Loading branch information
JoelChanZhiYang authored Mar 25, 2024
1 parent 05bb216 commit 72873e6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/commons/sagas/WorkspaceSaga/helpers/evalCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function* evalCode(
const isLazy: boolean = context.variant === Variant.LAZY;
const isWasm: boolean = context.variant === Variant.WASM;

const lastDebuggerResult = yield select(
let lastDebuggerResult = yield select(
(state: OverallState) => state.workspaces[workspaceLocation].lastDebuggerResult
);

Expand Down Expand Up @@ -215,17 +215,16 @@ export function* evalCode(
yield call(showWarningMessage, 'Execution aborted', 750);
return;
}

if (paused) {
yield put(actions.endDebuggerPause(workspaceLocation));
yield put(actions.updateLastDebuggerResult(manualToggleDebugger(context)));
yield put(actions.updateLastDebuggerResult(manualToggleDebugger(context), workspaceLocation));
yield call(updateInspector, workspaceLocation);
yield call(showWarningMessage, 'Execution paused', 750);
return;
}

if (actionType === EVAL_EDITOR) {
yield put(actions.updateLastDebuggerResult(result));
yield put(actions.updateLastDebuggerResult(result, workspaceLocation));
}

// do not highlight for stories
Expand Down Expand Up @@ -267,7 +266,7 @@ export function* evalCode(
if (result.value === 'cut') {
result.value = undefined;
}
yield put(actions.updateLastNonDetResult(result));
yield put(actions.updateLastNonDetResult(result, workspaceLocation));
}

yield* dumpDisplayBuffer(workspaceLocation, isStoriesBlock, storyEnv);
Expand All @@ -289,6 +288,9 @@ export function* evalCode(
}
}

lastDebuggerResult = yield select(
(state: OverallState) => state.workspaces[workspaceLocation].lastDebuggerResult
);
// For EVAL_EDITOR and EVAL_REPL, we send notification to workspace that a program has been evaluated
if (actionType === EVAL_EDITOR || actionType === EVAL_REPL || actionType === DEBUG_RESUME) {
if (context.errors.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/commons/sagas/WorkspaceSaga/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export default function* WorkspaceSaga(): SagaIterator {
// TODO: Hardcoded to make use of the first editor tab. Rewrite after editor tabs are added.
yield put(actions.setEditorHighlightedLines(workspaceLocation, 0, []));
context.runtime.break = false;
yield put(actions.updateLastDebuggerResult(undefined));
yield put(actions.updateLastDebuggerResult(undefined, workspaceLocation));
});

yield takeEvery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('CSE Machine sets visualization state and renders', async () => {
expect(screen.queryAllByTestId('sa-cse-machine')).toHaveLength(0);

const context = mockContext();
runInContext('const hello="world"; debugger;', context);
await runInContext('const hello="world"; debugger;', context);
act(() => visualizeCseMachine({ context }));

expect(screen.queryAllByTestId('cse-machine-default-text')).toHaveLength(0);
Expand Down
8 changes: 4 additions & 4 deletions src/commons/workspace/WorkspaceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,14 @@ export const updateBreakpointSteps = createAction(

export const updateLastDebuggerResult = createAction(
UPDATE_LAST_DEBUGGER_RESULT,
(lastDebuggerResult: any) => ({
payload: { lastDebuggerResult }
(lastDebuggerResult: any, workspaceLocation: WorkspaceLocation) => ({
payload: { lastDebuggerResult, workspaceLocation }
})
);

export const updateLastNonDetResult = createAction(
UPDATE_LAST_NON_DET_RESULT,
(lastNonDetResult: Result) => ({
payload: { lastNonDetResult }
(lastNonDetResult: Result, workspaceLocation: WorkspaceLocation) => ({
payload: { lastNonDetResult, workspaceLocation }
})
);

0 comments on commit 72873e6

Please sign in to comment.