From cb44f9256c4c60c73761801e6dd0f44cc403255b Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Mon, 29 Jul 2024 13:32:44 +0530 Subject: [PATCH] show workspace extension when offline --- .../common/extensionGalleryService.ts | 8 ++++-- .../common/extensionManagement.ts | 1 + .../extensions/browser/extensionsViews.ts | 25 ++++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/vs/platform/extensionManagement/common/extensionGalleryService.ts b/src/vs/platform/extensionManagement/common/extensionGalleryService.ts index 6a589146d2e37..bbe96046957f5 100644 --- a/src/vs/platform/extensionManagement/common/extensionGalleryService.ts +++ b/src/vs/platform/extensionManagement/common/extensionGalleryService.ts @@ -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'; @@ -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 { diff --git a/src/vs/platform/extensionManagement/common/extensionManagement.ts b/src/vs/platform/extensionManagement/common/extensionManagement.ts index 1dcc4c79e41ad..83ed0c519ca35 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagement.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagement.ts @@ -426,6 +426,7 @@ export const enum ExtensionGalleryErrorCode { Cancelled = 'Cancelled', Failed = 'Failed', DownloadFailedWriting = 'DownloadFailedWriting', + Offline = 'Offline', } export class ExtensionGalleryError extends Error { diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsViews.ts b/src/vs/workbench/contrib/extensions/browser/extensionsViews.ts index 933788b162f06..f2eea7c616d4f 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsViews.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsViews.ts @@ -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'; @@ -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; } } } @@ -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 { @@ -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;