Path: blob/main/extensions/copilot/src/extension/onboardDebug/node/copilotDebugWorker/open.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { spawn } from 'child_process';67export const openVscodeUri = (remoteCommand: string | undefined, uri: string): Promise<void> => {8let command: string;9let shell = false;10let args = [uri];11if (remoteCommand) {12const [cmd, ...cmdArgs] = remoteCommand.split(' ');13command = cmd;14args = [...cmdArgs, uri];15} else {16switch (process.platform) {17case 'win32':18command = 'cmd';19shell = true;20args = ['/c', 'start', '""', `"${uri}"`];21break;22case 'darwin':23command = 'open';24break;25case 'linux':26default:27command = 'xdg-open';28break;29}30}3132return new Promise((resolve, reject) => {33let std = '';34const cmd = spawn(command, args, {35stdio: 'pipe',36shell,37env: { ...process.env, ELECTRON_RUN_AS_NODE: undefined },38});39cmd.stdout.setEncoding('utf8').on('data', d => std += d);40cmd.stderr.setEncoding('utf8').on('data', d => std += d);4142cmd.on('error', reject);43cmd.on('exit', code => {44if (code !== 0) {45reject(new Error(`Failed to open: ${std}`));46} else {47resolve();48}49});50});51};525354