@@ -15,36 +15,53 @@ class TaskfileService {
1515 }
1616
1717 public async read ( ) : Promise < models . Taskfile > {
18- return await new Promise ( ( resolve , reject ) => {
18+ return await new Promise ( ( resolve ) => {
1919 let command = 'task --list-all --json' ;
20- cp . exec ( command , { cwd : getWorkspaceFolder ( ) } , ( err : cp . ExecException | null , stdout : string , stderr : string ) => {
21- if ( err ) {
22- console . log ( 'error: ' + err ) ;
23- reject ( ) ;
24- return ;
25- }
20+ cp . exec ( command , { cwd : getWorkspaceFolder ( ) } , ( _ , stdout : string ) => {
2621 var taskfile : models . Taskfile = JSON . parse ( stdout ) ;
2722 resolve ( taskfile ) ;
2823 } ) ;
2924 } ) ;
3025 }
3126
3227 public async runTask ( taskName : string ) : Promise < void > {
33- return await new Promise ( ( resolve , reject ) => {
28+ return await new Promise ( ( resolve ) => {
3429 let command = `task ${ taskName } ` ;
35- cp . exec ( command , { cwd : getWorkspaceFolder ( ) } , ( err : cp . ExecException | null , stdout : string , stderr : string ) => {
36- if ( err ) {
37- console . log ( 'error: ' + err ) ;
38- reject ( ) ;
39- return ;
40- }
30+ cp . exec ( command , { cwd : getWorkspaceFolder ( ) } , ( _ , stdout : string , stderr : string ) => {
4131 TaskfileService . outputChannel . append ( stderr ) ;
4232 TaskfileService . outputChannel . append ( stdout ) ;
33+ TaskfileService . outputChannel . append ( "-----" ) ;
4334 TaskfileService . outputChannel . show ( ) ;
4435 resolve ( ) ;
4536 } ) ;
4637 } ) ;
4738 }
39+
40+ public goToDefinition ( task : models . Task , preview : boolean = false ) : void {
41+ if ( task . location === undefined ) {
42+ vscode . window . showErrorMessage ( `Go to definition requires Task v3.23.0 or higher.` ) ;
43+ return ;
44+ }
45+
46+ let position = new vscode . Position ( task . location . line - 1 , task . location . column - 1 ) ;
47+ let range = new vscode . Range ( position , position ) ;
48+
49+ // Create the vscode URI from the Taskfile path
50+ let file = vscode . Uri . file ( task . location . taskfile ) ;
51+
52+ // Create the vscode text document show options
53+ let options : vscode . TextDocumentShowOptions = {
54+ selection : range ,
55+ preview : preview
56+ } ;
57+
58+ // Run the vscode open command with the range options
59+ try {
60+ vscode . commands . executeCommand ( 'vscode.open' , file , options ) ;
61+ } catch ( err ) {
62+ console . error ( err ) ;
63+ }
64+ }
4865}
4966
5067export const taskfile = TaskfileService . Instance ;
0 commit comments