Skip to content

Commit

Permalink
fix: immediately log stdout/err unless EXT is encountered
Browse files Browse the repository at this point in the history
Previously when supporting EXT we added per-line splitting and emitting,
but we actually should just reemit things immediately unless we see
an EXT.

Fixes microsoft/vscode#181785
  • Loading branch information
connor4312 committed Jul 31, 2023
1 parent df0247e commit e059f67
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 22 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"signale": "^1.4.0",
"source-map": "0.8.0-beta.0",
"source-map-support": "^0.5.21",
"split2": "^4.1.0",
"split2": "^4.2.0",
"to-absolute-glob": "^2.0.2",
"vscode-tas-client": "^0.1.42",
"ws": "^8.5.0"
Expand Down Expand Up @@ -118,7 +118,7 @@
"@types/prettier": "^2.4.4",
"@types/signale": "^1.4.4",
"@types/sinon": "^10.0.11",
"@types/split2": "^3.2.1",
"@types/split2": "^4.2.0",
"@types/stream-buffers": "^3.0.4",
"@types/tmp": "^0.2.3",
"@types/to-absolute-glob": "^2.0.1",
Expand Down
13 changes: 7 additions & 6 deletions src/targets/node/subprocessProgramLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ const formatArguments = (executable: string, args: ReadonlyArray<string>, cwd: s

const enum Char {
ETX = '\u0003',
LF = '\n',
}

/**
Expand All @@ -173,15 +172,17 @@ export class EtxSplitter {
private etxSpotted = false;

public static stream(): Transform {
// needs https://github.com/mcollina/split2/pull/59 and DT update
// to be done without workarounds
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (split as any)(new EtxSplitter(), undefined, undefined);
return split(new EtxSplitter());
}

[Symbol.split](str: string) {
this.etxSpotted ||= str.includes(Char.ETX);
const split = str.split(this.etxSpotted ? Char.ETX : Char.LF);
if (!this.etxSpotted) {
return [str, ''];
}

const split = str.split(Char.ETX);

// restore or add new lines between each record for proper debug console display
return split.length > 1 ? split.map((s, i) => (i < split.length - 1 ? `${s}\n` : s)) : split;
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/console/console-format-ext-handling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{"category":"stdout","output":"hello"}
{"category":"stdout","output":"world"}
{"category":"stdout","output":"new line\nasdf"}
{"category":"stdout","output":"now ext\n"}
{"category":"stdout","output":"this should be bulkedwith this!\n"}
{"category":"stderr","output":"Waiting for the debugger to disconnect...\n"}
{"category":"stdout","output":"trailing"}
38 changes: 38 additions & 0 deletions src/test/console/consoleFormatTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import { OutputSource } from '../../configuration';
import { createFileTree } from '../createFileTree';
import { testFixturesDir } from '../test';
import { itIntegrates } from '../testIntegrationUtils';

describe('console format', () => {
Expand Down Expand Up @@ -455,4 +458,39 @@ describe('console format', () => {
handle.log(`logged ${output.output} at ${output.source?.name}:${output.line}:${output.column}`);
handle.assertLog();
});

itIntegrates('EXT handling', async ({ r }) => {
createFileTree(testFixturesDir, {
'test.js': [
`
process.stdout.write('hello');
debugger;
process.stdout.write('world');
debugger;
process.stdout.write('new line\\r\\nasdf');
debugger;
process.stdout.write('now ext\\u0003this should be bulked');
debugger;
process.stdout.write('with this!\\u0003trailing');
`,
],
});
const handle = await r.runScript('test.js', { outputCapture: OutputSource.Stdio });
let todo = Promise.resolve();
r.rootDap().on('output', o => {
todo = todo.then(() => handle.log(JSON.stringify(o)));
});

// use debugger statements to sync chunks of output
handle.dap.on('stopped', ev => {
todo = todo.then(() => {
handle.dap.continue({ threadId: ev.threadId! });
});
});

await handle.load();
await r.rootDap().once('terminated');
await todo;
handle.assertLog();
});
});

0 comments on commit e059f67

Please sign in to comment.