@@ -32,6 +32,40 @@ function makeGroupLabel(label: string): string {
32
32
}
33
33
}
34
34
35
+ function makeGroupName ( name : string ) : string {
36
+ return name
37
+ . replace ( / [ A - Z ] / g, letter => `_${ letter . toLowerCase ( ) } ` )
38
+ . replace ( / \$ / g, '' )
39
+ }
40
+
41
+ async function getIconPath ( name : string ) : Promise < TreeItem [ 'iconPath' ] > {
42
+ // use product icons where applicable
43
+ switch ( name ) {
44
+ case 'composite' :
45
+ return new ThemeIcon ( 'layers' )
46
+ case 'shell' :
47
+ return new ThemeIcon ( 'terminal-view-icon' )
48
+ case groupKeyFavorites :
49
+ return new ThemeIcon ( 'star-full' )
50
+ }
51
+
52
+ const file = join ( __dirname , '..' , 'resources' , 'icons' , `${ name } .svg` )
53
+
54
+ try {
55
+ const stats = await stat ( file )
56
+ if ( stats . isFile ( ) ) {
57
+ return {
58
+ light : file ,
59
+ dark : file
60
+ }
61
+ }
62
+ } catch ( error ) {
63
+ // ¯\_(ツ)_/¯
64
+ }
65
+
66
+ return undefined
67
+ }
68
+
35
69
/**
36
70
* Represents a task group (e.g. npm, shell, etc.)
37
71
*/
@@ -48,41 +82,9 @@ export class GroupItem extends TreeItem {
48
82
this . setIconPath ( )
49
83
}
50
84
51
- private iconName ( ) : string {
52
- return ( this . originalLabel )
53
- . replace ( / [ A - Z ] / g, letter => `_${ letter . toLowerCase ( ) } ` )
54
- . replace ( / \$ / g, '' )
55
- }
56
-
57
85
private async setIconPath ( ) {
58
- const name = this . iconName ( )
59
-
60
- // use product icons where applicable
61
- switch ( name ) {
62
- case 'composite' :
63
- this . iconPath = new ThemeIcon ( 'layers' )
64
- return
65
- case 'shell' :
66
- this . iconPath = new ThemeIcon ( 'terminal-view-icon' )
67
- return
68
- case groupKeyFavorites :
69
- this . iconPath = new ThemeIcon ( 'star-full' )
70
- return
71
- }
72
-
73
- const file = join ( __dirname , '..' , 'resources' , 'icons' , `${ name } .svg` )
74
-
75
- try {
76
- const stats = await stat ( file )
77
- if ( stats . isFile ( ) ) {
78
- this . iconPath = {
79
- light : file ,
80
- dark : file
81
- }
82
- }
83
- } catch ( error ) {
84
- // ¯\_(ツ)_/¯
85
- }
86
+ const name = makeGroupName ( this . originalLabel )
87
+ this . iconPath = await getIconPath ( name )
86
88
}
87
89
88
90
}
@@ -122,6 +124,13 @@ export class FavoriteItem extends TaskItem {
122
124
command : Command ,
123
125
) {
124
126
super ( task , command , true )
127
+
128
+ this . setIconPath ( )
129
+ }
130
+
131
+ private async setIconPath ( ) {
132
+ const name = makeGroupName ( this . task . definition . type )
133
+ this . iconPath = await getIconPath ( name )
125
134
}
126
135
127
136
contextValue = 'favoriteItem'
0 commit comments