Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
RichDom2185 authored Mar 26, 2024
2 parents e43e474 + e804445 commit f11b59b
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"flexboxgrid": "^6.3.1",
"flexboxgrid-helpers": "^1.1.3",
"hastscript": "^9.0.0",
"js-slang": "^1.0.51",
"js-slang": "^1.0.52",
"js-yaml": "^4.1.0",
"konva": "^9.2.0",
"lodash": "^4.17.21",
Expand Down
10 changes: 1 addition & 9 deletions src/commons/application/ApplicationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,6 @@ export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): Wo
isDebugging: false,
enableDebugging: true,
debuggerContext: {} as DebuggerContext,
sideContent: {
alerts: [],
dynamicTabs: []
},
lastDebuggerResult: undefined,
lastNonDetResult: null
});
Expand Down Expand Up @@ -542,11 +538,7 @@ export const createDefaultStoriesEnv = (
stepLimit: 1000,
globals: [],
usingSubst: false,
debuggerContext: {} as DebuggerContext,
sideContent: {
dynamicTabs: [],
alerts: []
}
debuggerContext: {} as DebuggerContext
});

export const defaultFileSystem: FileSystemState = {
Expand Down
3 changes: 2 additions & 1 deletion src/commons/mocks/ContextMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export function mockRuntimeContext(): Context {
control: null,
stash: null,
envStepsTotal: 0,
breakpointSteps: []
breakpointSteps: [],
changepointSteps: []
};
return context;
}
Expand Down
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
11 changes: 7 additions & 4 deletions src/commons/sideContent/SideContentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,30 @@ const requireProvider = (x: string) => {
return exports[x];
};

type RawTab = (provider: ReturnType<typeof requireProvider>) => ModuleSideContent;
type RawTab = (provider: ReturnType<typeof requireProvider>) => { default: ModuleSideContent };

/**
* Returns an array of SideContentTabs to be spawned
* @param debuggerContext - DebuggerContext object from redux store
*/
export const getDynamicTabs = (debuggerContext: DebuggerContext): SideContentTab[] => {
export function getDynamicTabs(debuggerContext: DebuggerContext): SideContentTab[] {
const moduleContexts = debuggerContext?.context?.moduleContexts;

if (!moduleContexts) return [];

return Object.values(moduleContexts)
.flatMap(({ tabs }) => tabs ?? [])
.map((rawTab: RawTab) => rawTab(requireProvider))
.map((rawTab: RawTab) => {
const { default: content } = rawTab(requireProvider);
return content;
})
.filter(({ toSpawn }) => !toSpawn || toSpawn(debuggerContext))
.map(tab => ({
...tab,
body: tab.body(debuggerContext),
id: SideContentType.module
}));
};
}

export const generateIconId = (tabId: TabId) => `${tabId}-icon`;
export const getTabId = (tab: SideContentTab) =>
Expand Down
3 changes: 1 addition & 2 deletions src/commons/sideContent/SideContentReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { defaultSideContent, defaultSideContentManager } from '../application/Ap
import { SourceActionType } from '../utils/ActionsHelper';
import { getDynamicTabs, getTabId } from './SideContentHelper';
import { getLocation } from './SideContentHelper';
import { CHANGE_SIDE_CONTENT_HEIGHT } from './SideContentTypes';
import { CHANGE_SIDE_CONTENT_HEIGHT, SPAWN_SIDE_CONTENT } from './SideContentTypes';
import {
END_ALERT_SIDE_CONTENT,
REMOVE_SIDE_CONTENT_ALERT,
RESET_SIDE_CONTENT,
SideContentManagerState,
SPAWN_SIDE_CONTENT,
VISIT_SIDE_CONTENT
} from './SideContentTypes';

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 @@ -511,14 +511,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 }
})
);
2 changes: 0 additions & 2 deletions src/commons/workspace/WorkspaceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { InterpreterOutput } from '../application/ApplicationTypes';
import { ExternalLibraryName } from '../application/types/ExternalTypes';
import { AutogradingResult, Testcase } from '../assessment/AssessmentTypes';
import { HighlightedLines, Position } from '../editor/EditorTypes';
import { SideContentState } from '../sideContent/SideContentTypes';

export const ADD_HTML_CONSOLE_ERROR = 'ADD_HTML_CONSOLE_ERROR';
export const BEGIN_CLEAR_CONTEXT = 'BEGIN_CLEAR_CONTEXT';
Expand Down Expand Up @@ -163,7 +162,6 @@ export type WorkspaceState = {
readonly stepLimit: number;
readonly globals: Array<[string, any]>;
readonly debuggerContext: DebuggerContext;
readonly sideContent: SideContentState;
readonly lastDebuggerResult: any;
readonly lastNonDetResult: Result | null;
};
Expand Down
2 changes: 1 addition & 1 deletion src/features/cseMachine/CseMachineUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UnOpInstr
} from 'js-slang/dist/cse-machine/types';
import { Environment, Value as StashValue } from 'js-slang/dist/types';
import { astToString } from 'js-slang/dist/utils/astToString';
import { astToString } from 'js-slang/dist/utils/ast/astToString';
import { Group } from 'konva/lib/Group';
import { Node } from 'konva/lib/Node';
import { Shape } from 'konva/lib/Shape';
Expand Down
2 changes: 0 additions & 2 deletions src/features/stories/StoriesTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Context } from 'js-slang';
import { SideContentState } from 'src/commons/sideContent/SideContentTypes';
import { DebuggerContext } from 'src/commons/workspace/WorkspaceTypes';

import { InterpreterOutput, StoriesRole } from '../../commons/application/ApplicationTypes';
Expand Down Expand Up @@ -60,7 +59,6 @@ export type StoriesEnvState = {
readonly globals: Array<[string, any]>;
readonly usingSubst: boolean;
readonly debuggerContext: DebuggerContext;
readonly sideContent: SideContentState;
};

export type StoriesAuthState = {
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'src/styles/index.scss';

import { Button } from '@blueprintjs/core';
import * as Sentry from '@sentry/browser';
import { setModulesStaticURL } from 'js-slang/dist/modules/moduleLoader';
import { setModulesStaticURL } from 'js-slang/dist/modules/loader/moduleLoader';
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import Constants, { Links } from 'src/commons/utils/Constants';
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8563,10 +8563,10 @@ [email protected], js-sdsl@^4.1.4:
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.3.0.tgz#aeefe32a451f7af88425b11fdb5f58c90ae1d711"
integrity sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==

js-slang@^1.0.51:
version "1.0.51"
resolved "https://registry.yarnpkg.com/js-slang/-/js-slang-1.0.51.tgz#254ec52f4db29a8f51276cf681cf2608698337cf"
integrity sha512-UmoWDfcgwxG86s+Q7y9BxU8PcPnyyTs6jgVK77luaGqMy+kDKwwNqajjIOmd3thVOouAj2U1llAjVT1oZtmCLw==
js-slang@^1.0.52:
version "1.0.52"
resolved "https://registry.yarnpkg.com/js-slang/-/js-slang-1.0.52.tgz#f24d504e09842fc6567789b45e8c9fc3a86a38d3"
integrity sha512-Ioe/XQFxAwZpDGNsg8MDKbC/0CvLXN+0mwhKrtm2jq6PHGa9oldZqykZZAlPYdC5XifI3DktKrRmuc94AIiKfA==
dependencies:
"@babel/parser" "^7.19.4"
"@joeychenofficial/alt-ergo-modified" "^2.4.0"
Expand Down

0 comments on commit f11b59b

Please sign in to comment.