Skip to content

Commit

Permalink
Refactor fix for #188104 (#190977)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored Aug 22, 2023
1 parent f511840 commit 026f38a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as nls from 'vs/nls';
import {
ExtensionManagementError, IExtensionGalleryService, IExtensionIdentifier, IExtensionManagementParticipant, IGalleryExtension, ILocalExtension, InstallOperation,
IExtensionsControlManifest, StatisticType, isTargetPlatformCompatible, TargetPlatformToString, ExtensionManagementErrorCode,
InstallOptions, InstallVSIXOptions, UninstallOptions, Metadata, InstallExtensionEvent, DidUninstallExtensionEvent, InstallExtensionResult, UninstallExtensionEvent, IExtensionManagementService, InstallExtensionInfo, EXTENSION_INSTALL_SKIP_WALKTHROUGH_CONTEXT
InstallOptions, InstallVSIXOptions, UninstallOptions, Metadata, InstallExtensionEvent, DidUninstallExtensionEvent, InstallExtensionResult, UninstallExtensionEvent, IExtensionManagementService, InstallExtensionInfo, EXTENSION_INSTALL_DEP_PACK_CONTEXT
} from 'vs/platform/extensionManagement/common/extensionManagement';
import { areSameExtensions, ExtensionKey, getGalleryExtensionId, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { ExtensionType, IExtensionManifest, isApplicationScopedExtension, TargetPlatform } from 'vs/platform/extensions/common/extensions';
Expand All @@ -35,6 +35,7 @@ export interface IInstallExtensionTask {
readonly source: IGalleryExtension | URI;
readonly operation: InstallOperation;
readonly profileLocation: URI;
readonly options: InstallExtensionTaskOptions;
readonly verificationStatus?: ExtensionVerificationStatus;
run(): Promise<ILocalExtension>;
waitUntilTaskIsFinished(): Promise<ILocalExtension>;
Expand Down Expand Up @@ -248,14 +249,14 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
allInstallExtensionTasks.push({ task: installExtensionTask, manifest });
let installExtensionHasDependents: boolean = false;

const hasPackExtensions = manifest.extensionPack && manifest.extensionPack.length > 0;
try {
if (installExtensionTaskOptions.donotIncludePackAndDependencies) {
this.logService.info('Installing the extension without checking dependencies and pack', installExtensionTask.identifier.id);
} else {
try {
const allDepsAndPackExtensionsToInstall = await this.getAllDepsAndPackExtensions(installExtensionTask.identifier, manifest, !!installExtensionTaskOptions.installOnlyNewlyAddedFromExtensionPack, !!installExtensionTaskOptions.installPreReleaseVersion, installExtensionTaskOptions.profileLocation);
const installed = await this.getInstalled(undefined, installExtensionTaskOptions.profileLocation);
const options: InstallExtensionTaskOptions = { ...installExtensionTaskOptions, donotIncludePackAndDependencies: true, context: { ...installExtensionTaskOptions.context, [EXTENSION_INSTALL_DEP_PACK_CONTEXT]: true } };
for (const { gallery, manifest } of distinct(allDepsAndPackExtensionsToInstall, ({ gallery }) => gallery.identifier.id)) {
installExtensionHasDependents = installExtensionHasDependents || !!manifest.extensionDependencies?.some(id => areSameExtensions({ id }, installExtensionTask.identifier));
const key = getInstallExtensionTaskKey(gallery);
Expand All @@ -279,7 +280,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
}));
}
} else if (!installed.some(({ identifier }) => areSameExtensions(identifier, gallery.identifier))) {
const task = this.createInstallExtensionTask(manifest, gallery, { ...installExtensionTaskOptions, donotIncludePackAndDependencies: true });
const task = this.createInstallExtensionTask(manifest, gallery, options);
this.installingExtensions.set(key, { task, waitingTasks: [installExtensionTask] });
this._onInstallExtension.fire({ identifier: task.identifier, source: gallery, profileLocation: installExtensionTaskOptions.profileLocation });
this.logService.info('Installing extension:', task.identifier.id, installExtensionTask.identifier.id);
Expand Down Expand Up @@ -343,12 +344,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
}
}

