Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fix #161558

* fix tests
  • Loading branch information
sandy081 authored Oct 6, 2022
1 parent b1c1b3b commit aef171d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,6 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
}

async query(options: IQueryOptions, token: CancellationToken): Promise<IPager<IGalleryExtension>> {
if (!this.isEnabled()) {
throw new Error('No extension gallery service configured.');
}

let text = options.text || '';
const pageSize = options.pageSize ?? 50;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { EnablementState, IExtensionManagementServerService, IWorkbenchExtension
import { IExtensionIgnoredRecommendationsService, IExtensionRecommendationsService } from 'vs/workbench/services/extensionRecommendations/common/extensionRecommendations';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { VIEWLET_ID, IExtensionsWorkbenchService, IExtensionsViewPaneContainer, TOGGLE_IGNORE_EXTENSION_ACTION_ID, INSTALL_EXTENSION_FROM_VSIX_COMMAND_ID, WORKSPACE_RECOMMENDATIONS_VIEW_ID, IWorkspaceRecommendedExtensionsView, AutoUpdateConfigurationKey, HasOutdatedExtensionsContext, SELECT_INSTALL_VSIX_EXTENSION_COMMAND_ID, LIST_WORKSPACE_UNSUPPORTED_EXTENSIONS_COMMAND_ID, ExtensionEditorTab, THEME_ACTIONS_GROUP, INSTALL_ACTIONS_GROUP, OUTDATED_EXTENSIONS_VIEW_ID } from 'vs/workbench/contrib/extensions/common/extensions';
import { VIEWLET_ID, IExtensionsWorkbenchService, IExtensionsViewPaneContainer, TOGGLE_IGNORE_EXTENSION_ACTION_ID, INSTALL_EXTENSION_FROM_VSIX_COMMAND_ID, WORKSPACE_RECOMMENDATIONS_VIEW_ID, IWorkspaceRecommendedExtensionsView, AutoUpdateConfigurationKey, HasOutdatedExtensionsContext, SELECT_INSTALL_VSIX_EXTENSION_COMMAND_ID, LIST_WORKSPACE_UNSUPPORTED_EXTENSIONS_COMMAND_ID, ExtensionEditorTab, THEME_ACTIONS_GROUP, INSTALL_ACTIONS_GROUP, OUTDATED_EXTENSIONS_VIEW_ID, CONTEXT_HAS_GALLERY } from 'vs/workbench/contrib/extensions/common/extensions';
import { ReinstallAction, InstallSpecificVersionOfExtensionAction, ConfigureWorkspaceRecommendedExtensionsAction, ConfigureWorkspaceFolderRecommendedExtensionsAction, PromptExtensionInstallFailureAction, SearchExtensionsAction, SwitchToPreReleaseVersionAction, SwitchToReleasedVersionAction, SetColorThemeAction, SetFileIconThemeAction, SetProductIconThemeAction, ClearLanguageAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions';
import { ExtensionsInput } from 'vs/workbench/contrib/extensions/common/extensionsInput';
import { ExtensionEditor } from 'vs/workbench/contrib/extensions/browser/extensionEditor';
Expand Down Expand Up @@ -434,7 +434,6 @@ overrideActionForActiveExtensionEditorWebview(CutAction, webview => webview.cut(
overrideActionForActiveExtensionEditorWebview(PasteAction, webview => webview.paste());

// Contexts
export const CONTEXT_HAS_GALLERY = new RawContextKey<boolean>('hasGallery', false);
export const CONTEXT_HAS_LOCAL_SERVER = new RawContextKey<boolean>('hasLocalServer', false);
export const CONTEXT_HAS_REMOTE_SERVER = new RawContextKey<boolean>('hasRemoteServer', false);
export const CONTEXT_HAS_WEB_SERVER = new RawContextKey<boolean>('hasWebServer', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { append, $, Dimension, hide, show, DragAndDropObserver } from 'vs/base/b
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IExtensionsWorkbenchService, IExtensionsViewPaneContainer, VIEWLET_ID, CloseExtensionDetailsOnViewChangeKey, INSTALL_EXTENSION_FROM_VSIX_COMMAND_ID, WORKSPACE_RECOMMENDATIONS_VIEW_ID, AutoCheckUpdatesConfigurationKey, OUTDATED_EXTENSIONS_VIEW_ID } from '../common/extensions';
import { IExtensionsWorkbenchService, IExtensionsViewPaneContainer, VIEWLET_ID, CloseExtensionDetailsOnViewChangeKey, INSTALL_EXTENSION_FROM_VSIX_COMMAND_ID, WORKSPACE_RECOMMENDATIONS_VIEW_ID, AutoCheckUpdatesConfigurationKey, OUTDATED_EXTENSIONS_VIEW_ID, CONTEXT_HAS_GALLERY } from '../common/extensions';
import { InstallLocalExtensionsInRemoteAction, InstallRemoteExtensionsInLocalAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions';
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IWorkbenchExtensionEnablementService, IExtensionManagementServerService, IExtensionManagementServer } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
Expand Down Expand Up @@ -212,7 +212,7 @@ export class ExtensionsViewletViewsContribution implements IWorkbenchContributio
id: 'workbench.views.extensions.popular',
name: localize('popularExtensions', "Popular"),
ctorDescriptor: new SyncDescriptor(DefaultPopularExtensionsView, [{ hideBadge: true }]),
when: ContextKeyExpr.and(DefaultViewsContext, ContextKeyExpr.not('hasInstalledExtensions')),
when: ContextKeyExpr.and(DefaultViewsContext, ContextKeyExpr.not('hasInstalledExtensions'), CONTEXT_HAS_GALLERY),
weight: 60,
order: 2,
canToggleVisibility: false
Expand All @@ -227,7 +227,7 @@ export class ExtensionsViewletViewsContribution implements IWorkbenchContributio
id: 'extensions.recommendedList',
name: localize('recommendedExtensions', "Recommended"),
ctorDescriptor: new SyncDescriptor(DefaultRecommendedExtensionsView, [{ flexibleHeight: true }]),
when: ContextKeyExpr.and(DefaultViewsContext, SortByUpdateDateContext.negate(), ContextKeyExpr.not('config.extensions.showRecommendationsOnlyOnDemand')),
when: ContextKeyExpr.and(DefaultViewsContext, SortByUpdateDateContext.negate(), ContextKeyExpr.not('config.extensions.showRecommendationsOnlyOnDemand'), CONTEXT_HAS_GALLERY),
weight: 40,
order: 3,
canToggleVisibility: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,38 +894,38 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
queryGallery(token: CancellationToken): Promise<IPager<IExtension>>;
queryGallery(options: IQueryOptions, token: CancellationToken): Promise<IPager<IExtension>>;
async queryGallery(arg1: any, arg2?: any): Promise<IPager<IExtension>> {
if (!this.galleryService.isEnabled()) {
return singlePagePager([]);
}

const options: IQueryOptions = CancellationToken.isCancellationToken(arg1) ? {} : arg1;
const token: CancellationToken = CancellationToken.isCancellationToken(arg1) ? arg1 : arg2;
options.text = options.text ? this.resolveQueryText(options.text) : options.text;
options.includePreRelease = isUndefined(options.includePreRelease) ? this.preferPreReleases : options.includePreRelease;

const extensionsControlManifest = await this.extensionManagementService.getExtensionsControlManifest();
try {
const pager = await this.galleryService.query(options, token);
this.syncInstalledExtensionsWithGallery(pager.firstPage);
return {
firstPage: pager.firstPage.map(gallery => this.fromGallery(gallery, extensionsControlManifest)),
total: pager.total,
pageSize: pager.pageSize,
getPage: async (pageIndex, token) => {
const page = await pager.getPage(pageIndex, token);
this.syncInstalledExtensionsWithGallery(page);
return page.map(gallery => this.fromGallery(gallery, extensionsControlManifest));
}
};
} catch (error) {
if (/No extension gallery service configured/.test(error.message)) {
return Promise.resolve(singlePagePager([]));
const pager = await this.galleryService.query(options, token);
this.syncInstalledExtensionsWithGallery(pager.firstPage);
return {
firstPage: pager.firstPage.map(gallery => this.fromGallery(gallery, extensionsControlManifest)),
total: pager.total,
pageSize: pager.pageSize,
getPage: async (pageIndex, token) => {
const page = await pager.getPage(pageIndex, token);
this.syncInstalledExtensionsWithGallery(page);
return page.map(gallery => this.fromGallery(gallery, extensionsControlManifest));
}
throw error;
}
};
}

getExtensions(extensionInfos: IExtensionInfo[], token: CancellationToken): Promise<IExtension[]>;
getExtensions(extensionInfos: IExtensionInfo[], options: IExtensionQueryOptions, token: CancellationToken): Promise<IExtension[]>;
async getExtensions(extensionInfos: IExtensionInfo[], arg1: any, arg2?: any): Promise<IExtension[]> {
extensionInfos.forEach(e => e.preRelease = e.preRelease ?? this.preferPreReleases);
if (!this.galleryService.isEnabled()) {
return [];
}

extensionInfos.forEach(e => e.preRelease = e.preRelease ?? this.preferPreReleases);
const extensionsControlManifest = await this.extensionManagementService.getExtensionsControlManifest();
const galleryExtensions = await this.galleryService.getExtensions(extensionInfos, arg1, arg2);
this.syncInstalledExtensionsWithGallery(galleryExtensions);
Expand Down Expand Up @@ -1215,6 +1215,9 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
}

async checkForUpdates(onlyBuiltin?: boolean): Promise<void> {
if (!this.galleryService.isEnabled()) {
return;
}
const extensions: Extensions[] = [];
if (this.localExtensions) {
extensions.push(this.localExtensions);
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/extensions/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export const LIST_WORKSPACE_UNSUPPORTED_EXTENSIONS_COMMAND_ID = 'workbench.exten

// Context Keys
export const HasOutdatedExtensionsContext = new RawContextKey<boolean>('hasOutdatedExtensions', false);
export const CONTEXT_HAS_GALLERY = new RawContextKey<boolean>('hasGallery', false);

// Context Menu Groups
export const THEME_ACTIONS_GROUP = '_theme_';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function setupTest() {
instantiationService.stub(IExtensionRecommendationsService, {});
instantiationService.stub(IURLService, NativeURLService);

instantiationService.stub(IExtensionGalleryService, 'isEnabled', true);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage());
instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', []);
instantiationService.stub(IExtensionService, <Partial<IExtensionService>>{ extensions: [], onDidChangeExtensions: Event.None, canAddExtension: (extension: IExtensionDescription) => false, canRemoveExtension: (extension: IExtensionDescription) => false, whenInstalledExtensionsRegistered: () => Promise.resolve(true) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ suite('ExtensionsViews Tests', () => {
setup(async () => {
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [localEnabledTheme, localEnabledLanguage, localRandom, localDisabledTheme, localDisabledLanguage, builtInTheme, builtInBasic]);
instantiationService.stubPromise(IExtensionManagementService, 'getExtensgetExtensionsControlManifestionsReport', {});
instantiationService.stub(IExtensionGalleryService, 'isEnabled', true);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(galleryEnabledLanguage));
instantiationService.stubPromise(IExtensionGalleryService, 'getCompatibleExtension', galleryEnabledLanguage);
instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', [galleryEnabledLanguage]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ suite('ExtensionsWorkbenchServiceTest', () => {

setup(async () => {
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', []);
instantiationService.stub(IExtensionGalleryService, 'isEnabled', true);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage());
instantiationService.stubPromise(IExtensionGalleryService, 'getExtensions', []);
instantiationService.stubPromise(INotificationService, 'prompt', 0);
Expand Down

0 comments on commit aef171d

Please sign in to comment.