@@ -4,7 +4,7 @@ import * as models from '../models';
44import * as path from 'path' ;
55import * as fs from 'fs' ;
66import * as semver from 'semver' ;
7- import { settings } from '../settings ' ;
7+ import { log , settings } from '../utils ' ;
88import { Octokit } from 'octokit' ;
99import { Endpoints } from "@octokit/types" ;
1010
@@ -42,6 +42,7 @@ class TaskfileService {
4242
4343 // If the version is a devel version, ignore all version checks
4444 if ( stdout . includes ( "devel" ) ) {
45+ log . info ( "Using development version of task" ) ;
4546 return resolve ( "ready" ) ;
4647 }
4748
@@ -50,13 +51,15 @@ class TaskfileService {
5051
5152 // If there is an error fetching the version, assume task is not installed
5253 if ( stderr !== "" || version === undefined ) {
54+ log . error ( version ? stderr : "Version is undefined" ) ;
5355 vscode . window . showErrorMessage ( "Task command not found." , "Install" ) . then ( this . buttonCallback ) ;
5456 return resolve ( "notInstalled" ) ;
5557 }
5658
5759 // If the current version is older than the minimum required version, show an error
5860 if ( version && version . compare ( minimumRequiredVersion ) < 0 ) {
59- vscode . window . showErrorMessage ( `Task v${ minimumRequiredVersion } is required to run this extension. Your current version is v${ version } .` , "Update" ) . then ( this . buttonCallback ) ;
61+ log . error ( `Task v${ minimumRequiredVersion } is required to run this extension. The current version is v${ version } ` ) ;
62+ vscode . window . showErrorMessage ( `Task v${ minimumRequiredVersion } is required to run this extension. The current version is v${ version } .` , "Update" ) . then ( this . buttonCallback ) ;
6063 return resolve ( "outOfDate" ) ;
6164 }
6265
@@ -65,11 +68,12 @@ class TaskfileService {
6568 if ( settings . checkForUpdates ) {
6669 this . getLatestVersion ( ) . then ( ( latestVersion ) => {
6770 if ( version && latestVersion && version . compare ( latestVersion ) < 0 ) {
71+ log . info ( `A new version of Task is available. Current version: v${ version } , Latest version: v${ latestVersion } ` ) ;
6872 vscode . window . showInformationMessage ( `A new version of Task is available. Current version: v${ version } , Latest version: v${ latestVersion } ` , "Update" ) . then ( this . buttonCallback ) ;
6973 }
7074 return resolve ( "ready" ) ;
7175 } ) . catch ( ( err ) => {
72- console . error ( err ) ;
76+ log . error ( err ) ;
7377 return resolve ( "notInstalled" ) ;
7478 } ) ;
7579 }
@@ -88,6 +92,7 @@ class TaskfileService {
8892 }
8993
9094 async getLatestVersion ( ) : Promise < semver . SemVer | null > {
95+ log . info ( `Calling GitHub to get the latest version` ) ;
9196 let request : ReleaseRequest = {
9297 owner : 'go-task' ,
9398 repo : 'task'
@@ -111,6 +116,7 @@ class TaskfileService {
111116 }
112117
113118 public async init ( dir : string ) : Promise < void > {
119+ log . info ( `Initialising taskfile in: "${ dir } "` ) ;
114120 return await new Promise ( ( resolve ) => {
115121 let command = this . command ( '--init' ) ;
116122 cp . exec ( command , { cwd : dir } , ( _ , stdout : string , stderr : string ) => {
@@ -129,23 +135,28 @@ class TaskfileService {
129135 for ( let i = 0 ; i < filenames . length ; i ++ ) {
130136 let filename = path . join ( dir , filenames [ i ] ) ;
131137 if ( fs . existsSync ( filename ) ) {
138+ log . info ( `Opening taskfile: "${ filename } "` ) ;
132139 await vscode . commands . executeCommand ( 'vscode.open' , vscode . Uri . parse ( filename ) , { preview : false } ) ;
133140 return ;
134141 }
135142 }
136143 }
137144
138145 public async read ( dir : string ) : Promise < models . Taskfile > {
146+ log . info ( `Searching for taskfile in: "${ dir } "` ) ;
139147 return await new Promise ( ( resolve , reject ) => {
140148 let command = this . command ( '--list-all --json' ) ;
141149 cp . exec ( command , { cwd : dir } , ( err : cp . ExecException | null , stdout : string ) => {
142150 if ( err ) {
151+ log . error ( err ) ;
143152 return reject ( ) ;
144153 }
145154 var taskfile : models . Taskfile = JSON . parse ( stdout ) ;
146155 if ( path . dirname ( taskfile . location ) !== dir ) {
156+ log . info ( `Ignoring taskfile: "${ taskfile . location } " (outside of workspace)` ) ;
147157 return reject ( ) ;
148158 }
159+ log . info ( `Found taskfile: "${ taskfile . location } "` ) ;
149160 taskfile . workspace = dir ;
150161 return resolve ( taskfile ) ;
151162 } ) ;
@@ -162,6 +173,8 @@ class TaskfileService {
162173
163174 public async runTask ( taskName : string , dir ?: string ) : Promise < void > {
164175 return await new Promise ( ( resolve ) => {
176+ log . info ( `Running task: "${ taskName } " in: "${ dir } "` ) ;
177+
165178 // Spawn a child process
166179 let child = cp . spawn ( this . command ( ) , [ taskName ] , { cwd : dir } ) ;
167180
@@ -183,6 +196,7 @@ class TaskfileService {
183196
184197 // When the task finishes, print the exit code and resolve the promise
185198 child . on ( 'close' , code => {
199+ log . info ( `Task completed with code ${ code } ` ) ;
186200 TaskfileService . outputChannel . append ( `task: completed with code ${ code } \n` ) ;
187201 this . lastTaskName = taskName ;
188202 this . lastTaskDir = dir ;
@@ -192,6 +206,8 @@ class TaskfileService {
192206 }
193207
194208 public async goToDefinition ( task : models . Task , preview : boolean = false ) : Promise < void > {
209+ log . info ( `Navigating to "${ task . name } " definition in: "${ task . location . taskfile } "` ) ;
210+
195211 let position = new vscode . Position ( task . location . line - 1 , task . location . column - 1 ) ;
196212 let range = new vscode . Range ( position , position ) ;
197213
@@ -208,7 +224,7 @@ class TaskfileService {
208224 try {
209225 await vscode . commands . executeCommand ( 'vscode.open' , file , options ) ;
210226 } catch ( err ) {
211- console . error ( err ) ;
227+ log . error ( err ) ;
212228 }
213229 }
214230}
0 commit comments