Skip to content

Commit

Permalink
fix #211965
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed May 29, 2024
1 parent 6e37770 commit ca280cc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/vs/server/node/remoteExtensionsScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class RemoteExtensionsScannerService implements IRemoteExtensionsScannerS
this._scanDevelopedExtensions(language, extensionDevelopmentPath)
]);

return dedupExtensions(builtinExtensions, [...installedExtensions, ...workspaceInstalledExtensions], developedExtensions, this._logService);
return dedupExtensions(builtinExtensions, installedExtensions, workspaceInstalledExtensions, developedExtensions, this._logService);
}

private async _scanDevelopedExtensions(language: string, extensionDevelopmentPaths?: string[]): Promise<IExtensionDescription[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,28 @@ class Extensions extends Disposable {
all.push(...await this.workbenchExtensionManagementService.getInstalledWorkspaceExtensions(true));
}

// dedup user and system extensions by giving priority to user extensions.
// dedup workspace, user and system extensions by giving priority to workspace first and then to user extension.
const installed = groupByExtension(all, r => r.identifier).reduce((result, extensions) => {
const extension = extensions.length === 1 ? extensions[0]
: extensions.find(e => e.type === ExtensionType.User) || extensions.find(e => e.type === ExtensionType.System);
result.push(extension!);
if (extensions.length === 1) {
result.push(extensions[0]);
} else {
let workspaceExtension: ILocalExtension | undefined,
userExtension: ILocalExtension | undefined,
systemExtension: ILocalExtension | undefined;
for (const extension of extensions) {
if (extension.isWorkspaceScoped) {
workspaceExtension = extension;
} else if (extension.type === ExtensionType.User) {
userExtension = extension;
} else {
systemExtension = extension;
}
}
const extension = workspaceExtension ?? userExtension ?? systemExtension;
if (extension) {
result.push(extension);
}
}
return result;
}, []);

Expand Down Expand Up @@ -1300,7 +1317,9 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension

if (isUninstalled) {
const canRemoveRunningExtension = runningExtension && this.extensionService.canRemoveExtension(runningExtension);
const isSameExtensionRunning = runningExtension && (!extension.server || extension.server === this.extensionManagementServerService.getExtensionManagementServer(toExtension(runningExtension)));
const isSameExtensionRunning = runningExtension
&& (!extension.server || extension.server === this.extensionManagementServerService.getExtensionManagementServer(toExtension(runningExtension)))
&& (!extension.resourceExtension || this.uriIdentityService.extUri.isEqual(extension.resourceExtension.location, runningExtension.extensionLocation));
if (!canRemoveRunningExtension && isSameExtensionRunning && !runningExtension.isUnderDevelopment) {
return { action: reloadAction, reason: nls.localize('postUninstallTooltip', "Please {0} to complete the uninstallation of this extension.", reloadActionLabel) };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class ExtensionService extends AbstractExtensionService implements IExten
} catch (error) {
this._logService.error(error);
}
return dedupExtensions(system, user, development, this._logService);
return dedupExtensions(system, user, [], development, this._logService);
}

protected async _resolveExtensionsDefault() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import * as semver from 'vs/base/common/semver/semver';

// TODO: @sandy081 merge this with deduping in extensionsScannerService.ts
export function dedupExtensions(system: IExtensionDescription[], user: IExtensionDescription[], development: IExtensionDescription[], logService: ILogService): IExtensionDescription[] {
export function dedupExtensions(system: IExtensionDescription[], user: IExtensionDescription[], workspace: IExtensionDescription[], development: IExtensionDescription[], logService: ILogService): IExtensionDescription[] {
const result = new ExtensionIdentifierMap<IExtensionDescription>();
system.forEach((systemExtension) => {
const extension = result.get(systemExtension.identifier);
Expand Down Expand Up @@ -37,6 +37,13 @@ export function dedupExtensions(system: IExtensionDescription[], user: IExtensio
}
result.set(userExtension.identifier, userExtension);
});
workspace.forEach(workspaceExtension => {
const extension = result.get(workspaceExtension.identifier);
if (extension) {
logService.warn(localize('overwritingWithWorkspaceExtension', "Overwriting {0} with Workspace Extension {1}.", extension.extensionLocation.fsPath, workspaceExtension.extensionLocation.fsPath));
}
result.set(workspaceExtension.identifier, workspaceExtension);
});
development.forEach(developedExtension => {
logService.info(localize('extensionUnderDevelopment', "Loading development extension at {0}", developedExtension.extensionLocation.fsPath));
const extension = result.get(developedExtension.identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ export class CachedExtensionScanner {
}

const system = scannedSystemExtensions.map(e => toExtensionDescriptionFromScannedExtension(e, false));
const userGlobal = scannedUserExtensions.map(e => toExtensionDescriptionFromScannedExtension(e, false));
const userWorkspace = workspaceExtensions.map(e => toExtensionDescription(e, false));
const user = scannedUserExtensions.map(e => toExtensionDescriptionFromScannedExtension(e, false));
const workspace = workspaceExtensions.map(e => toExtensionDescription(e, false));
const development = scannedDevelopedExtensions.map(e => toExtensionDescriptionFromScannedExtension(e, true));
const r = dedupExtensions(system, [...userGlobal, ...userWorkspace], development, this._logService);
const r = dedupExtensions(system, user, workspace, development, this._logService);

if (!hasErrors) {
const disposable = this._extensionsScannerService.onDidChangeCache(() => {
Expand Down

0 comments on commit ca280cc

Please sign in to comment.