提交 3ee6fc3f 编写于 作者: S Sandeep Somavarapu

Fix showing newly enabled extension in enabled section

上级 3d8ad7d7
......@@ -332,8 +332,6 @@ export class ExtensionEditor extends EditorPane {
}
private async updateTemplate(input: ExtensionsInput, template: IExtensionEditorTemplate, preserveFocus: boolean): Promise<void> {
const runningExtensions = await this.extensionService.getExtensions();
this.activeElement = null;
this.editorLoadComplete = false;
const extension = input.extension;
......@@ -421,7 +419,7 @@ export class ExtensionEditor extends EditorPane {
this.instantiationService.createInstance(SetProductIconThemeAction, await this.workbenchThemeService.getProductIconThemes()),
this.instantiationService.createInstance(EnableDropDownAction),
this.instantiationService.createInstance(DisableDropDownAction, runningExtensions),
this.instantiationService.createInstance(DisableDropDownAction),
this.instantiationService.createInstance(RemoteInstallAction, false),
this.instantiationService.createInstance(LocalInstallAction),
combinedInstallAction,
......
......@@ -1104,7 +1104,7 @@ export class DisableForWorkspaceAction extends ExtensionAction {
static readonly ID = 'extensions.disableForWorkspace';
static readonly LABEL = localize('disableForWorkspaceAction', "Disable (Workspace)");
constructor(readonly runningExtensions: IExtensionDescription[],
constructor(private _runningExtensions: IExtensionDescription[],
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
......@@ -1113,9 +1113,14 @@ export class DisableForWorkspaceAction extends ExtensionAction {
this.update();
}
set runningExtensions(runningExtensions: IExtensionDescription[]) {
this._runningExtensions = runningExtensions;
this.update();
}
update(): void {
this.enabled = false;
if (this.extension && this.extension.local && this.runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier) && this.workspaceContextService.getWorkbenchState() !== WorkbenchState.EMPTY)) {
if (this.extension && this.extension.local && this._runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier) && this.workspaceContextService.getWorkbenchState() !== WorkbenchState.EMPTY)) {
this.enabled = this.extension.state === ExtensionState.Installed
&& (this.extension.enablementState === EnablementState.EnabledGlobally || this.extension.enablementState === EnablementState.EnabledWorkspace)
&& this.extensionEnablementService.canChangeWorkspaceEnablement(this.extension.local);
......@@ -1135,7 +1140,8 @@ export class DisableGloballyAction extends ExtensionAction {
static readonly ID = 'extensions.disableGlobally';
static readonly LABEL = localize('disableGloballyAction', "Disable");
constructor(readonly runningExtensions: IExtensionDescription[],
constructor(
private _runningExtensions: IExtensionDescription[],
@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService
) {
......@@ -1143,9 +1149,14 @@ export class DisableGloballyAction extends ExtensionAction {
this.update();
}
set runningExtensions(runningExtensions: IExtensionDescription[]) {
this._runningExtensions = runningExtensions;
this.update();
}
update(): void {
this.enabled = false;
if (this.extension && this.extension.local && this.runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))) {
if (this.extension && this.extension.local && this._runningExtensions.some(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, this.extension!.identifier))) {
this.enabled = this.extension.state === ExtensionState.Installed
&& (this.extension.enablementState === EnablementState.EnabledGlobally || this.extension.enablementState === EnablementState.EnabledWorkspace)
&& this.extensionEnablementService.canChangeEnablement(this.extension.local);
......@@ -1175,13 +1186,21 @@ export class EnableDropDownAction extends ActionWithDropDownAction {
export class DisableDropDownAction extends ActionWithDropDownAction {
constructor(
runningExtensions: IExtensionDescription[],
@IExtensionService extensionService: IExtensionService,
@IInstantiationService instantiationService: IInstantiationService
) {
super('extensions.disable', localize('disableAction', "Disable"), [
instantiationService.createInstance(DisableGloballyAction, runningExtensions),
instantiationService.createInstance(DisableForWorkspaceAction, runningExtensions)
]);
const actions = [
instantiationService.createInstance(DisableGloballyAction, []),
instantiationService.createInstance(DisableForWorkspaceAction, [])
];
super('extensions.disable', localize('disableAction', "Disable"), actions);
const updateRunningExtensions = async () => {
const runningExtensions = await extensionService.getExtensions();
actions.forEach(a => a.runningExtensions = runningExtensions);
};
updateRunningExtensions();
this._register(extensionService.onDidChangeExtensions(() => updateRunningExtensions()));
}
}
......
......@@ -322,22 +322,26 @@ export class ExtensionsListView extends ViewPane {
private async queryLocal(query: Query, options: IQueryOptions): Promise<IQueryResult> {
const local = await this.extensionsWorkbenchService.queryLocal();
let { extensions, canIncludeInstalledExtensions } = await this.filterLocal(local, query, options);
const runningExtensions = await this.extensionService.getExtensions();
let { extensions, canIncludeInstalledExtensions } = this.filterLocal(local, runningExtensions, query, options);
const disposables = new DisposableStore();
const onDidChangeModel = disposables.add(new Emitter<IPagedModel<IExtension>>());
if (canIncludeInstalledExtensions) {
let isDisposed: boolean = false;
disposables.add(toDisposable(() => isDisposed = true));
disposables.add(this.extensionsWorkbenchService.onChange(async e => {
if (e?.state === ExtensionState.Installed) {
const { extensions: newExtensions } = await this.filterLocal(this.extensionsWorkbenchService.local, query, options);
if (!isDisposed) {
const mergedExtensions = this.mergeAddedExtensions(extensions, newExtensions);
if (mergedExtensions) {
extensions = mergedExtensions;
onDidChangeModel.fire(new PagedModel(extensions));
}
disposables.add(Event.debounce(Event.any(
Event.filter(this.extensionsWorkbenchService.onChange, e => e?.state === ExtensionState.Installed),
this.extensionService.onDidChangeExtensions
), () => undefined)(async () => {
const local = this.extensionsWorkbenchService.local;
const runningExtensions = await this.extensionService.getExtensions();
const { extensions: newExtensions } = this.filterLocal(local, runningExtensions, query, options);
if (!isDisposed) {
const mergedExtensions = this.mergeAddedExtensions(extensions, newExtensions);
if (mergedExtensions) {
extensions = mergedExtensions;
onDidChangeModel.fire(new PagedModel(extensions));
}
}
}));
......@@ -350,7 +354,7 @@ export class ExtensionsListView extends ViewPane {
};
}
private async filterLocal(local: IExtension[], query: Query, options: IQueryOptions): Promise<{ extensions: IExtension[], canIncludeInstalledExtensions: boolean }> {
private filterLocal(local: IExtension[], runningExtensions: IExtensionDescription[], query: Query, options: IQueryOptions): { extensions: IExtension[], canIncludeInstalledExtensions: boolean } {
let value = query.value;
let extensions: IExtension[] = [];
let canIncludeInstalledExtensions = true;
......@@ -361,7 +365,7 @@ export class ExtensionsListView extends ViewPane {
}
else if (/@installed/i.test(value)) {
extensions = await this.filterInstalledExtensions(local, query, options);
extensions = this.filterInstalledExtensions(local, runningExtensions, query, options);
}
else if (/@outdated/i.test(value)) {
......@@ -369,11 +373,11 @@ export class ExtensionsListView extends ViewPane {
}
else if (/@disabled/i.test(value)) {
extensions = await this.filterDisabledExtensions(local, query, options);
extensions = this.filterDisabledExtensions(local, runningExtensions, query, options);
}
else if (/@enabled/i.test(value)) {
extensions = await this.filterEnabledExtensions(local, query, options);
extensions = this.filterEnabledExtensions(local, runningExtensions, query, options);
}
return { extensions, canIncludeInstalledExtensions };
......@@ -441,7 +445,7 @@ export class ExtensionsListView extends ViewPane {
return { value, categories };
}
private async filterInstalledExtensions(local: IExtension[], query: Query, options: IQueryOptions): Promise<IExtension[]> {
private filterInstalledExtensions(local: IExtension[], runningExtensions: IExtensionDescription[], query: Query, options: IQueryOptions): IExtension[] {
let { value, categories } = this.parseCategories(query.value);
value = value.replace(/@installed/g, '').replace(/@sort:(\w+)(-\w*)?/g, '').trim().toLowerCase();
......@@ -454,7 +458,6 @@ export class ExtensionsListView extends ViewPane {
if (options.sortBy !== undefined) {
result = this.sortExtensions(result, options);
} else {
const runningExtensions = await this.extensionService.getExtensions();
const runningExtensionsById = runningExtensions.reduce((result, e) => { result.set(ExtensionIdentifier.toKey(e.identifier.value), e); return result; }, new Map<string, IExtensionDescription>());
result = result.sort((e1, e2) => {
const running1 = runningExtensionsById.get(ExtensionIdentifier.toKey(e1.identifier.id));
......@@ -498,12 +501,11 @@ export class ExtensionsListView extends ViewPane {
return this.sortExtensions(result, options);
}
private async filterDisabledExtensions(local: IExtension[], query: Query, options: IQueryOptions): Promise<IExtension[]> {
private filterDisabledExtensions(local: IExtension[], runningExtensions: IExtensionDescription[], query: Query, options: IQueryOptions): IExtension[] {
let { value, categories } = this.parseCategories(query.value);
value = value.replace(/@disabled/g, '').replace(/@sort:(\w+)(-\w*)?/g, '').trim().toLowerCase();
const runningExtensions = await this.extensionService.getExtensions();
const result = local
.sort((e1, e2) => e1.displayName.localeCompare(e2.displayName))
.filter(e => runningExtensions.every(r => !areSameExtensions({ id: r.identifier.value, uuid: r.uuid }, e.identifier))
......@@ -513,13 +515,12 @@ export class ExtensionsListView extends ViewPane {
return this.sortExtensions(result, options);
}
private async filterEnabledExtensions(local: IExtension[], query: Query, options: IQueryOptions): Promise<IExtension[]> {
private filterEnabledExtensions(local: IExtension[], runningExtensions: IExtensionDescription[], query: Query, options: IQueryOptions): IExtension[] {
let { value, categories } = this.parseCategories(query.value);
value = value ? value.replace(/@enabled/g, '').replace(/@sort:(\w+)(-\w*)?/g, '').trim().toLowerCase() : '';
local = local.filter(e => !e.isBuiltin);
const runningExtensions = await this.extensionService.getExtensions();
const result = local
.sort((e1, e2) => e1.displayName.localeCompare(e2.displayName))
.filter(e => runningExtensions.some(r => areSameExtensions({ id: r.identifier.value, uuid: r.uuid }, e.identifier))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册