Skip to content

Commit a76b3cc

Browse files
CopilotTheLarkInn
andcommitted
Refactor outputMarker to only extract from output, not construct command
Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>
1 parent 82b974e commit a76b3cc

3 files changed

Lines changed: 16 additions & 27 deletions

File tree

vscode-extensions/debug-certificate-manager-vscode-extension/src/extension.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,15 @@ export function activate(context: vscode.ExtensionContext): void {
207207
let homeDir: string;
208208

209209
if (vscode.env.remoteName) {
210+
const markerPrefix: string = '<<<HOMEDIR_START>>>';
211+
const markerSuffix: string = '<<<HOMEDIR_END>>>';
210212
homeDir = await runWorkspaceCommandAsync({
211213
terminalOptions: { name: 'debug-certificate-manager', hideFromUser: true },
212-
commandLine: '',
214+
commandLine: `node -p "'${markerPrefix}' + require('os').homedir() + '${markerSuffix}'"`,
213215
terminal,
214216
outputMarker: {
215-
expression: "require('os').homedir()",
216-
prefix: '<<<HOMEDIR_START>>>',
217-
suffix: '<<<HOMEDIR_END>>>'
217+
prefix: markerPrefix,
218+
suffix: markerSuffix
218219
}
219220
});
220221
terminal.writeLine(`Running command to resolve home directory: ${homeDir}`);

vscode-extensions/playwright-local-browser-server-vscode-extension/src/extension.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ async function writeExtensionInstalledFileAsync(terminal: ITerminal): Promise<vo
4545
let tempDir: string;
4646

4747
if (vscode.env.remoteName) {
48+
const markerPrefix: string = '<<<TEMPDIR_START>>>';
49+
const markerSuffix: string = '<<<TEMPDIR_END>>>';
4850
tempDir = await runWorkspaceCommandAsync({
4951
terminalOptions: { name: 'playwright-local-browser-server', hideFromUser: true },
50-
commandLine: '',
52+
commandLine: `node -p "'${markerPrefix}' + require('node:os').tmpdir() + '${markerSuffix}'"`,
5153
terminal,
5254
outputMarker: {
53-
expression: "require('node:os').tmpdir()",
54-
prefix: '<<<TEMPDIR_START>>>',
55-
suffix: '<<<TEMPDIR_END>>>'
55+
prefix: markerPrefix,
56+
suffix: markerSuffix
5657
}
5758
});
5859

vscode-extensions/vscode-shared/src/runWorkspaceCommandAsync.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ import { stripVTControlCharacters } from 'node:util';
77

88
/**
99
* Options for extracting a specific value from the command output using markers.
10-
* When provided, the command will be wrapped with the specified markers, and only
11-
* the content between them will be returned. This is useful for extracting specific
10+
* When provided, the function will search for the markers in the command output and
11+
* return only the content between them. This is useful for extracting specific
1212
* values from shell output that may contain additional noise.
1313
*/
1414
export interface IOutputMarkerOptions {
15-
/**
16-
* The expression to evaluate and wrap with markers. This will be inserted between
17-
* the prefix and suffix markers in the command output.
18-
*/
19-
expression: string;
2015
/**
2116
* The prefix marker used to identify the start of the desired output.
2217
*/
@@ -37,19 +32,11 @@ export async function runWorkspaceCommandAsync({
3732
commandLine: string;
3833
terminal: ITerminal;
3934
/**
40-
* Optional marker options for extracting specific output. When provided, the
41-
* commandLine is constructed as: `node -p "'${prefix}' + ${expression} + '${suffix}'"`
42-
* and the returned output will be only the content between the markers.
35+
* Optional marker options for extracting specific output from the command result.
36+
* When provided, the returned output will be only the content between the markers.
4337
*/
4438
outputMarker?: IOutputMarkerOptions;
4539
}): Promise<string> {
46-
// If outputMarker is provided, construct the command with markers
47-
let effectiveCommandLine: string;
48-
if (outputMarker) {
49-
effectiveCommandLine = `node -p "'${outputMarker.prefix}' + ${outputMarker.expression} + '${outputMarker.suffix}'"`;
50-
} else {
51-
effectiveCommandLine = commandLine;
52-
}
5340
const vsTerminal: vscode.Terminal = vscode.window.createTerminal(terminalOptions);
5441

5542
// wait for shell to bootup and vs code shell integration to kick-in
@@ -123,8 +110,8 @@ export async function runWorkspaceCommandAsync({
123110
}
124111
);
125112

126-
shellIntegration.executeCommand(effectiveCommandLine);
127-
terminal.writeLine(`Executing command: ${effectiveCommandLine}`);
113+
shellIntegration.executeCommand(commandLine);
114+
terminal.writeLine(`Executing command: ${commandLine}`);
128115
}).finally(() => {
129116
vsTerminal.dispose();
130117
});

0 commit comments

Comments
 (0)