Skip to content

Commit 405cf46

Browse files
author
Benjamin Pasero
committed
strict property init (microsoft#78168)
1 parent 198b3a2 commit 405cf46

6 files changed

Lines changed: 102 additions & 89 deletions

File tree

src/vs/workbench/browser/layout.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
2121
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
2222
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
2323
import { ITitleService } from 'vs/workbench/services/title/common/titleService';
24-
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
24+
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
2525
import { LifecyclePhase, StartupKind, ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
2626
import { MenuBarVisibility, getTitleBarStyle } from 'vs/platform/windows/common/windows';
2727
import { IHostService } from 'vs/workbench/services/host/browser/host';
@@ -48,7 +48,6 @@ enum Settings {
4848
PANEL_POSITION = 'workbench.panel.defaultLocation',
4949

5050
ZEN_MODE_RESTORE = 'zenMode.restore',
51-
5251
}
5352

5453
enum Storage {
@@ -105,38 +104,38 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
105104

106105
//#endregion
107106

108-
private _dimension: IDimension;
107+
private _dimension!: IDimension;
109108
get dimension(): IDimension { return this._dimension; }
110109

111110
private _container: HTMLElement = document.createElement('div');
112111
get container(): HTMLElement { return this._container; }
113112

114113
private parts: Map<string, Part> = new Map<string, Part>();
115114

116-
private workbenchGrid: SerializableGrid<ISerializableView>;
117-
118-
private disposed: boolean;
119-
120-
private titleBarPartView: ISerializableView;
121-
private activityBarPartView: ISerializableView;
122-
private sideBarPartView: ISerializableView;
123-
private panelPartView: ISerializableView;
124-
private editorPartView: ISerializableView;
125-
private statusBarPartView: ISerializableView;
126-
127-
private environmentService: IWorkbenchEnvironmentService;
128-
private configurationService: IConfigurationService;
129-
private lifecycleService: ILifecycleService;
130-
private storageService: IStorageService;
131-
private hostService: IHostService;
132-
private editorService: IEditorService;
133-
private editorGroupService: IEditorGroupsService;
134-
private panelService: IPanelService;
135-
private titleService: ITitleService;
136-
private viewletService: IViewletService;
137-
private contextService: IWorkspaceContextService;
138-
private backupFileService: IBackupFileService;
139-
private notificationService: INotificationService;
115+
private workbenchGrid!: SerializableGrid<ISerializableView>;
116+
117+
private disposed: boolean | undefined;
118+
119+
private titleBarPartView!: ISerializableView;
120+
private activityBarPartView!: ISerializableView;
121+
private sideBarPartView!: ISerializableView;
122+
private panelPartView!: ISerializableView;
123+
private editorPartView!: ISerializableView;
124+
private statusBarPartView!: ISerializableView;
125+
126+
private environmentService!: IWorkbenchEnvironmentService;
127+
private configurationService!: IConfigurationService;
128+
private lifecycleService!: ILifecycleService;
129+
private storageService!: IStorageService;
130+
private hostService!: IHostService;
131+
private editorService!: IEditorService;
132+
private editorGroupService!: IEditorGroupsService;
133+
private panelService!: IPanelService;
134+
private titleService!: ITitleService;
135+
private viewletService!: IViewletService;
136+
private contextService!: IWorkspaceContextService;
137+
private backupFileService!: IBackupFileService;
138+
private notificationService!: INotificationService;
140139

141140
protected readonly state = {
142141
fullscreen: false,
@@ -763,7 +762,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
763762
this.workbenchGrid.setViewVisible(this.statusBarPartView, !hidden);
764763
}
765764

766-
protected createWorkbenchLayout(instantiationService: IInstantiationService): void {
765+
protected createWorkbenchLayout(): void {
767766
const titleBar = this.getPart(Parts.TITLEBAR_PART);
768767
const editorPart = this.getPart(Parts.EDITOR_PART);
769768
const activityBar = this.getPart(Parts.ACTIVITYBAR_PART);

src/vs/workbench/browser/part.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export abstract class Part extends Component implements ISerializableView {
127127
private _onDidChange = this._register(new Emitter<IViewSize | undefined>());
128128
get onDidChange(): Event<IViewSize | undefined> { return this._onDidChange.event; }
129129

130-
element: HTMLElement;
130+
element!: HTMLElement;
131131

132132
abstract minimumWidth: number;
133133
abstract maximumWidth: number;

src/vs/workbench/browser/parts/compositeBarActions.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ export interface IActivityActionViewItemOptions extends IBaseActionViewItemOptio
126126
}
127127

128128
export class ActivityActionViewItem extends BaseActionViewItem {
129-
protected container: HTMLElement;
130-
protected label: HTMLElement;
131-
protected badge: HTMLElement;
132-
protected options: IActivityActionViewItemOptions;
129+
protected container!: HTMLElement;
130+
protected label!: HTMLElement;
131+
protected badge!: HTMLElement;
132+
protected options!: IActivityActionViewItemOptions;
133133

134134
private badgeContent: HTMLElement | undefined;
135135
private readonly badgeDisposable = this._register(new MutableDisposable());
@@ -219,7 +219,6 @@ export class ActivityActionViewItem extends BaseActionViewItem {
219219
dom.append(container, dom.$('.active-item-indicator'));
220220
}
221221

222-
223222
dom.hide(this.badge);
224223

225224
this.updateActivity();
@@ -303,14 +302,17 @@ export class ActivityActionViewItem extends BaseActionViewItem {
303302
} else {
304303
title = this.activity.name;
305304
}
305+
306306
this.updateTitle(title);
307307
}
308308

309309
protected updateLabel(): void {
310310
this.label.className = 'action-label';
311+
311312
if (this.activity.cssClass) {
312313
dom.addClass(this.label, this.activity.cssClass);
313314
}
315+
314316
if (!this.options.icon) {
315317
this.label.textContent = this.getAction().label;
316318
}

src/vs/workbench/browser/parts/editor/editorPart.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
3030
import { Parts, IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
3131
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
3232
import { MementoObject } from 'vs/workbench/common/memento';
33+
import { assertIsDefined } from 'vs/base/common/types';
3334

3435
interface IEditorPartUIState {
3536
serializedGrid: ISerializedGrid;
@@ -49,13 +50,13 @@ class GridWidgetView<T extends IView> implements IView {
4950
private _onDidChange = new Relay<{ width: number; height: number; } | undefined>();
5051
readonly onDidChange: Event<{ width: number; height: number; } | undefined> = this._onDidChange.event;
5152

52-
private _gridWidget: Grid<T>;
53+
private _gridWidget: Grid<T> | undefined;
5354

54-
get gridWidget(): Grid<T> {
55+
get gridWidget(): Grid<T> | undefined {
5556
return this._gridWidget;
5657
}
5758

58-
set gridWidget(grid: Grid<T>) {
59+
set gridWidget(grid: Grid<T> | undefined) {
5960
this.element.innerHTML = '';
6061

6162
if (grid) {
@@ -123,17 +124,18 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
123124

124125
private _partOptions: IEditorPartOptions;
125126

126-
private _activeGroup: IEditorGroupView;
127127
private groupViews: Map<GroupIdentifier, IEditorGroupView> = new Map<GroupIdentifier, IEditorGroupView>();
128128
private mostRecentActiveGroups: GroupIdentifier[] = [];
129129

130-
private container: HTMLElement;
131-
private centeredLayoutWidget: CenteredViewLayout;
132-
private gridWidget: SerializableGrid<IEditorGroupView>;
130+
private container: HTMLElement | undefined;
131+
132+
private centeredLayoutWidget!: CenteredViewLayout;
133+
134+
private gridWidget!: SerializableGrid<IEditorGroupView>;
133135
private gridWidgetView: GridWidgetView<IEditorGroupView>;
134136

135137
private _whenRestored: Promise<void>;
136-
private whenRestoredResolve: () => void;
138+
private whenRestoredResolve: (() => void) | undefined;
137139

138140
constructor(
139141
@IInstantiationService private readonly instantiationService: IInstantiationService,
@@ -204,9 +206,10 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
204206

205207
//#region IEditorGroupsService
206208

207-
private _contentDimension: Dimension;
209+
private _contentDimension!: Dimension;
208210
get contentDimension(): Dimension { return this._contentDimension; }
209211

212+
private _activeGroup!: IEditorGroupView;
210213
get activeGroup(): IEditorGroupView {
211214
return this._activeGroup;
212215
}
@@ -463,7 +466,11 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
463466
}
464467
}
465468

466-
private shouldRestoreFocus(target: Element): boolean {
469+
private shouldRestoreFocus(target: Element | undefined): boolean {
470+
if (!target) {
471+
return false;
472+
}
473+
467474
const activeElement = document.activeElement;
468475

469476
if (activeElement === document.body) {
@@ -796,7 +803,8 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
796803
}
797804

798805
updateStyles(): void {
799-
this.container.style.backgroundColor = this.getColor(editorBackground) || '';
806+
const container = assertIsDefined(this.container);
807+
container.style.backgroundColor = this.getColor(editorBackground) || '';
800808

801809
const separatorBorderStyle = { separatorBorder: this.gridSeparatorBorder, background: this.theme.getColor(EDITOR_PANE_BACKGROUND) || Color.transparent };
802810
this.gridWidget.style(separatorBorderStyle);
@@ -850,7 +858,11 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
850858
}
851859

852860
// Signal restored
853-
Promise.all(this.groups.map(group => group.whenRestored)).finally(() => this.whenRestoredResolve());
861+
Promise.all(this.groups.map(group => group.whenRestored)).finally(() => {
862+
if (this.whenRestoredResolve) {
863+
this.whenRestoredResolve();
864+
}
865+
});
854866

855867
// Update container
856868
this.updateContainer();
@@ -950,7 +962,8 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
950962
}
951963

952964
private updateContainer(): void {
953-
toggleClass(this.container, 'empty', this.isEmpty);
965+
const container = assertIsDefined(this.container);
966+
toggleClass(container, 'empty', this.isEmpty);
954967
}
955968

956969
private notifyGroupIndexChange(): void {

0 commit comments

Comments
 (0)