Skip to content

Commit

Permalink
show workspace extension when offline
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jul 29, 2024
1 parent 0c5af5d commit cb44f92
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { isWeb, platform } from 'vs/base/common/platform';
import { arch } from 'vs/base/common/process';
import { isBoolean } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { IHeaders, IRequestContext, IRequestOptions } from 'vs/base/parts/request/common/request';
import { IHeaders, IRequestContext, IRequestOptions, isOfflineError } from 'vs/base/parts/request/common/request';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { getTargetPlatform, IExtensionGalleryService, IExtensionIdentifier, IExtensionInfo, IGalleryExtension, IGalleryExtensionAsset, IGalleryExtensionAssets, IGalleryExtensionVersion, InstallOperation, IQueryOptions, IExtensionsControlManifest, isNotWebExtensionInWebTargetPlatform, isTargetPlatformCompatible, ITranslation, SortBy, SortOrder, StatisticType, toTargetPlatform, WEB_EXTENSION_TAG, IExtensionQueryOptions, IDeprecationInfo, ISearchPrefferedResults, ExtensionGalleryError, ExtensionGalleryErrorCode, IProductVersion } from 'vs/platform/extensionManagement/common/extensionManagement';
Expand Down Expand Up @@ -1042,7 +1042,11 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
throw e;
} else {
const errorMessage = getErrorMessage(e);
errorCode = errorMessage.startsWith('XHR timeout') ? ExtensionGalleryErrorCode.Timeout : ExtensionGalleryErrorCode.Failed;
errorCode = isOfflineError(e)
? ExtensionGalleryErrorCode.Offline
: errorMessage.startsWith('XHR timeout')
? ExtensionGalleryErrorCode.Timeout
: ExtensionGalleryErrorCode.Failed;
throw new ExtensionGalleryError(errorMessage, errorCode);
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ export const enum ExtensionGalleryErrorCode {
Cancelled = 'Cancelled',
Failed = 'Failed',
DownloadFailedWriting = 'DownloadFailedWriting',
Offline = 'Offline',
}

export class ExtensionGalleryError extends Error {
Expand Down
25 changes: 19 additions & 6 deletions src/vs/workbench/contrib/extensions/browser/extensionsViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Event, Emitter } from 'vs/base/common/event';
import { isCancellationError, getErrorMessage } from 'vs/base/common/errors';
import { createErrorWithActions } from 'vs/base/common/errorMessage';
import { PagedModel, IPagedModel, IPager, DelayedPagedModel } from 'vs/base/common/paging';
import { SortOrder, IQueryOptions as IGalleryQueryOptions, SortBy as GallerySortBy, InstallExtensionInfo } from 'vs/platform/extensionManagement/common/extensionManagement';
import { SortOrder, IQueryOptions as IGalleryQueryOptions, SortBy as GallerySortBy, InstallExtensionInfo, ExtensionGalleryErrorCode, ExtensionGalleryError } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IExtensionManagementServer, IExtensionManagementServerService, EnablementState, IWorkbenchExtensionManagementService, IWorkbenchExtensionEnablementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { IExtensionRecommendationsService } from 'vs/workbench/services/extensionRecommendations/common/extensionRecommendations';
import { areSameExtensions, getExtensionDependencies } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
Expand Down Expand Up @@ -897,10 +897,16 @@ export class ExtensionsListView extends ViewPane {
}
}
if (galleryExtensions.length) {
const extensions = await this.extensionsWorkbenchService.getExtensions(galleryExtensions.map(id => ({ id })), { source: options.source }, token);
for (const extension of extensions) {
if (extension.gallery && !extension.deprecationInfo && (await this.extensionManagementService.canInstall(extension.gallery))) {
result.push(extension);
try {
const extensions = await this.extensionsWorkbenchService.getExtensions(galleryExtensions.map(id => ({ id })), { source: options.source }, token);
for (const extension of extensions) {
if (extension.gallery && !extension.deprecationInfo && (await this.extensionManagementService.canInstall(extension.gallery))) {
result.push(extension);
}
}
} catch (error) {
if (!resourceExtensions.length || !this.isOfflineError(error)) {
throw error;
}
}
}
Expand Down Expand Up @@ -1067,7 +1073,7 @@ export class ExtensionsListView extends ViewPane {

if (count === 0 && this.isBodyVisible()) {
if (error) {
if (isOfflineError(error)) {
if (this.isOfflineError(error)) {
this.bodyTemplate.messageSeverityIcon.className = SeverityIcon.className(Severity.Warning);
this.bodyTemplate.messageBox.textContent = localize('offline error', "Unable to search the Marketplace when offline, please check your network connection.");
} else {
Expand All @@ -1085,6 +1091,13 @@ export class ExtensionsListView extends ViewPane {
this.updateSize();
}

private isOfflineError(error: Error): boolean {
if (error instanceof ExtensionGalleryError) {
return error.code === ExtensionGalleryErrorCode.Offline;
}
return isOfflineError(error);
}

protected updateSize() {
if (this.options.flexibleHeight) {
this.maximumBodySize = this.list?.model.length ? Number.POSITIVE_INFINITY : 0;
Expand Down

0 comments on commit cb44f92

Please sign in to comment.