1+ import { task as taskReq } from "./lsp_extensions" ;
12import * as path from "path" ;
23import {
34 commands ,
45 EventEmitter ,
56 ExtensionContext ,
67 Position ,
7- ProcessExecution ,
88 Selection ,
99 Task ,
1010 TaskProvider ,
@@ -25,7 +25,7 @@ import {
2525 readTaskDefinitions ,
2626} from "./util" ;
2727import { DenoExtensionContext } from "./types" ;
28- import { task as taskReq } from "./lsp_extensions " ;
28+ import { buildDenoConfigTask , TASK_TYPE } from "./tasks " ;
2929
3030class Folder extends TreeItem {
3131 configs : DenoJSON [ ] = [ ] ;
@@ -109,26 +109,6 @@ class DenoTask extends TreeItem {
109109 }
110110}
111111
112- function buildDenoConfigTask (
113- scope : WorkspaceFolder ,
114- process : string ,
115- name : string ,
116- command : string ,
117- sourceUri : Uri ,
118- ) : Task {
119- const execution = new ProcessExecution ( process , [ "task" , name ] ) ;
120- const task = new Task (
121- { type : "denoTasks" , name, command, sourceUri } ,
122- scope ,
123- name ,
124- "deno task" ,
125- execution ,
126- [ "$deno" ] ,
127- ) ;
128- task . detail = command ;
129- return task ;
130- }
131-
132112class NoScripts extends TreeItem {
133113 constructor ( message : string ) {
134114 super ( message , TreeItemCollapsibleState . None ) ;
@@ -144,47 +124,46 @@ class DenoTaskProvider implements TaskProvider {
144124 }
145125
146126 async provideTasks ( ) : Promise < Task [ ] > {
147- const tasks : Task [ ] = [ ] ;
148-
149127 const process = await getDenoCommandName ( ) ;
150-
151- // we retrieve config tasks from the language server, if the language server
152- // supports the capability
153128 const client = this . #extensionContext. client ;
154129 const supportsConfigTasks = this . #extensionContext. serverCapabilities
155130 ?. experimental ?. denoConfigTasks ;
156- if ( client && supportsConfigTasks ) {
157- try {
158- const configTasks = await client . sendRequest ( taskReq ) ;
159- for ( const { name, detail : command , sourceUri } of configTasks ?? [ ] ) {
160- const workspaceFolder = ( workspace . workspaceFolders ?? [ ] ) . find ( ( f ) =>
161- // NOTE: skipEncoding in Uri.toString(), read more at https://github.com/microsoft/vscode/commit/65cb3397673b922c1b6759d145a3a183feb3ee5d
162- sourceUri
163- . toLocaleLowerCase ( )
164- . startsWith ( f . uri . toString ( true ) . toLocaleLowerCase ( ) )
165- ) ;
166- if ( ! workspaceFolder ) {
167- continue ;
168- }
169-
170- tasks . push (
171- buildDenoConfigTask (
172- workspaceFolder ,
173- process ,
174- name ,
175- command ,
176- Uri . parse ( sourceUri ) ,
177- ) ,
178- ) ;
131+ if ( ! client || ! supportsConfigTasks ) {
132+ return [ ] ;
133+ }
134+ const tasks = [ ] ;
135+ try {
136+ const configTasks = await client . sendRequest ( taskReq ) ;
137+ for ( const configTask of configTasks ?? [ ] ) {
138+ const workspaceFolders = Array . from (
139+ workspace . workspaceFolders ?? [ ] ,
140+ ) ;
141+ workspaceFolders . reverse ( ) ;
142+ const workspaceFolder = workspaceFolders . find ( ( f ) =>
143+ // NOTE: skipEncoding in Uri.toString(), read more at https://github.com/microsoft/vscode/commit/65cb3397673b922c1b6759d145a3a183feb3ee5d
144+ // See https://github.com/denoland/vscode_deno/issues/991#issuecomment-1825340906.
145+ configTask . sourceUri
146+ . toLocaleLowerCase ( )
147+ . startsWith ( f . uri . toString ( true ) . toLocaleLowerCase ( ) )
148+ ) ;
149+ if ( ! workspaceFolder ) {
150+ continue ;
179151 }
180- } catch ( err ) {
181- window . showErrorMessage ( "Failed to retrieve config tasks." ) ;
182- this . #extensionContext. outputChannel . appendLine (
183- `Error retrieving config tasks: ${ err } ` ,
152+ const task = buildDenoConfigTask (
153+ workspaceFolder ,
154+ process ,
155+ configTask . name ,
156+ configTask . command ?? configTask . detail ,
157+ Uri . parse ( configTask . sourceUri ) ,
184158 ) ;
159+ tasks . push ( task ) ;
185160 }
161+ } catch ( err ) {
162+ window . showErrorMessage ( "Failed to retrieve config tasks." ) ;
163+ this . #extensionContext. outputChannel . appendLine (
164+ `Error retrieving config tasks: ${ err } ` ,
165+ ) ;
186166 }
187-
188167 return tasks ;
189168 }
190169
@@ -198,16 +177,13 @@ type TaskTree = Folder[] | DenoJSON[] | NoScripts[];
198177
199178export class DenoTasksTreeDataProvider implements TreeDataProvider < TreeItem > {
200179 #taskTree: TaskTree | null = null ;
201- #extensionContext: DenoExtensionContext ;
202180 #onDidChangeTreeData = new EventEmitter < TreeItem | null > ( ) ;
203181 readonly onDidChangeTreeData = this . #onDidChangeTreeData. event ;
204182
205183 constructor (
206- context : DenoExtensionContext ,
207184 public taskProvider : DenoTaskProvider ,
208185 subscriptions : ExtensionContext [ "subscriptions" ] ,
209186 ) {
210- this . #extensionContext = context ;
211187 subscriptions . push (
212188 commands . registerCommand ( "deno.client.runTask" , this . #runTask, this ) ,
213189 ) ;
@@ -401,10 +377,11 @@ export function registerSidebar(
401377 if ( ! workspace . workspaceFolders ) return ;
402378
403379 const taskProvider = new DenoTaskProvider ( context ) ;
404- subscriptions . push ( tasks . registerTaskProvider ( "denoTasks" , taskProvider ) ) ;
380+ subscriptions . push (
381+ tasks . registerTaskProvider ( TASK_TYPE , taskProvider ) ,
382+ ) ;
405383
406384 const treeDataProvider = new DenoTasksTreeDataProvider (
407- context ,
408385 taskProvider ,
409386 subscriptions ,
410387 ) ;
0 commit comments