From d84fda67886b5db94837e59a9459057a227f329b Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Wed, 14 Sep 2016 00:36:18 +0200 Subject: [PATCH] first cut of supporting PowerShell in integrated terminal --- .../debug/electron-browser/rawDebugSession.ts | 6 +- .../debug/electron-browser/terminalSupport.ts | 65 +++++++++++++------ 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts b/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts index 1c19f36b60e..1786d1e0a9e 100644 --- a/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts +++ b/src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts @@ -25,6 +25,7 @@ import v8 = require('vs/workbench/parts/debug/node/v8Protocol'); import {IOutputService} from 'vs/workbench/parts/output/common/output'; import {ExtensionsChannelId} from 'vs/platform/extensionManagement/common/extensionManagement'; import {TerminalSupport} from 'vs/workbench/parts/debug/electron-browser/terminalSupport'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import {shell} from 'electron'; @@ -75,7 +76,8 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes @ITelemetryService private telemetryService: ITelemetryService, @IOutputService private outputService: IOutputService, @ITerminalService private terminalService: ITerminalService, - @IExternalTerminalService private nativeTerminalService: IExternalTerminalService + @IExternalTerminalService private nativeTerminalService: IExternalTerminalService, + @IConfigurationService private configurationService: IConfigurationService ) { super(); this.emittedStopped = false; @@ -348,7 +350,7 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes if (request.command === 'runInTerminal') { - TerminalSupport.runInTerminal(this.terminalService, this.nativeTerminalService, request.arguments, response).then(() => { + TerminalSupport.runInTerminal(this.terminalService, this.nativeTerminalService, this.configurationService, request.arguments, response).then(() => { this.sendResponse(response); }, e => { response.success = false; diff --git a/src/vs/workbench/parts/debug/electron-browser/terminalSupport.ts b/src/vs/workbench/parts/debug/electron-browser/terminalSupport.ts index 0abf4baf819..b8474a0018f 100644 --- a/src/vs/workbench/parts/debug/electron-browser/terminalSupport.ts +++ b/src/vs/workbench/parts/debug/electron-browser/terminalSupport.ts @@ -8,33 +8,40 @@ import platform = require('vs/base/common/platform'); import {TPromise} from 'vs/base/common/winjs.base'; import {ITerminalService, ITerminalInstance} from 'vs/workbench/parts/terminal/electron-browser/terminal'; import {ITerminalService as IExternalTerminalService} from 'vs/workbench/parts/execution/common/execution'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; +export interface IIntegratedTerminalConfiguration { + terminal: { + integrated: { + shell: { + windows: string + } + } + }; +} + export class TerminalSupport { private static integratedTerminalInstance: ITerminalInstance; - public static runInTerminal(terminalService: ITerminalService, nativeTerminalService: IExternalTerminalService, args: DebugProtocol.RunInTerminalRequestArguments, response: DebugProtocol.RunInTerminalResponse): TPromise { + public static runInTerminal(terminalService: ITerminalService, nativeTerminalService: IExternalTerminalService, configurationService: IConfigurationService, args: DebugProtocol.RunInTerminalRequestArguments, response: DebugProtocol.RunInTerminalResponse): TPromise { if (args.kind === 'external') { return nativeTerminalService.runInTerminal(args.title, args.cwd, args.args, args.env); } - return this.runInIntegratedTerminal(terminalService, args); - } - - private static runInIntegratedTerminal(terminalService: ITerminalService, args: DebugProtocol.RunInTerminalRequestArguments): TPromise { if (!TerminalSupport.integratedTerminalInstance) { TerminalSupport.integratedTerminalInstance = terminalService.createInstance(args.title || nls.localize('debuggee', "debuggee")); } terminalService.setActiveInstance(TerminalSupport.integratedTerminalInstance); terminalService.showPanel(true); - const command = this.prepareCommand(args); + const command = this.prepareCommand(args, configurationService); TerminalSupport.integratedTerminalInstance.sendText(command, true); return TPromise.as(void 0); } - private static prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments): string { + private static prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments, configurationService: IConfigurationService): string { let command = ''; if (platform.isWindows) { @@ -44,21 +51,41 @@ export class TerminalSupport { return (s.indexOf(' ') >= 0 || s.indexOf('"') >= 0) ? `"${s}"` : s; }; - if (args.cwd) { - command += `cd ${quote(args.cwd)} && `; + const conf = configurationService.getConfiguration(); + + let isPowerShell = false; + if (conf.terminal && conf.terminal.integrated && conf.terminal.integrated.shell && conf.terminal.integrated.shell.windows) { + isPowerShell = conf.terminal.integrated.shell.windows.indexOf('PowerShell') >= 0; } - if (args.env) { - command += 'cmd /C "'; - for (let key in args.env) { - command += `set "${key}=${args.env[key]}" && `; + + if (isPowerShell) { + + if (args.cwd) { + command += `cd ${quote(args.cwd)}; `; + } + for (let a of args.args) { + command += `${quote(a)} `; + } + + } else { + + if (args.cwd) { + command += `cd ${quote(args.cwd)} && `; + } + if (args.env) { + command += 'cmd /C "'; + for (let key in args.env) { + command += `set "${key}=${args.env[key]}" && `; + } + } + for (let a of args.args) { + command += `${quote(a)} `; + } + if (args.env) { + command += '"'; } } - for (let a of args.args) { - command += `${quote(a)} `; - } - if (args.env) { - command += '"'; - } + } else { const quote = (s: string) => { s = s.replace(/\"/g, '\\"'); -- GitLab