Skip to content

Commit

Permalink
Merge branch 'master' into hotkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz committed Jun 21, 2021
2 parents 46b9480 + bed351d commit 6e165b1
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 358 deletions.
227 changes: 0 additions & 227 deletions public/externalLibs/inspector/inspector.js
Original file line number Diff line number Diff line change
@@ -1,225 +1,4 @@
(function (exports) {
var container = document.createElement('div');
container.id = 'inspector-container';

const builtins = [
'Infinity',
'NaN',
'accumulate',
'alert',
'append',
'apply_in_underlying_javascript',
'array_length',
'assoc',
'black',
'blue',
'brown',
'build_list',
'build_stream',
'color',
'display',
'display_list',
'draw_data',
'enum_list',
'enum_stream',
'equal',
'error',
'eval_stream',
'filter',
'for_each',
'get_time',
'green',
'has_own_property',
'head',
'indigo',
'integers_from',
'is',
'is_NaN',
'is_array',
'is_boolean',
'is_function',
'is_list',
'is_null',
'is_number',
'is_object',
'is_pair',
'is_stream',
'is_string',
'is_undefined',
'length',
'list',
'list_ref',
'list_to_stream',
'list_to_string',
'map',
'math_E',
'math_LN10',
'math_LN2',
'math_LOG10E',
'math_LOG2E',
'math_PI',
'math_SQRT1_2',
'math_SQRT2',
'math_abs',
'math_acos',
'math_acosh',
'math_asin',
'math_asinh',
'math_atan',
'math_atan2',
'math_atanh',
'math_cbrt',
'math_ceil',
'math_clz32',
'math_cos',
'math_cosh',
'math_exp',
'math_expm1',
'math_floor',
'math_fround',
'math_hypot',
'math_imul',
'math_log',
'math_log10',
'math_log1p',
'math_log2',
'math_max',
'math_min',
'math_pow',
'math_random',
'math_round',
'math_sign',
'math_sin',
'math_sinh',
'math_sqrt',
'math_tan',
'math_tanh',
'math_toSource',
'math_trunc',
'member',
'orange',
'pair',
'parse',
'parse_int',
'pink',
'prompt',
'purple',
'quarter_turn_left',
'quarter_turn_right',
'random_color',
'raw_display',
'red',
'remove',
'remove_all',
'reverse',
'rotate',
'runtime',
'scale',
'scale_independent',
'set_head',
'set_tail',
'show',
'stack',
'stack_frac',
'stackn',
'stream',
'stream_append',
'stream_filter',
'stream_for_each',
'stream_length',
'stream_map',
'stream_member',
'stream_ref',
'stream_remove',
'stream_remove_all',
'stream_reverse',
'stream_tail',
'stream_to_list',
'stringify',
'tail',
'translate',
'undefined',
'white',
'yellow'
];

function filter(str) {
// regex to match: replacement for match
swapTable = {
programEnvironment: 'Program',
forLoopEnvironment: 'Body of <code>for</code>',
forBlockEnvironment: 'Control statement of <code>for</code>',
blockEnvironment: 'Block',
'[.]* => [.]*': ' => ',
'{[\\s\\S]*}': '{...}',
'Symbol.*': '-'
};
for (var r in swapTable) {
str = str.replace(new RegExp(r), swapTable[r]);
}
return str;
}

function updateContext(context, stringify) {
// Hides the default text
const defaultText = document.getElementById('inspector-default-text');
if (defaultText) {
defaultText.hidden = true;
}

function dumpTable(env) {
var res = '';
for (var k in env) {
if (builtins.indexOf('' + k) < 0) {
var str = filter(stringify(env[k]));
res +=
'<tr><td class="inspect-table-obj-name">' +
k +
'</td>' +
'<td class="inspect-table-obj-details"><code>' +
filter(str) +
'</code></td></tr>';
}
}
return res.length > 0 ? res : undefined;
}

function drawOutput() {
var frames = context.context.runtime.environments;
container.innerHTML = '';
for (var frame of frames) {
var envtoString = dumpTable(frame.head);
if (envtoString == undefined) {
// skipping either empty frame or perhaps the global
continue;
}
var newtable = document.createElement('table');
newtable.classList.add('inspect-scope-table');
newtable.innerHTML = '<colgroup><col width="20%"><col width="80%"></colgroup>';
var tbody = document.createElement('tbody');
tbody.innerHTML =
'</br><caption><strong>' + filter(frame.name) + '</strong></caption>' + envtoString;
newtable.appendChild(tbody);
container.appendChild(newtable);
}
}

// icon to blink
const icon = document.getElementById('inspector-icon');

if (context) {
drawOutput();
if (icon) {
icon.classList.add('side-content-tab-alert'); // this blinks the icon
}
} else if (icon) {
// here we have no context! don't alert the inspector...
document.getElementById('inspector-default-text').hidden = false;
icon.classList.remove('side-content-tab-alert');
container.innerHTML = '';
}
}

function highlightClean() {
var gutterCells = document.getElementsByClassName('ace_gutter-cell');
var aceLines = document.getElementsByClassName('ace_line');
Expand All @@ -241,12 +20,6 @@
}

exports.Inspector = {
builtins,
filter,
init: function (parent) {
parent.appendChild(container);
},
updateContext,
highlightLine,
highlightClean
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const MobileSideContent: React.FC<MobileSideContentProps & OwnProps> = props =>
* would force React.useMemo to recompute the nullary function anyway
*/
const renderedPanels = () => {
// TODO: Fix the CSS of all the panels (e.g. subst_visualizer, inspector, etc.)
// TODO: Fix the CSS of all the panels (e.g. subst_visualizer)
const renderPanel = (tab: SideContentTab, workspaceLocation?: WorkspaceLocation) => {
const tabBody: JSX.Element = workspaceLocation
? {
Expand Down Expand Up @@ -175,7 +175,7 @@ const MobileSideContent: React.FC<MobileSideContentProps & OwnProps> = props =>
/**
* Remove the 'side-content-tab-alert' class that causes tabs flash.
* To be run when tabs are changed.
* Currently this style is only used for the "Inspector" and "Env Visualizer" tabs.
* Currently this style is only used for the "Env Visualizer" tab.
*/
const resetAlert = (prevTabId: TabId) => {
const iconId = generateIconId(prevTabId);
Expand Down
7 changes: 0 additions & 7 deletions src/commons/sagas/WorkspaceSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {
getRestoreExtraMethodsString,
getStoreExtraMethodsString,
highlightLine,
inspectorUpdate,
makeElevatedContext,
visualizeEnv
} from '../utils/JsSlangHelper';
Expand Down Expand Up @@ -278,7 +277,6 @@ export default function* WorkspaceSaga(): SagaIterator {
const workspaceLocation = action.payload.workspaceLocation;
context = yield select((state: OverallState) => state.workspaces[workspaceLocation].context);
yield put(actions.clearReplOutput(workspaceLocation));
inspectorUpdate(undefined);
highlightLine(undefined);
yield put(actions.clearReplOutput(workspaceLocation));
context.runtime.break = false;
Expand Down Expand Up @@ -564,7 +562,6 @@ function* updateInspector(workspaceLocation: WorkspaceLocation): SagaIterator {
const start = lastDebuggerResult.context.runtime.nodes[0].loc.start.line - 1;
const end = lastDebuggerResult.context.runtime.nodes[0].loc.end.line - 1;
yield put(actions.highlightEditorLine([start, end], workspaceLocation));
inspectorUpdate(lastDebuggerResult);
visualizeEnv(lastDebuggerResult);
} catch (e) {
yield put(actions.highlightEditorLine([], workspaceLocation));
Expand Down Expand Up @@ -613,10 +610,6 @@ export function* evalCode(
): SagaIterator {
context.runtime.debuggerOn =
(actionType === EVAL_EDITOR || actionType === DEBUG_RESUME) && context.chapter > 2;
if (!context.runtime.debuggerOn && context.chapter > 2 && actionType !== EVAL_SILENT) {
// Interface not guaranteed to exist, e.g. mission editor.
inspectorUpdate(undefined); // effectively resets the interface
}

// Logic for execution of substitution model visualizer
const correctWorkspace = workspaceLocation === 'playground' || workspaceLocation === 'sicp';
Expand Down
1 change: 0 additions & 1 deletion src/commons/sagas/__tests__/WorkspaceSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function generateDefaultState(
beforeEach(() => {
// Mock the inspector
(window as any).Inspector = jest.fn();
(window as any).Inspector.updateContext = jest.fn();
(window as any).Inspector.highlightClean = jest.fn();
(window as any).Inspector.highlightLine = jest.fn();
});
Expand Down
2 changes: 1 addition & 1 deletion src/commons/sideContent/SideContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const SideContent = (props: SideContentProps) => {
/**
* Remove the 'side-content-tab-alert' class that causes tabs flash.
* To be run when tabs are changed.
* Currently this style is only used for the "Inspector" and "Env Visualizer" tabs.
* Currently this style is only used for the "Env Visualizer" tab.
*/
const resetAlert = (prevTabId: TabId) => {
const iconId = generateIconId(prevTabId);
Expand Down
54 changes: 0 additions & 54 deletions src/commons/sideContent/SideContentInspector.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/commons/sideContent/SideContentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export enum SideContentType {
envVisualizer = 'env_visualizer',
grading = 'grading',
introduction = 'introduction',
inspector = 'inspector',
module = 'module',
questionOverview = 'question_overview',
remoteExecution = 'remote_execution',
Expand Down
8 changes: 0 additions & 8 deletions src/commons/utils/JsSlangHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ export function highlightLine(line: number | undefined) {
}
}

export function inspectorUpdate(context: Context | undefined) {
if ((window as any).Inspector) {
(window as any).Inspector.updateContext(context, stringify);
} else {
throw new Error('Inspector not loaded');
}
}

export const externalBuiltIns = {
display,
rawDisplay,
Expand Down
Loading

0 comments on commit 6e165b1

Please sign in to comment.