Skip to content

Commit 1100c52

Browse files
Tweak IDL Machine to improve UX in notebooks
1 parent 2d6c138 commit 1100c52

4 files changed

Lines changed: 44 additions & 10 deletions

File tree

libs/idl/idl-interaction-manager/src/lib/idl-interaction-manager.class.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ export class IDLInteractionManager {
439439
this.idl.removeAllListeners();
440440
}
441441

442+
/**
443+
* Resets information about the call stack so that we are always fresh
444+
*/
445+
async resetCallStack() {
446+
await this.idl.resetCallStack();
447+
}
448+
442449
/**
443450
* Reset errors by file
444451
*/

libs/idl/idl-process/src/lib/idl-process.class.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ export class IDLProcess extends EventEmitter {
239239
this._machine.registerRequestHandler(event, handler);
240240
}
241241

242+
/**
243+
* Resets information about the call stack so that we are always fresh
244+
*/
245+
async resetCallStack() {
246+
/**
247+
* If machine, forget the last place we stopped to trigger a new stop as unexpected
248+
*/
249+
if (this.isIDLMachine()) {
250+
this._machine.lastStop = undefined;
251+
} else {
252+
this.idlInfo = copy(DEFAULT_IDL_INFO);
253+
}
254+
}
255+
242256
/**
243257
* Wraps emitting standard output to make sure all checks happen in one place
244258
*/

libs/idl/idl-process/src/lib/wrappers/idl-machine-wrapper.class.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ const kill = require('tree-kill');
3434
* Wraps the IDL Machine process and connects events from it to/from our IDL Process class
3535
*/
3636
export class IDLMachineWrapper {
37+
/** last debug send */
38+
lastDebugSend: FromIDLMachineNotificationParams<'debugSend'>;
39+
40+
/** Track the last interpreter stopped params */
41+
lastStop: FromIDLMachineNotificationParams<'interpreterStopped'>;
42+
3743
/** Flag that we are expecting a stop or end to command running */
3844
private expectingStop = false;
3945

4046
/** The IDL process */
4147
private idl: ChildProcess;
4248

43-
/** last debug send */
44-
private lastDebugSend: FromIDLMachineNotificationParams<'debugSend'>;
45-
4649
/** The IDL Machine */
4750
private machine: IDLMachine;
4851

@@ -147,15 +150,13 @@ export class IDLMachineWrapper {
147150
}
148151
});
149152

150-
/** Track the last interpreter stopped params */
151-
let lastStop: FromIDLMachineNotificationParams<'interpreterStopped'>;
152-
153153
this.machine.onNotification('interpreterStopped', (params) => {
154154
/** Check if our last stop is different */
155-
const stopDelta = lastStop !== undefined || !deepEqual(params, lastStop);
155+
const stopDelta =
156+
this.lastStop !== undefined || !deepEqual(params, this.lastStop);
156157

157158
// save the parameters
158-
lastStop = params;
159+
this.lastStop = params;
159160

160161
// create output parameters
161162
const res: IDLOutput = {
@@ -169,7 +170,7 @@ export class IDLMachineWrapper {
169170
*/
170171
if (
171172
params.line > 0 &&
172-
(!this.expectingStop || (this.lastDebugSend.stack.changed && stopDelta))
173+
(!this.expectingStop || this.lastDebugSend.stack.changed || stopDelta)
173174
) {
174175
res.stopped = {
175176
reason: 'stop',
@@ -188,7 +189,9 @@ export class IDLMachineWrapper {
188189
// check if we are expecting to stop or not
189190
if (this.expectingStop) {
190191
// emit that IDL is ready
191-
this.process.emit(IDL_EVENT_LOOKUP.PROMPT_READY, res);
192+
setTimeout(() => {
193+
this.process.emit(IDL_EVENT_LOOKUP.PROMPT_READY, res);
194+
}, 10);
192195
} else {
193196
this.process.emit(
194197
IDL_EVENT_LOOKUP.STOP,

libs/vscode/notebooks/client/src/lib/controller/idl-notebook-execution-manager.class.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ export class IDLNotebookExecutionManager {
355355
* Clean things up and get our !magic system variable
356356
*/
357357
await this.evaluate(commands.join(' & '));
358+
359+
// reset the call stack
360+
this.resetCallStack();
358361
}
359362

360363
// remove listener
@@ -733,6 +736,13 @@ export class IDLNotebookExecutionManager {
733736
}
734737
}
735738

739+
/**
740+
* Resets information about the call stack so that we are always fresh
741+
*/
742+
async resetCallStack() {
743+
await this._runtime.resetCallStack();
744+
}
745+
736746
/**
737747
* Stop kernel execution
738748
*/

0 commit comments

Comments
 (0)