const context = installExtensionTaskOptions.context ?? {};
if (hasPackExtensions && task.identifier.id !== installExtensionTask.identifier.id) {
context[EXTENSION_INSTALL_SKIP_WALKTHROUGH_CONTEXT] = true;
}

installResults.push({ local, identifier: task.identifier, operation: task.operation, source: task.source, context: context, profileLocation: task.profileLocation, applicationScoped: local.isApplicationScoped });
installResults.push({ local, identifier: task.identifier, operation: task.operation, source: task.source, context: task.options.context, profileLocation: task.profileLocation, applicationScoped: local.isApplicationScoped });
} catch (error) {
if (!URI.isUri(task.source)) {
reportTelemetry(this.telemetryService, task.operation === InstallOperation.Update ? 'extensionGallery:update' : 'extensionGallery:install', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const EXTENSION_IDENTIFIER_REGEX = new RegExp(EXTENSION_IDENTIFIER_PATTER
export const WEB_EXTENSION_TAG = '__web_extension';
export const EXTENSION_INSTALL_SKIP_WALKTHROUGH_CONTEXT = 'skipWalkthrough';
export const EXTENSION_INSTALL_SYNC_CONTEXT = 'extensionsSync';
export const EXTENSION_INSTALL_DEP_PACK_CONTEXT = 'dependecyOrPackExtensionInstall';

export function TargetPlatformToString(targetPlatform: TargetPlatform) {
switch (targetPlatform) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ abstract class InstallExtensionTask extends AbstractExtensionTask<ILocalExtensio
constructor(
readonly identifier: IExtensionIdentifier,
readonly source: URI | IGalleryExtension,
protected readonly options: InstallExtensionTaskOptions,
readonly options: InstallExtensionTaskOptions,
protected readonly extensionsScanner: ExtensionsScanner,
protected readonly uriIdentityService: IUriIdentityService,
protected readonly userDataProfilesService: IUserDataProfilesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { URI } from 'vs/base/common/uri';
import { joinPath } from 'vs/base/common/resources';
import { FileAccess } from 'vs/base/common/network';
import { EXTENSION_INSTALL_SKIP_WALKTHROUGH_CONTEXT, IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { EXTENSION_INSTALL_DEP_PACK_CONTEXT, EXTENSION_INSTALL_SKIP_WALKTHROUGH_CONTEXT, IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ThemeIcon } from 'vs/base/common/themables';
import { walkthroughs } from 'vs/workbench/contrib/welcomeGettingStarted/common/gettingStartedContent';
import { IWorkbenchAssignmentService } from 'vs/workbench/services/assignment/common/assignmentService';
Expand Down Expand Up @@ -229,9 +229,10 @@ export class WalkthroughsService extends Disposable implements IWalkthroughsServ
this._register(this.extensionManagementService.onDidInstallExtensions(async (result) => {
const hadLastFoucs = await this.hostService.hadLastFocus();
for (const e of result) {
const skipWalkthrough = e?.context?.[EXTENSION_INSTALL_SKIP_WALKTHROUGH_CONTEXT] || e?.context?.[EXTENSION_INSTALL_DEP_PACK_CONTEXT];
// If the window had last focus and the install didn't specify to skip the walkthrough
// Then add it to the sessionInstallExtensions to be opened
if (hadLastFoucs && !e?.context?.[EXTENSION_INSTALL_SKIP_WALKTHROUGH_CONTEXT]) {
if (hadLastFoucs && !skipWalkthrough) {
this.sessionInstalledExtensions.add(e.identifier.id.toLowerCase());
}
this.progressByEvent(`extensionInstalled:${e.identifier.id.toLowerCase()}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class InstallExtensionTask extends AbstractExtensionTask<ILocalExtension> implem
constructor(
manifest: IExtensionManifest,
private readonly extension: URI | IGalleryExtension,
private readonly options: InstallExtensionTaskOptions,
readonly options: InstallExtensionTaskOptions,
private readonly webExtensionsScannerService: IWebExtensionsScannerService,
private readonly userDataProfilesService: IUserDataProfilesService,
) {
Expand Down

0 comments on commit 026f38a

Please sign in to comment.