Skip to content

Commit b6f2c05

Browse files
Fix IDL Machine to detect unexpected stops
1 parent 214d6e3 commit b6f2c05

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ export class IDLInteractionManager {
360360
* Let's us know if we are the IDL Machine or not
361361
*/
362362
isIDLMachine() {
363-
return this.idl.processType !== 'stdio';
363+
return this.idl.isIDLMachine();
364364
}
365365

366366
/**

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ export class IDLProcess extends EventEmitter {
171171
return res.idlOutput;
172172
}
173173

174+
/**
175+
* Let's us know if we are the IDL Machine or not
176+
*/
177+
isIDLMachine() {
178+
return this.processType === 'machine';
179+
}
180+
174181
/**
175182
* Wraps node.js event emitter with types for supported events and
176183
* event data.
@@ -241,6 +248,11 @@ export class IDLProcess extends EventEmitter {
241248
this.emit(IDL_EVENT_LOOKUP.STANDARD_OUT, data);
242249
}
243250

251+
// do not check output for a stop and return
252+
if (this.isIDLMachine()) {
253+
return;
254+
}
255+
244256
/**
245257
* If we are not evaluating a statement, then do a stop check
246258
*

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ 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+
/** Flag that we are expecting a stop or end to command running */
38+
private expectingStop = false;
39+
3740
/** The IDL process */
3841
private idl: ChildProcess;
3942

@@ -161,8 +164,13 @@ export class IDLMachineWrapper {
161164

162165
/**
163166
* See if we need to emit a stop event
167+
*
168+
* debugSend comes before this event
164169
*/
165-
if (this.lastDebugSend.stack.changed && params.line > 0 && stopDelta) {
170+
if (
171+
params.line > 0 &&
172+
(!this.expectingStop || (this.lastDebugSend.stack.changed && stopDelta))
173+
) {
166174
res.stopped = {
167175
reason: 'stop',
168176
stack: {
@@ -177,8 +185,17 @@ export class IDLMachineWrapper {
177185
};
178186
}
179187

180-
// emit that IDL is ready
181-
this.process.emit(IDL_EVENT_LOOKUP.PROMPT_READY, res);
188+
// check if we are expecting to stop or not
189+
if (this.expectingStop) {
190+
// emit that IDL is ready
191+
this.process.emit(IDL_EVENT_LOOKUP.PROMPT_READY, res);
192+
} else {
193+
this.process.emit(
194+
IDL_EVENT_LOOKUP.STOP,
195+
res.stopped.reason,
196+
res.stopped.stack
197+
);
198+
}
182199
});
183200

184201
this.machine.onNotification('modalMessage', () => {
@@ -456,9 +473,13 @@ export class IDLMachineWrapper {
456473

457474
// listen for our event returning back to the command prompt
458475
this.process.once(IDL_EVENT_LOOKUP.PROMPT_READY, async (idlOutput) => {
476+
this.expectingStop = false;
459477
resolve(idlOutput);
460478
});
461479

480+
// update flag that we are expecting an answer
481+
this.expectingStop = true;
482+
462483
// run it!
463484
this.machine.sendNotification('exec', {
464485
string: command,

0 commit comments

Comments
 (0)