Skip to content

Commit 20c0679

Browse files
committed
refator: options
1 parent 5061e3b commit 20c0679

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/extension.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@ export function activate (context: vscode.ExtensionContext) {
1111
'http://localhost:3033/snippets/embed-folder'
1212
)
1313

14-
const options: vscode.QuickPickItem[] = []
14+
const options = data
15+
.filter(i => !i.isDeleted)
16+
.reduce((acc: vscode.QuickPickItem[], snippet) => {
17+
const fragments = snippet.content.map(fragment => {
18+
return {
19+
label: snippet.name || '',
20+
detail: snippet.content.length > 1 ? fragment.label : '',
21+
description: `${fragment.language}${
22+
snippet.folder?.name || 'Inbox'
23+
}`
24+
}
25+
})
1526

16-
for (const snippet of data) {
17-
if (snippet.isDeleted) continue
27+
acc.push(...fragments)
1828

19-
for (const fragment of snippet.content) {
20-
let fragmentLabel = ''
21-
if (snippet.content.length > 1) {
22-
fragmentLabel = fragment.label
23-
}
24-
options.push({
25-
label: `${snippet.name || ''}`,
26-
detail: `${fragmentLabel}`,
27-
description: `${fragment.language}${
28-
snippet.folder?.name || 'Inbox'
29-
}`
30-
})
31-
}
32-
}
29+
return acc
30+
}, []) as vscode.QuickPickItem[]
3331

3432
let fragmentContent = ''
3533

0 commit comments

Comments
 (0)