@@ -60,7 +60,7 @@ interface ActiveTerminalData {
6060
6161class VariableResolver {
6262
63- constructor ( public workspaceFolder : IWorkspaceFolder , public taskSystemInfo : TaskSystemInfo | undefined , private _values : Map < string , string > , private _service : IConfigurationResolverService | undefined ) {
63+ constructor ( public workspaceFolder : IWorkspaceFolder | undefined , public taskSystemInfo : TaskSystemInfo | undefined , private _values : Map < string , string > , private _service : IConfigurationResolverService | undefined ) {
6464 }
6565 resolve ( value : string ) : string {
6666 return value . replace ( / \$ \{ ( .* ?) \} / g, ( match : string , variable : string ) => {
@@ -389,7 +389,7 @@ export class TerminalTaskSystem implements ITaskSystem {
389389 }
390390 }
391391
392- private resolveVariablesFromSet ( taskSystemInfo : TaskSystemInfo | undefined , workspaceFolder : IWorkspaceFolder , task : CustomTask | ContributedTask , variables : Set < string > ) : Promise < ResolvedVariables > {
392+ private resolveVariablesFromSet ( taskSystemInfo : TaskSystemInfo | undefined , workspaceFolder : IWorkspaceFolder | undefined , task : CustomTask | ContributedTask , variables : Set < string > ) : Promise < ResolvedVariables > {
393393 let isProcess = task . command && task . command . runtime === RuntimeType . Process ;
394394 let options = task . command && task . command . options ? task . command . options : undefined ;
395395 let cwd = options ? options . cwd : undefined ;
@@ -406,7 +406,7 @@ export class TerminalTaskSystem implements ITaskSystem {
406406 }
407407
408408 let resolvedVariables : Promise < ResolvedVariables > ;
409- if ( taskSystemInfo ) {
409+ if ( taskSystemInfo && workspaceFolder ) {
410410 let resolveSet : ResolveSet = {
411411 variables
412412 } ;
@@ -463,10 +463,7 @@ export class TerminalTaskSystem implements ITaskSystem {
463463
464464 private executeCommand ( task : CustomTask | ContributedTask , trigger : string ) : Promise < ITaskSummary > {
465465 const workspaceFolder = this . currentTask . workspaceFolder = task . getWorkspaceFolder ( ) ;
466- if ( workspaceFolder === undefined ) {
467- return Promise . reject ( new Error ( `Must have workspace folder${ task . _label } ` ) ) ;
468- }
469- const systemInfo = this . currentTask . systemInfo = this . taskSystemInfoResolver ( workspaceFolder ) ;
466+ const systemInfo : TaskSystemInfo | undefined = this . currentTask . systemInfo = workspaceFolder ? this . taskSystemInfoResolver ( workspaceFolder ) : undefined ;
470467
471468 let variables = new Set < string > ( ) ;
472469 this . collectTaskVariables ( variables , task ) ;
@@ -515,7 +512,7 @@ export class TerminalTaskSystem implements ITaskSystem {
515512 }
516513 }
517514
518- private async executeInTerminal ( task : CustomTask | ContributedTask , trigger : string , resolver : VariableResolver , workspaceFolder : IWorkspaceFolder ) : Promise < ITaskSummary > {
515+ private async executeInTerminal ( task : CustomTask | ContributedTask , trigger : string , resolver : VariableResolver , workspaceFolder : IWorkspaceFolder | undefined ) : Promise < ITaskSummary > {
519516 let terminal : ITerminalInstance | undefined = undefined ;
520517 let executedCommand : string | undefined = undefined ;
521518 let error : TaskError | undefined = undefined ;
@@ -761,7 +758,7 @@ export class TerminalTaskSystem implements ITaskSystem {
761758 } ) ;
762759 }
763760
764- private createTerminalName ( task : CustomTask | ContributedTask , workspaceFolder : IWorkspaceFolder ) : string {
761+ private createTerminalName ( task : CustomTask | ContributedTask ) : string {
765762 const needsFolderQualification = this . contextService . getWorkbenchState ( ) === WorkbenchState . WORKSPACE ;
766763 return nls . localize ( 'TerminalTaskSystem.terminalName' , 'Task - {0}' , needsFolderQualification ? task . getQualifiedLabel ( ) : task . configurationProperties . name ) ;
767764 }
@@ -774,11 +771,11 @@ export class TerminalTaskSystem implements ITaskSystem {
774771 return URI . from ( { scheme : Schemas . file , path : this . environmentService . userHome } ) ;
775772 }
776773
777- private async createShellLaunchConfig ( task : CustomTask | ContributedTask , workspaceFolder : IWorkspaceFolder , variableResolver : VariableResolver , platform : Platform . Platform , options : CommandOptions , command : CommandString , args : CommandString [ ] , waitOnExit : boolean | string ) : Promise < IShellLaunchConfig | undefined > {
774+ private async createShellLaunchConfig ( task : CustomTask | ContributedTask , workspaceFolder : IWorkspaceFolder | undefined , variableResolver : VariableResolver , platform : Platform . Platform , options : CommandOptions , command : CommandString , args : CommandString [ ] , waitOnExit : boolean | string ) : Promise < IShellLaunchConfig | undefined > {
778775 let shellLaunchConfig : IShellLaunchConfig ;
779776 let isShellCommand = task . command . runtime === RuntimeType . Shell ;
780777 let needsFolderQualification = this . contextService . getWorkbenchState ( ) === WorkbenchState . WORKSPACE ;
781- let terminalName = this . createTerminalName ( task , workspaceFolder ) ;
778+ let terminalName = this . createTerminalName ( task ) ;
782779 let originalCommand = task . command . name ;
783780 if ( isShellCommand ) {
784781 const defaultConfig = await this . terminalInstanceService . getDefaultShellAndArgs ( true , platform ) ;
@@ -846,7 +843,7 @@ export class TerminalTaskSystem implements ITaskSystem {
846843 shellArgs . push ( commandLine ) ;
847844 shellLaunchConfig . args = windowsShellArgs ? shellArgs . join ( ' ' ) : shellArgs ;
848845 if ( task . command . presentation && task . command . presentation . echo ) {
849- if ( needsFolderQualification ) {
846+ if ( needsFolderQualification && workspaceFolder ) {
850847 shellLaunchConfig . initialText = `\x1b[1m> Executing task in folder ${ workspaceFolder . name } : ${ commandLine } <\x1b[0m\n` ;
851848 } else {
852849 shellLaunchConfig . initialText = `\x1b[1m> Executing task: ${ commandLine } <\x1b[0m\n` ;
@@ -875,7 +872,7 @@ export class TerminalTaskSystem implements ITaskSystem {
875872 }
876873 return args . join ( ' ' ) ;
877874 } ;
878- if ( needsFolderQualification ) {
875+ if ( needsFolderQualification && workspaceFolder ) {
879876 shellLaunchConfig . initialText = `\x1b[1m> Executing task in folder ${ workspaceFolder . name } : ${ shellLaunchConfig . executable } ${ getArgsToEcho ( shellLaunchConfig . args ) } <\x1b[0m\n` ;
880877 } else {
881878 shellLaunchConfig . initialText = `\x1b[1m> Executing task: ${ shellLaunchConfig . executable } ${ getArgsToEcho ( shellLaunchConfig . args ) } <\x1b[0m\n` ;
@@ -886,7 +883,6 @@ export class TerminalTaskSystem implements ITaskSystem {
886883 if ( options . cwd ) {
887884 let cwd = options . cwd ;
888885 if ( ! path . isAbsolute ( cwd ) ) {
889- let workspaceFolder = task . getWorkspaceFolder ( ) ;
890886 if ( workspaceFolder && ( workspaceFolder . uri . scheme === 'file' ) ) {
891887 cwd = path . join ( workspaceFolder . uri . fsPath , cwd ) ;
892888 }
@@ -900,7 +896,7 @@ export class TerminalTaskSystem implements ITaskSystem {
900896 return shellLaunchConfig ;
901897 }
902898
903- private async createTerminal ( task : CustomTask | ContributedTask , resolver : VariableResolver , workspaceFolder : IWorkspaceFolder ) : Promise < [ ITerminalInstance | undefined , string | undefined , TaskError | undefined ] > {
899+ private async createTerminal ( task : CustomTask | ContributedTask , resolver : VariableResolver , workspaceFolder : IWorkspaceFolder | undefined ) : Promise < [ ITerminalInstance | undefined , string | undefined , TaskError | undefined ] > {
904900 let platform = resolver . taskSystemInfo ? resolver . taskSystemInfo . platform : Platform . platform ;
905901 let options = this . resolveOptions ( resolver , task . command . options ) ;
906902
@@ -929,7 +925,7 @@ export class TerminalTaskSystem implements ITaskSystem {
929925 this . currentTask . shellLaunchConfig = launchConfigs = {
930926 isExtensionTerminal : true ,
931927 waitOnExit,
932- name : this . createTerminalName ( task , workspaceFolder ) ,
928+ name : this . createTerminalName ( task ) ,
933929 initialText : task . command . presentation && task . command . presentation . echo ? `\x1b[1m> Executing task: ${ task . _label } <\x1b[0m\n` : undefined
934930 } ;
935931 } else {
0 commit comments