Skip to content

Commit c9282b2

Browse files
authored
1 parent 5a4e405 commit c9282b2

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

src/vs/workbench/contrib/extensions/browser/extensionsViews.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface ExtensionsListViewOptions {
9191

9292
interface IQueryResult {
9393
model: IPagedModel<IExtension>;
94-
description?: string;
94+
message?: { text: string; severity: Severity };
9595
readonly onDidChangeModel?: Event<IPagedModel<IExtension>>;
9696
readonly disposables: DisposableStore;
9797
}
@@ -248,7 +248,7 @@ export class ExtensionsListView extends ViewPane {
248248
try {
249249
this.queryResult = await this.query(parsedQuery, options, token);
250250
const model = this.queryResult.model;
251-
this.setModel(model, this.queryResult.description ? { text: this.queryResult.description, severity: Severity.Info } : undefined);
251+
this.setModel(model, this.queryResult.message);
252252
if (this.queryResult.onDidChangeModel) {
253253
this.queryResult.disposables.add(this.queryResult.onDidChangeModel(model => {
254254
if (this.queryResult) {
@@ -310,8 +310,7 @@ export class ExtensionsListView extends ViewPane {
310310
}
311311

312312
const galleryQueryOptions: IGalleryQueryOptions = { ...options, sortBy: isLocalSortBy(options.sortBy) ? undefined : options.sortBy };
313-
const model = await this.queryGallery(query, galleryQueryOptions, token);
314-
return { model, disposables: new DisposableStore() };
313+
return this.queryGallery(query, galleryQueryOptions, token);
315314
}
316315

317316
private async queryByIds(ids: string[], options: IQueryOptions, token: CancellationToken): Promise<IPagedModel<IExtension>> {
@@ -356,7 +355,7 @@ export class ExtensionsListView extends ViewPane {
356355

357356
return {
358357
model: new PagedModel(extensions),
359-
description,
358+
message: description ? { text: description, severity: Severity.Info } : undefined,
360359
onDidChangeModel: onDidChangeModel.event,
361360
disposables
362361
};
@@ -720,45 +719,66 @@ export class ExtensionsListView extends ViewPane {
720719
return hasChanged ? extensions : undefined;
721720
}
722721

723-
private async queryGallery(query: Query, options: IGalleryQueryOptions, token: CancellationToken): Promise<IPagedModel<IExtension>> {
722+
private async queryGallery(query: Query, options: IGalleryQueryOptions, token: CancellationToken): Promise<IQueryResult> {
724723
const hasUserDefinedSortOrder = options.sortBy !== undefined;
725724
if (!hasUserDefinedSortOrder && !query.value.trim()) {
726725
options.sortBy = GallerySortBy.InstallCount;
727726
}
728727

729728
if (this.isRecommendationsQuery(query)) {
730-
return this.queryRecommendations(query, options, token);
729+
const model = await this.queryRecommendations(query, options, token);
730+
return { model, disposables: new DisposableStore() };
731731
}
732732

733733
const text = query.value;
734734

735735
if (!text) {
736736
options.source = 'viewlet';
737737
const pager = await this.extensionsWorkbenchService.queryGallery(options, token);
738-
return new PagedModel(pager);
738+
return { model: new PagedModel(pager), disposables: new DisposableStore() };
739739
}
740740

741741
if (/\bext:([^\s]+)\b/g.test(text)) {
742742
options.text = text;
743743
options.source = 'file-extension-tags';
744744
const pager = await this.extensionsWorkbenchService.queryGallery(options, token);
745-
return new PagedModel(pager);
745+
return { model: new PagedModel(pager), disposables: new DisposableStore() };
746746
}
747747

748748
options.text = text.substring(0, 350);
749749
options.source = 'searchText';
750750

751751
if (hasUserDefinedSortOrder || /\b(category|tag):([^\s]+)\b/gi.test(text) || /\bfeatured(\s+|\b|$)/gi.test(text)) {
752752
const pager = await this.extensionsWorkbenchService.queryGallery(options, token);
753-
return new PagedModel(pager);
753+
return { model: new PagedModel(pager), disposables: new DisposableStore() };
754754
}
755755

756-
const [pager, preferredExtensions] = await Promise.all([
757-
this.extensionsWorkbenchService.queryGallery(options, token),
758-
this.getPreferredExtensions(options.text.toLowerCase(), token).catch(() => [])
759-
]);
756+
try {
757+
const [pager, preferredExtensions] = await Promise.all([
758+
this.extensionsWorkbenchService.queryGallery(options, token),
759+
this.getPreferredExtensions(options.text.toLowerCase(), token).catch(() => [])
760+
]);
761+
762+
const model = preferredExtensions.length ? new PreferredExtensionsPagedModel(preferredExtensions, pager) : new PagedModel(pager);
763+
return { model, disposables: new DisposableStore() };
764+
} catch (error) {
765+
if (isCancellationError(error)) {
766+
throw error;
767+
}
760768

761-
return preferredExtensions.length ? new PreferredExtensionsPagedModel(preferredExtensions, pager) : new PagedModel(pager);
769+
if (!(error instanceof ExtensionGalleryError)) {
770+
throw error;
771+
}
772+
773+
const searchText = options.text.toLowerCase();
774+
const localExtensions = this.extensionsWorkbenchService.local.filter(e => !e.isBuiltin && (e.name.toLowerCase().indexOf(searchText) > -1 || e.displayName.toLowerCase().indexOf(searchText) > -1 || e.description.toLowerCase().indexOf(searchText) > -1));
775+
if (localExtensions.length) {
776+
const message = this.getMessage(error);
777+
return { model: new PagedModel(localExtensions), disposables: new DisposableStore(), message: { text: localize('showing local extensions only', "{0} Showing local extensions.", message.text), severity: message.severity } };
778+
}
779+
780+
throw error;
781+
}
762782
}
763783

764784
private async getPreferredExtensions(searchText: string, token: CancellationToken): Promise<IExtension[]> {

0 commit comments

Comments
 (0)