44 * ------------------------------------------------------------------------------------------ */
55import * as path from 'path' ;
66import {
7- TaskDefinition , Task , TaskGroup , WorkspaceFolder , ShellExecution , Uri , workspace ,
7+ TaskDefinition , Task , TaskGroup , ShellExecution , Uri , workspace ,
88 TaskProvider , TaskScope , CustomExecution , ProcessExecution , TextEditor , Pseudoterminal , EventEmitter , Event , TerminalDimensions , window
99} from 'vscode' ;
1010import * as os from 'os' ;
@@ -185,9 +185,9 @@ export class CppBuildTaskProvider implements TaskProvider {
185185
186186 const scope : TaskScope = TaskScope . Workspace ;
187187 const task : CppBuildTask = new Task ( definition , scope , definition . label , CppBuildTaskProvider . CppBuildSourceStr ,
188- new CustomExecution ( async ( ) : Promise < Pseudoterminal > =>
188+ new CustomExecution ( async ( resolvedDefinition : TaskDefinition ) : Promise < Pseudoterminal > =>
189189 // When the task is executed, this callback will run. Here, we setup for running the task.
190- new CustomBuildTaskTerminal ( resolvedcompilerPath , definition ? definition . args : [ ] , definition ? definition . options : undefined )
190+ new CustomBuildTaskTerminal ( resolvedcompilerPath , resolvedDefinition . args , resolvedDefinition . options )
191191 ) , isCl ? '$msCompile' : '$gcc' ) ;
192192
193193 task . group = TaskGroup . Build ;
@@ -200,6 +200,9 @@ export class CppBuildTaskProvider implements TaskProvider {
200200 const rawJson : any = await this . getRawTasksJson ( ) ;
201201 const rawTasksJson : any = ( ! rawJson . tasks ) ? new Array ( ) : rawJson . tasks ;
202202 const buildTasksJson : CppBuildTask [ ] = rawTasksJson . map ( ( task : any ) => {
203+ if ( ! task . label ) {
204+ return null ;
205+ }
203206 const definition : CppBuildTaskDefinition = {
204207 type : task . type ,
205208 label : task . label ,
@@ -211,7 +214,7 @@ export class CppBuildTaskProvider implements TaskProvider {
211214 cppBuildTask . detail = task . detail ;
212215 return cppBuildTask ;
213216 } ) ;
214- return buildTasksJson ;
217+ return buildTasksJson . filter ( ( task : CppBuildTask ) => task !== null ) ;
215218 }
216219
217220 public async ensureBuildTaskExists ( taskLabel : string ) : Promise < void > {
@@ -343,16 +346,16 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
343346
344347 private async doBuild ( ) : Promise < any > {
345348 // Do build.
346- let activeCommand : string = util . resolveVariables ( this . command , this . AdditionalEnvironment ) ;
349+ let activeCommand : string = util . resolveVariables ( this . command ) ;
347350 this . args . forEach ( value => {
348- let temp : string = util . resolveVariables ( value , this . AdditionalEnvironment ) ;
351+ let temp : string = util . resolveVariables ( value ) ;
349352 if ( temp && temp . includes ( " " ) ) {
350353 temp = "\"" + temp + "\"" ;
351354 }
352355 activeCommand = activeCommand + " " + temp ;
353356 } ) ;
354357 if ( this . options ?. cwd ) {
355- this . options . cwd = util . resolveVariables ( this . options . cwd , this . AdditionalEnvironment ) ;
358+ this . options . cwd = util . resolveVariables ( this . options . cwd ) ;
356359 }
357360
358361 const splitWriteEmitter = ( lines : string | Buffer ) => {
@@ -382,23 +385,4 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
382385 this . closeEmitter . fire ( - 1 ) ;
383386 }
384387 }
385-
386- private get AdditionalEnvironment ( ) : { [ key : string ] : string | string [ ] } | undefined {
387- const editor : TextEditor | undefined = window . activeTextEditor ;
388- if ( ! editor ) {
389- return undefined ;
390- }
391- const fileDir : WorkspaceFolder | undefined = workspace . getWorkspaceFolder ( editor . document . uri ) ;
392- if ( ! fileDir ) {
393- window . showErrorMessage ( 'This command is not yet available for single-file mode.' ) ;
394- return undefined ;
395- }
396- const file : string = editor . document . fileName ;
397- return {
398- "file" : file ,
399- "fileDirname" : path . parse ( file ) . dir ,
400- "fileBasenameNoExtension" : path . parse ( file ) . name ,
401- "workspaceFolder" : fileDir . uri . fsPath
402- } ;
403- }
404388}
0 commit comments