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