17
18
static suggestions(query: string, galleryManifest: IExtensionGalleryManifest | null): string[] {
20
>
const commands = ['installed', 'updates', 'enabled', 'disabled', 'builtin', 'contribute'];
21
>
if (galleryManifest?.capabilities.extensionQuery?.filtering?.some(c => c.name === FilterType.Featured)) {
22
commands.push('featured');
23
}
25
>
commands.push(...['mcp', 'agentPlugins', 'popular', 'recommended', 'recentlyPublished', 'workspaceUnsupported', 'deprecated', 'sort']);
26
>
const isCategoriesEnabled = galleryManifest?.capabilities.extensionQuery?.filtering?.some(c => c.name === FilterType.Category);
27
>
if (isCategoriesEnabled) {
28
commands.push('category');
29
}
31
>
commands.push(...['tag', 'ext', 'id', 'outdated', 'recentlyUpdated', 'restartRequired']);
32
>
const sortCommands = [];
33
>
if (galleryManifest?.capabilities.extensionQuery?.sorting?.some(c => c.name === SortBy.InstallCount)) {
34
sortCommands.push('installs');
35
}
36
>
if (galleryManifest?.capabilities.extensionQuery?.sorting?.some(c => c.name === SortBy.WeightedRating)) {
extensionQuery.ts
37
sortCommands.push('rating');
38
}
40
>
41
>
const contributeCommands = [];
42
>
for (const feature of Registry.as<IExtensionFeaturesRegistry>(Extensions.ExtensionFeaturesRegistry).getExtensionFeatures()) {
43
contributeCommands.push(feature.id);
44
}
46
>
const subcommands = {
47
>
'sort': sortCommands,
48
>
'category': isCategoriesEnabled ? EXTENSION_CATEGORIES.map(c => `"${c.toLowerCase()}"`) : [],
49
>
'tag': [''],
50
>
'ext': [''],
51
>
'id': [''],
52
>
'contribute': contributeCommands
53
>
} as const;
54
>
55
>
const queryContains = (substr: string) => query.indexOf(substr) > -1;
56
>
const hasSort = subcommands.sort.some(subcommand => queryContains(`@sort:${subcommand}`));
57
>
const hasCategory = subcommands.category.some(subcommand => queryContains(`@category:${subcommand}`));
58
>
59
>
return commands.flatMap(command => {
60
>
if (hasSort && command === 'sort' || hasCategory && command === 'category') {
61
return [];
62
}
64
>
return (subcommands as Record<string, readonly string[]>)[command]
65
>
.map(subcommand => `@${command}:${subcommand}${subcommand === '' ? '' : ' '}`);
66
>
}
67
>
else {
68
>
return queryContains(`@${command}`) ? [] : [`@${command} `];
69
>
}
70
>
});
71
>
}
72
73
static parse(value: string): Query {