Skip to content

Commit 362ac63

Browse files
authored
1 parent 8e665b0 commit 362ac63

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { IDialogService, IPromptButton } from 'vs/platform/dialogs/common/dialog
5656
import { IUpdateService, StateType } from 'vs/platform/update/common/update';
5757
import { isEngineValid } from 'vs/platform/extensions/common/extensionValidator';
5858
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
59+
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
5960

6061
interface IExtensionStateProvider<T> {
6162
(extension: Extension): T;
@@ -879,6 +880,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
879880
@IUserDataSyncEnablementService private readonly userDataSyncEnablementService: IUserDataSyncEnablementService,
880881
@IUpdateService private readonly updateService: IUpdateService,
881882
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService,
883+
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
882884
) {
883885
super();
884886
const preferPreReleasesValue = configurationService.getValue('_extensions.preferPreReleases');
@@ -1004,21 +1006,31 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
10041006

10051007
private async onDidChangeRunningExtensions(added: ReadonlyArray<IExtensionDescription>, removed: ReadonlyArray<IExtensionDescription>): Promise<void> {
10061008
const changedExtensions: IExtension[] = [];
1007-
const extsNotInstalled: IExtensionInfo[] = [];
1009+
const extensionsToFetch: IExtensionDescription[] = [];
10081010
for (const desc of added) {
10091011
const extension = this.installed.find(e => areSameExtensions({ id: desc.identifier.value, uuid: desc.uuid }, e.identifier));
10101012
if (extension) {
10111013
changedExtensions.push(extension);
10121014
} else {
1013-
extsNotInstalled.push({ id: desc.identifier.value, uuid: desc.uuid });
1015+
extensionsToFetch.push(desc);
10141016
}
10151017
}
1016-
if (extsNotInstalled.length) {
1017-
const extensions = await this.getExtensions(extsNotInstalled, CancellationToken.None);
1018-
for (const extension of extensions) {
1019-
changedExtensions.push(extension);
1018+
const workspaceExtensions: IExtensionDescription[] = [];
1019+
for (const desc of removed) {
1020+
if (this.workspaceContextService.isInsideWorkspace(desc.extensionLocation)) {
1021+
workspaceExtensions.push(desc);
1022+
} else {
1023+
extensionsToFetch.push(desc);
10201024
}
10211025
}
1026+
if (extensionsToFetch.length) {
1027+
const extensions = await this.getExtensions(extensionsToFetch.map(e => ({ id: e.identifier.value, uuid: e.uuid })), CancellationToken.None);
1028+
changedExtensions.push(...extensions);
1029+
}
1030+
if (workspaceExtensions.length) {
1031+
const extensions = await this.getResourceExtensions(workspaceExtensions.map(e => e.extensionLocation), true)
1032+
changedExtensions.push(...extensions);
1033+
}
10221034
for (const changedExtension of changedExtensions) {
10231035
this._onChange.fire(changedExtension);
10241036
}
@@ -1237,13 +1249,6 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
12371249
const toRemove: string[] = [];
12381250

12391251
const extensionsToCheck = [...this.local];
1240-
1241-
const notExistingRunningExtensions = this.extensionService.extensions.filter(e => !this.local.some(local => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, local.identifier)));
1242-
if (notExistingRunningExtensions.length) {
1243-
const extensions = await this.getExtensions(notExistingRunningExtensions.map(e => ({ id: e.identifier.value })), CancellationToken.None);
1244-
extensionsToCheck.push(...extensions);
1245-
}
1246-
12471252
for (const extension of extensionsToCheck) {
12481253
const runtimeState = extension.runtimeState;
12491254
if (!runtimeState || runtimeState.action !== ExtensionRuntimeActionType.RestartExtensions) {
@@ -1267,6 +1272,18 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
12671272
toRemove.push(extension.identifier.id);
12681273
}
12691274
}
1275+
1276+
for (const extension of this.extensionService.extensions) {
1277+
if (extension.isUnderDevelopment) {
1278+
continue;
1279+
}
1280+
if (extensionsToCheck.some(e => areSameExtensions({ id: extension.identifier.value, uuid: extension.uuid }, e.identifier))) {
1281+
continue;
1282+
}
1283+
// Extension is running but doesn't exist locally. Remove it from running extensions.
1284+
toRemove.push(extension.identifier.value);
1285+
}
1286+
12701287
if (toAdd.length || toRemove.length) {
12711288
if (await this.extensionService.stopExtensionHosts(nls.localize('restart', "Enable or Disable extensions"))) {
12721289
await this.extensionService.startExtensionHosts({ toAdd, toRemove });

0 commit comments

Comments
 (0)