Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services - prevent eager layout service use #160103

Merged
merged 1 commit into from Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/vs/platform/quickinput/browser/quickInput.ts
Expand Up @@ -6,6 +6,7 @@
import { IListRenderer, IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
import { List } from 'vs/base/browser/ui/list/listWidget';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Emitter } from 'vs/base/common/event';
import { IQuickInputOptions, IQuickInputStyles, QuickInputController } from 'vs/base/parts/quickinput/browser/quickInput';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
Expand All @@ -27,8 +28,11 @@ export class QuickInputService extends Themable implements IQuickInputService {

get backButton(): IQuickInputButton { return this.controller.backButton; }

get onShow() { return this.controller.onShow; }
get onHide() { return this.controller.onHide; }
private readonly _onShow = this._register(new Emitter<void>());
readonly onShow = this._onShow.event;

private readonly _onHide = this._register(new Emitter<void>());
readonly onHide = this._onHide.event;

private _controller: QuickInputController | undefined;
private get controller(): QuickInputController {
Expand All @@ -39,6 +43,8 @@ export class QuickInputService extends Themable implements IQuickInputService {
return this._controller;
}

private get hasController() { return !!this._controller; }

private _quickAccess: IQuickAccessController | undefined;
get quickAccess(): IQuickAccessController {
if (!this._quickAccess) {
Expand Down Expand Up @@ -90,8 +96,14 @@ export class QuickInputService extends Themable implements IQuickInputService {
this._register(host.onDidLayout(dimension => controller.layout(dimension, host.offset.quickPickTop)));

// Context keys
this._register(controller.onShow(() => this.resetContextKeys()));
this._register(controller.onHide(() => this.resetContextKeys()));
this._register(controller.onShow(() => {
this.resetContextKeys();
this._onShow.fire();
}));
this._register(controller.onHide(() => {
this.resetContextKeys();
this._onHide.fire();
}));

return controller;
}
Expand Down Expand Up @@ -165,7 +177,9 @@ export class QuickInputService extends Themable implements IQuickInputService {
}

protected override updateStyles() {
this.controller.applyStyles(this.computeStyles());
if (this.hasController) {
this.controller.applyStyles(this.computeStyles());
}
}

private computeStyles(): IQuickInputStyles {
Expand Down
73 changes: 41 additions & 32 deletions src/vs/workbench/browser/layoutState.ts
Expand Up @@ -4,30 +4,35 @@
*--------------------------------------------------------------------------------------------*/

import { getClientArea } from 'vs/base/browser/dom';
import { Emitter, Event } from 'vs/base/common/event';
import { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { PanelAlignment, Position, positionFromString, positionToString } from 'vs/workbench/services/layout/browser/layoutService';

interface IWorkbenchLayoutStateKey {
name: string;
runtime: boolean;
defaultValue: any;
scope: StorageScope;
target: StorageTarget;
zenModeIgnore?: boolean;
readonly name: string;
readonly runtime: boolean;
readonly defaultValue: unknown;
readonly scope: StorageScope;
readonly target: StorageTarget;
readonly zenModeIgnore?: boolean;
}

type StorageKeyType = string | boolean | number | object;

abstract class WorkbenchLayoutStateKey<T extends StorageKeyType> implements IWorkbenchLayoutStateKey {

abstract readonly runtime: boolean;

constructor(readonly name: string, readonly scope: StorageScope, readonly target: StorageTarget, public defaultValue: T) { }
}

class RuntimeStateKey<T extends StorageKeyType> extends WorkbenchLayoutStateKey<T> {

readonly runtime = true;

constructor(name: string, scope: StorageScope, target: StorageTarget, defaultValue: T, readonly zenModeIgnore?: boolean) {
super(name, scope, target, defaultValue);
}
Expand All @@ -38,6 +43,7 @@ class InitializationStateKey<T extends StorageKeyType> extends WorkbenchLayoutSt
}

export const LayoutStateKeys = {

// Editor
EDITOR_CENTERED: new RuntimeStateKey<boolean>('editor.centered', StorageScope.WORKSPACE, StorageTarget.USER, false),

Expand Down Expand Up @@ -75,27 +81,46 @@ export const LayoutStateKeys = {
EDITOR_HIDDEN: new RuntimeStateKey<boolean>('editor.hidden', StorageScope.WORKSPACE, StorageTarget.USER, false),
PANEL_HIDDEN: new RuntimeStateKey<boolean>('panel.hidden', StorageScope.WORKSPACE, StorageTarget.USER, true),
AUXILIARYBAR_HIDDEN: new RuntimeStateKey<boolean>('auxiliaryBar.hidden', StorageScope.WORKSPACE, StorageTarget.USER, true),
STATUSBAR_HIDDEN: new RuntimeStateKey<boolean>('statusBar.hidden', StorageScope.WORKSPACE, StorageTarget.USER, false, true),
} as const;
STATUSBAR_HIDDEN: new RuntimeStateKey<boolean>('statusBar.hidden', StorageScope.WORKSPACE, StorageTarget.USER, false, true)

} as const;

interface ILayoutStateChangeEvent<T extends StorageKeyType> {
key: RuntimeStateKey<T>;
value: T;
readonly key: RuntimeStateKey<T>;
readonly value: T;
}

export enum WorkbenchLayoutSettings {
PANEL_POSITION = 'workbench.panel.defaultLocation',
PANEL_OPENS_MAXIMIZED = 'workbench.panel.opensMaximized',
ZEN_MODE_CONFIG = 'zenMode',
ZEN_MODE_SILENT_NOTIFICATIONS = 'zenMode.silentNotifications',
EDITOR_CENTERED_LAYOUT_AUTO_RESIZE = 'workbench.editor.centeredLayoutAutoResize',
}

enum LegacyWorkbenchLayoutSettings {
ACTIVITYBAR_VISIBLE = 'workbench.activityBar.visible', // Deprecated to UI State
STATUSBAR_VISIBLE = 'workbench.statusBar.visible', // Deprecated to UI State
SIDEBAR_POSITION = 'workbench.sideBar.location', // Deprecated to UI State
}

export class LayoutStateModel extends Disposable {

static readonly STORAGE_PREFIX = 'workbench.';
private stateCache = new Map<string, any>();

private readonly _onDidChangeState: Emitter<ILayoutStateChangeEvent<StorageKeyType>> = this._register(new Emitter<ILayoutStateChangeEvent<StorageKeyType>>());
readonly onDidChangeState: Event<ILayoutStateChangeEvent<StorageKeyType>> = this._onDidChangeState.event;
private readonly _onDidChangeState = this._register(new Emitter<ILayoutStateChangeEvent<StorageKeyType>>());
readonly onDidChangeState = this._onDidChangeState.event;

private readonly stateCache = new Map<string, unknown>();

constructor(
private readonly storageService: IStorageService,
private readonly configurationService: IConfigurationService,
private readonly contextService: IWorkspaceContextService,
private readonly container: HTMLElement) {
private readonly container: HTMLElement
) {
super();

this._register(this.configurationService.onDidChangeConfiguration(configurationChange => this.updateStateFromLegacySettings(configurationChange)));
}

Expand Down Expand Up @@ -157,7 +182,6 @@ export class LayoutStateModel extends Disposable {
LayoutStateKeys.PANEL_SIZE.defaultValue = (this.stateCache.get(LayoutStateKeys.PANEL_POSITION.name) ?? LayoutStateKeys.PANEL_POSITION.defaultValue) === 'bottom' ? workbenchDimensions.height / 3 : workbenchDimensions.width / 4;
LayoutStateKeys.SIDEBAR_HIDDEN.defaultValue = this.contextService.getWorkbenchState() === WorkbenchState.EMPTY;


// Apply all defaults
for (key in LayoutStateKeys) {
const stateKey = LayoutStateKeys[key];
Expand Down Expand Up @@ -193,9 +217,8 @@ export class LayoutStateModel extends Disposable {
const stateKey = LayoutStateKeys[key] as WorkbenchLayoutStateKey<StorageKeyType>;
if ((workspace && stateKey.scope === StorageScope.WORKSPACE) ||
(global && stateKey.scope === StorageScope.PROFILE)) {
// Don't write out specific keys while in zen mode
if (isZenMode && stateKey instanceof RuntimeStateKey && stateKey.zenModeIgnore) {
continue;
continue; // Don't write out specific keys while in zen mode
}

this.saveKeyToStorage(stateKey);
Expand Down Expand Up @@ -270,17 +293,3 @@ export class LayoutStateModel extends Disposable {
return value as T | undefined;
}
}

export enum WorkbenchLayoutSettings {
PANEL_POSITION = 'workbench.panel.defaultLocation',
PANEL_OPENS_MAXIMIZED = 'workbench.panel.opensMaximized',
ZEN_MODE_CONFIG = 'zenMode',
ZEN_MODE_SILENT_NOTIFICATIONS = 'zenMode.silentNotifications',
EDITOR_CENTERED_LAYOUT_AUTO_RESIZE = 'workbench.editor.centeredLayoutAutoResize',
}

enum LegacyWorkbenchLayoutSettings {
ACTIVITYBAR_VISIBLE = 'workbench.activityBar.visible', // Deprecated to UI State
STATUSBAR_VISIBLE = 'workbench.statusBar.visible', // Deprecated to UI State
SIDEBAR_POSITION = 'workbench.sideBar.location', // Deprecated to UI State
}
Expand Up @@ -42,7 +42,7 @@ export class QuickInputService extends BaseQuickInputService {
protected override createController(): QuickInputController {
return super.createController(this.layoutService, {
ignoreFocusOut: () => !this.configurationService.getValue('workbench.quickOpen.closeOnFocusLost'),
backKeybindingLabel: () => this.keybindingService.lookupKeybinding('workbench.action.quickInputBack')?.getLabel() || undefined,
backKeybindingLabel: () => this.keybindingService.lookupKeybinding('workbench.action.quickInputBack')?.getLabel() || undefined
});
}
}
Expand Down
Expand Up @@ -193,8 +193,23 @@ export class TextModelResolverService extends Disposable implements ITextModelSe

declare readonly _serviceBrand: undefined;

private readonly resourceModelCollection: ResourceModelCollection & ReferenceCollection<Promise<IResolvedTextEditorModel>> /* TS Fail */ = this.instantiationService.createInstance(ResourceModelCollection);
private readonly asyncModelCollection = new AsyncReferenceCollection(this.resourceModelCollection);
private _resourceModelCollection: ResourceModelCollection & ReferenceCollection<Promise<IResolvedTextEditorModel>> /* TS Fail */ | undefined = undefined;
private get resourceModelCollection() {
if (!this._resourceModelCollection) {
this._resourceModelCollection = this.instantiationService.createInstance(ResourceModelCollection);
}

return this._resourceModelCollection;
}

private _asyncModelCollection: AsyncReferenceCollection<IResolvedTextEditorModel> | undefined = undefined;
private get asyncModelCollection() {
if (!this._asyncModelCollection) {
this._asyncModelCollection = new AsyncReferenceCollection(this.resourceModelCollection);
}

return this._asyncModelCollection;
}

constructor(
@IInstantiationService private readonly instantiationService: IInstantiationService,
Expand Down