Skip to content

Commit 070314c

Browse files
committed
feat: display icon next to favorite tasks
1 parent 9a54df1 commit 070314c

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

src/services/task-data-provider.ts

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,40 @@ function makeGroupLabel(label: string): string {
3232
}
3333
}
3434

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+
3569
/**
3670
* Represents a task group (e.g. npm, shell, etc.)
3771
*/
@@ -48,41 +82,9 @@ export class GroupItem extends TreeItem {
4882
this.setIconPath()
4983
}
5084

51-
private iconName(): string {
52-
return (this.originalLabel)
53-
.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`)
54-
.replace(/\$/g, '')
55-
}
56-
5785
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)
8688
}
8789

8890
}
@@ -122,6 +124,13 @@ export class FavoriteItem extends TaskItem {
122124
command: Command,
123125
) {
124126
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)
125134
}
126135

127136
contextValue = 'favoriteItem'

0 commit comments

Comments
 (0)