Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Both debug-certificate-manager and playwright-local-browser-server extensions duplicate marker-based output extraction logic when using runWorkspaceCommandAsync. This refactors that pattern into the shared function.

Changes

  • Added IOutputMarkerOptions interface with expression, prefix, and suffix properties
  • When outputMarker is provided, constructs command and extracts content between markers automatically
  • Updated both extensions to use the new option

Usage

Before:

const markerPrefix = '<<<START>>>';
const markerSuffix = '<<<END>>>';
const output = await runWorkspaceCommandAsync({
  commandLine: `node -p "'${markerPrefix}' + require('os').homedir() + '${markerSuffix}'"`,
  ...
});
const startIndex = output.indexOf(markerPrefix);
const endIndex = output.indexOf(markerSuffix);
const result = output.substring(startIndex + markerPrefix.length, endIndex).trim();

After:

const result = await runWorkspaceCommandAsync({
  commandLine: '',
  outputMarker: {
    expression: "require('os').homedir()",
    prefix: '<<<START>>>',
    suffix: '<<<END>>>'
  },
  ...
});
Original prompt

This section details on the original issue you should resolve

<issue_title>[vscode-shared] Refactor string marking logic into runWorkspaceCommandAsync</issue_title>
<issue_description>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. </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Refactor string marking logic into runWorkspaceCommandAsync [vscode-shared] Add outputMarker option to runWorkspaceCommandAsync Feb 3, 2026
Copilot AI requested a review from TheLarkInn February 3, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

[vscode-shared] Refactor string marking logic into runWorkspaceCommandAsync

2 participants