File tree Expand file tree Collapse file tree 3 files changed +55
-4
lines changed Expand file tree Collapse file tree 3 files changed +55
-4
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "editor.defaultFormatter" : " esbenp.prettier-vscode" ,
2
+ "[javascriptreact]" : {
3
+ "editor.defaultFormatter" : " esbenp.prettier-vscode"
4
+ },
5
+ "[typescriptreact]" : {
6
+ "editor.defaultFormatter" : " esbenp.prettier-vscode"
7
+ },
8
+ "[typescript]" : {
9
+ "editor.defaultFormatter" : " esbenp.prettier-vscode"
10
+ },
11
+ "[scss]" : {
12
+ "editor.defaultFormatter" : " esbenp.prettier-vscode"
13
+ },
14
+ "[javascript]" : {
15
+ "editor.defaultFormatter" : " esbenp.prettier-vscode"
16
+ },
17
+ "[html]" : {
18
+ "editor.defaultFormatter" : " esbenp.prettier-vscode"
19
+ },
20
+ "[css]" : {
21
+ "editor.defaultFormatter" : " esbenp.prettier-vscode"
22
+ },
23
+ "[yaml]" : {
24
+ "editor.defaultFormatter" : null
25
+ },
3
26
"editor.formatOnSave" : true
4
27
}
Original file line number Diff line number Diff line change @@ -230,15 +230,24 @@ export class PyTaskProvider implements vscode.TreeDataProvider<TreeItemType> {
230
230
const lines = content . split ( "\n" ) ;
231
231
232
232
let isDecorated = false ;
233
+ let taskName : string | undefined ;
233
234
for ( let i = 0 ; i < lines . length ; i ++ ) {
234
235
const line = lines [ i ] . trim ( ) ;
235
236
236
237
// Check for decorators
237
238
if ( line . startsWith ( "@" ) ) {
238
239
// Handle both @task and @pytask.task(...) patterns
239
240
isDecorated =
240
- ( hasTaskImport && line === `@${ taskAlias } ` ) ||
241
+ ( hasTaskImport && ( line === `@${ taskAlias } ` || line . startsWith ( `@ ${ taskAlias } (` ) ) ) ||
241
242
( hasPytaskImport && line . startsWith ( `@${ pytaskAlias } .task` ) ) ;
243
+
244
+ // Extract name from decorator if present
245
+ if ( isDecorated ) {
246
+ const nameMatch = line . match ( / n a m e \s * = \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / ) ;
247
+ if ( nameMatch ) {
248
+ taskName = nameMatch [ 1 ] ;
249
+ }
250
+ }
242
251
continue ;
243
252
}
244
253
@@ -248,9 +257,10 @@ export class PyTaskProvider implements vscode.TreeDataProvider<TreeItemType> {
248
257
const funcName = funcMatch [ 1 ] ;
249
258
// Add if it's a task_* function or has a task decorator
250
259
if ( funcName . startsWith ( "task_" ) || isDecorated ) {
251
- tasks . push ( new TaskItem ( funcName , filePath , i + 1 ) ) ;
260
+ tasks . push ( new TaskItem ( taskName || funcName , filePath , i + 1 ) ) ;
252
261
}
253
- isDecorated = false ; // Reset decorator flag
262
+ isDecorated = false ;
263
+ taskName = undefined ; // Reset task name
254
264
}
255
265
}
256
266
Original file line number Diff line number Diff line change @@ -363,4 +363,22 @@ def decorated_task(): # line 8
363
363
expect ( tasks [ 1 ] . label ) . to . equal ( "task_one" ) ;
364
364
expect ( tasks [ 1 ] . lineNumber ) . to . equal ( 4 ) ;
365
365
} ) ;
366
+
367
+ test ( "Should handle tasks that set a new name via the decorator" , ( ) => {
368
+ const content = `
369
+ from pytask import task
370
+
371
+ @task(name="new_name")
372
+ def task_one():
373
+ pass
374
+
375
+ @task(kwargs={}, name="second_new_name")
376
+ def task_two():
377
+ pass
378
+ ` ;
379
+ const tasks = provider . findTaskFunctions ( dummyPath , content ) ;
380
+ expect ( tasks ) . to . have . lengthOf ( 2 , "Should find both tasks" ) ;
381
+ expect ( tasks [ 0 ] . label ) . to . equal ( "new_name" ) ;
382
+ expect ( tasks [ 1 ] . label ) . to . equal ( "second_new_name" ) ;
383
+ } ) ;
366
384
} ) ;
You can’t perform that action at this time.
0 commit comments