Skip to content

Commit d4dbf77

Browse files
committed
don't "delete" mandatory property; fixes microsoft#99479
1 parent 09f3600 commit d4dbf77

2 files changed

Lines changed: 33 additions & 30 deletions

File tree

src/vs/workbench/api/node/extHostDebugService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class ExtHostDebugService extends ExtHostDebugServiceBase {
8888

8989
const configProvider = await this._configurationService.getConfigProvider();
9090
const shell = this._terminalService.getDefaultShell(true, configProvider);
91+
let cwdForPrepareCommand: string | undefined;
9192

9293
if (needNewTerminal || !this._integratedTerminalInstance) {
9394

@@ -97,16 +98,17 @@ export class ExtHostDebugService extends ExtHostDebugServiceBase {
9798
cwd: args.cwd,
9899
name: args.title || nls.localize('debug.terminal.title', "debuggee"),
99100
};
100-
delete (args as any).cwd; // TODO: remove this any cast
101101
this._integratedTerminalInstance = this._terminalService.createTerminalFromOptions(options);
102+
} else {
103+
cwdForPrepareCommand = args.cwd;
102104
}
103105

104106
const terminal = this._integratedTerminalInstance;
105107

106108
terminal.show();
107109

108110
const shellProcessId = await this._integratedTerminalInstance.processId;
109-
const command = prepareCommand(args, shell);
111+
const command = prepareCommand(shell, args.args, cwdForPrepareCommand, args.env);
110112
terminal.sendText(command, true);
111113

112114
return shellProcessId;

src/vs/workbench/contrib/debug/node/terminals.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as cp from 'child_process';
7-
import * as env from 'vs/base/common/platform';
7+
import * as platform from 'vs/base/common/platform';
88
import { WindowsExternalTerminalService, MacExternalTerminalService, LinuxExternalTerminalService } from 'vs/workbench/contrib/externalTerminal/node/externalTerminalService';
99
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1010
import { IExternalTerminalService } from 'vs/workbench/contrib/externalTerminal/common/externalTerminal';
@@ -14,11 +14,11 @@ let externalTerminalService: IExternalTerminalService | undefined = undefined;
1414

1515
export function runInExternalTerminal(args: DebugProtocol.RunInTerminalRequestArguments, configProvider: ExtHostConfigProvider): Promise<number | undefined> {
1616
if (!externalTerminalService) {
17-
if (env.isWindows) {
17+
if (platform.isWindows) {
1818
externalTerminalService = new WindowsExternalTerminalService(<IConfigurationService><unknown>undefined);
19-
} else if (env.isMacintosh) {
19+
} else if (platform.isMacintosh) {
2020
externalTerminalService = new MacExternalTerminalService(<IConfigurationService><unknown>undefined);
21-
} else if (env.isLinux) {
21+
} else if (platform.isLinux) {
2222
externalTerminalService = new LinuxExternalTerminalService(<IConfigurationService><unknown>undefined);
2323
} else {
2424
throw new Error('external terminals not supported on this platform');
@@ -49,7 +49,7 @@ function spawnAsPromised(command: string, args: string[]): Promise<string> {
4949
export function hasChildProcesses(processId: number | undefined): Promise<boolean> {
5050
if (processId) {
5151
// if shell has at least one child process, assume that shell is busy
52-
if (env.isWindows) {
52+
if (platform.isWindows) {
5353
return spawnAsPromised('wmic', ['process', 'get', 'ParentProcessId']).then(stdout => {
5454
const pids = stdout.split('\r\n');
5555
return pids.some(p => parseInt(p) === processId);
@@ -75,7 +75,8 @@ export function hasChildProcesses(processId: number | undefined): Promise<boolea
7575

7676
const enum ShellType { cmd, powershell, bash }
7777

78-
export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments, shell: string): string {
78+
79+
export function prepareCommand(shell: string, args: string[], cwd?: string, env?: { [key: string]: string | null; }): string {
7980

8081
shell = shell.trim().toLowerCase();
8182

@@ -87,7 +88,7 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
8788
shellType = ShellType.cmd;
8889
} else if (shell.indexOf('bash') >= 0) {
8990
shellType = ShellType.bash;
90-
} else if (env.isWindows) {
91+
} else if (platform.isWindows) {
9192
shellType = ShellType.cmd; // pick a good default for Windows
9293
} else {
9394
shellType = ShellType.bash; // pick a good default for anything else
@@ -109,23 +110,23 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
109110
return `'${s}'`;
110111
};
111112

112-
if (args.cwd) {
113-
command += `cd '${args.cwd}'; `;
113+
if (cwd) {
114+
command += `cd '${cwd}'; `;
114115
}
115-
if (args.env) {
116-
for (let key in args.env) {
117-
const value = args.env[key];
116+
if (env) {
117+
for (let key in env) {
118+
const value = env[key];
118119
if (value === null) {
119120
command += `Remove-Item env:${key}; `;
120121
} else {
121122
command += `\${env:${key}}='${value}'; `;
122123
}
123124
}
124125
}
125-
if (args.args && args.args.length > 0) {
126-
const cmd = quote(args.args.shift()!);
126+
if (args.length > 0) {
127+
const cmd = quote(args.shift()!);
127128
command += (cmd[0] === '\'') ? `& ${cmd} ` : `${cmd} `;
128-
for (let a of args.args) {
129+
for (let a of args) {
129130
command += `${quote(a)} `;
130131
}
131132
}
@@ -138,13 +139,13 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
138139
return (s.indexOf(' ') >= 0 || s.indexOf('"') >= 0 || s.length === 0) ? `"${s}"` : s;
139140
};
140141

141-
if (args.cwd) {
142-
command += `cd ${quote(args.cwd)} && `;
142+
if (cwd) {
143+
command += `cd ${quote(cwd)} && `;
143144
}
144-
if (args.env) {
145+
if (env) {
145146
command += 'cmd /C "';
146-
for (let key in args.env) {
147-
let value = args.env[key];
147+
for (let key in env) {
148+
let value = env[key];
148149
if (value === null) {
149150
command += `set "${key}=" && `;
150151
} else {
@@ -153,10 +154,10 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
153154
}
154155
}
155156
}
156-
for (let a of args.args) {
157+
for (let a of args) {
157158
command += `${quote(a)} `;
158159
}
159-
if (args.env) {
160+
if (env) {
160161
command += '"';
161162
}
162163
break;
@@ -172,13 +173,13 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
172173
return /[^\w@%\/+=,.:^-]/.test(s) ? `'${s.replace(/'/g, '\'\\\'\'')}'` : s;
173174
};
174175

175-
if (args.cwd) {
176-
command += `cd ${quote(args.cwd)} ; `;
176+
if (cwd) {
177+
command += `cd ${quote(cwd)} ; `;
177178
}
178-
if (args.env) {
179+
if (env) {
179180
command += 'env';
180-
for (let key in args.env) {
181-
const value = args.env[key];
181+
for (let key in env) {
182+
const value = env[key];
182183
if (value === null) {
183184
command += ` -u ${hardQuote(key)}`;
184185
} else {
@@ -187,7 +188,7 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
187188
}
188189
command += ' ';
189190
}
190-
for (let a of args.args) {
191+
for (let a of args) {
191192
command += `${quote(a)} `;
192193
}
193194
break;

0 commit comments

Comments
 (0)