Skip to content

[vscode-shared] Refactor string marking logic into runWorkspaceCommandAsync #5589

@TheLarkInn

Description

@TheLarkInn

runWorkspaceCommandAsync used in two places:

const markerPrefix: string = '<<<HOMEDIR_START>>>';
const markerSuffix: string = '<<<HOMEDIR_END>>>';
const output: string = await runWorkspaceCommandAsync({
terminalOptions: { name: 'debug-certificate-manager', hideFromUser: true },
// Wrapping the desired node output in markers to trim uninteresting shell output.
commandLine: `node -p "'${markerPrefix}' + require('os').homedir() + '${markerSuffix}'"`,
terminal
});
terminal.writeLine(`Running command to resolve home directory: ${output}`);
const startIndex: number = output.lastIndexOf(markerPrefix);
const endIndex: number = output.lastIndexOf(markerSuffix);
if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
homeDir = output.substring(startIndex + markerPrefix.length, endIndex).trim();
} else {
throw new Error('Failed to parse home directory from command output');
}

and

const markerPrefix: string = '<<<TEMPDIR_START>>>';
const markerSuffix: string = '<<<TEMPDIR_END>>>';
const output: string = await runWorkspaceCommandAsync({
terminalOptions: { name: 'playwright-local-browser-server', hideFromUser: true },
commandLine: `node -p "'${markerPrefix}' + require('node:os').tmpdir() + '${markerSuffix}'"`,
terminal
});
const startIndex: number = output.indexOf(markerPrefix);
const endIndex: number = output.indexOf(markerSuffix);
if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
tempDir = output.substring(startIndex + markerPrefix.length, endIndex).trim();
} else {
throw new Error('Failed to parse temp directory from command output');
}

with duplicate string marker logic wrapped around the usage of these functions.

We should abstract this as a new option in runWorkspaceCommandAsync so we don't have this extra logic.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

Needs triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions