Skip to content

Commit 25c53a8

Browse files
committed
record variable names as outputKeys json string array
1 parent 8399b2f commit 25c53a8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/nodeKernel.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class NodeKernel {
1313
private nodeRuntime: cp.ChildProcess | undefined;
1414
private outputBuffer = ''; // collect output here
1515
private hasRuntimeError = false;
16+
private outputKeys = '';
1617
private tmpDirectory?: string;
1718

1819
public async start() {
@@ -32,6 +33,9 @@ export class NodeKernel {
3233
} else if (dataStr.includes('\nUncaught')) {
3334
this.hasRuntimeError = true;
3435
this.outputBuffer += dataStr;
36+
} else if (dataStr.includes('#keys#')) {
37+
this.outputKeys = dataStr.substring(7);
38+
console.log('outputKeys ======', this.outputKeys);
3539
} else {
3640
this.outputBuffer += dataStr;
3741
}
@@ -53,12 +57,19 @@ export class NodeKernel {
5357
const cellPath = cell.document.languageId === 'xpath' ? this.dumpCell(cell) : this.dumpCell(cell); // TODO: dumpJSCell
5458
if (cellPath && this.nodeRuntime && this.nodeRuntime.stdin) {
5559
this.outputBuffer = '';
60+
this.outputKeys = '';
5661
this.hasRuntimeError = false;
5762

5863
this.nodeRuntime.stdin.write(`.load ${cellPath}\n`);
5964
while (this.outputBuffer === '') {
6065
await this.sleep(100);
6166
}
67+
if (!this.hasRuntimeError) {
68+
this.nodeRuntime.stdin.write(`globalVariables.getKeysJSON()\n`);
69+
while (this.outputKeys === '') {
70+
await this.sleep(100);
71+
}
72+
}
6273

6374
if (this.hasRuntimeError) {
6475
return Promise.reject(this.outputBuffer);
@@ -173,6 +184,9 @@ console.log(prevResult);
173184
getKeys = () => {
174185
return this.keys;
175186
}
187+
getKeysJSON = () => {
188+
return '#keys#' + JSON.stringify(this.keys);
189+
}
176190
getVariables = () => {
177191
return this.variables;
178192
}

0 commit comments

Comments
 (0)