33
44'use strict' ;
55
6- import { CancellationToken , Uri , WorkspaceFolder } from 'vscode' ;
6+ import { CancellationToken , Uri , WorkspaceFolder , workspace } from 'vscode' ;
77import { getOSType , OSType } from '../../../common/platform' ;
88import { getEnvFile } from '../../../common/settings' ;
99import { DebuggerTypeName } from '../../../constants' ;
@@ -13,6 +13,7 @@ import { BaseConfigurationResolver } from './base';
1313import { getDebugEnvironmentVariables , getProgram } from './helper' ;
1414import { getConfiguration } from '../../../common/vscodeapi' ;
1515import { traceLog } from '../../../common/log/logging' ;
16+ import { debug } from 'console' ;
1617
1718export class LaunchConfigurationResolver extends BaseConfigurationResolver < LaunchRequestArguments > {
1819 public async resolveDebugConfiguration (
@@ -105,6 +106,13 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
105106 if ( debugConfiguration . console !== 'internalConsole' && ! debugConfiguration . internalConsoleOptions ) {
106107 debugConfiguration . internalConsoleOptions = 'neverOpen' ;
107108 }
109+
110+ // Compute the terminal quoting character.
111+ if ( ! debugConfiguration . terminalQuoteCharacter || debugConfiguration . terminalQuoteCharacter . length !== 1 ) {
112+ const quoteChar = this . _computeTerminalQuoteCharacter ( ) ;
113+ debugConfiguration . terminalQuoteCharacter = quoteChar ;
114+ }
115+
108116 if ( ! Array . isArray ( debugConfiguration . debugOptions ) ) {
109117 debugConfiguration . debugOptions = [ ] ;
110118 }
@@ -182,4 +190,46 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
182190 : 'launch' ;
183191 LaunchConfigurationResolver . sendTelemetry ( trigger , debugConfiguration ) ;
184192 }
193+
194+ private _computeTerminalQuoteCharacter ( ) : string {
195+ const platform = process . platform ; // 'win32', 'linux', 'darwin'
196+ const config = workspace . getConfiguration ( 'terminal' ) ;
197+
198+ let defaultProfile : string | undefined ;
199+ let profiles : any ;
200+
201+ if ( platform === 'win32' ) {
202+ defaultProfile = config . get < string > ( 'integrated.defaultProfile.windows' ) ;
203+ profiles = config . get < any > ( 'integrated.profiles.windows' ) ;
204+ } else if ( platform === 'linux' ) {
205+ defaultProfile = config . get < string > ( 'integrated.defaultProfile.linux' ) ;
206+ profiles = config . get < any > ( 'integrated.profiles.linux' ) ;
207+ } else if ( platform === 'darwin' ) {
208+ defaultProfile = config . get < string > ( 'integrated.defaultProfile.osx' ) ;
209+ profiles = config . get < any > ( 'integrated.profiles.osx' ) ;
210+ }
211+
212+ if ( ! defaultProfile || ! profiles ) {
213+ if ( platform === 'win32' ) {
214+ return "'" ; // Default is powershell
215+ } else {
216+ return '"' ; // Default is bash/zsh
217+ }
218+ }
219+
220+ const profile = defaultProfile ? profiles [ defaultProfile ] : profiles [ 0 ] ;
221+ const shellPath = profile ?. path || '' ;
222+
223+ if ( / p o w e r s h e l l / i. test ( shellPath ) ) {
224+ return "'" ;
225+ }
226+ if ( / c m d \. e x e $ / i. test ( shellPath ) ) {
227+ return '"' ;
228+ }
229+ if ( / b a s h | z s h | f i s h / i. test ( shellPath ) ) {
230+ return '"' ;
231+ }
232+
233+ return '"' ;
234+ }
185235}
0 commit comments