Skip to content

Commit

Permalink
debt - a bit more strict init
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 3, 2019
1 parent 02eb784 commit 309b492
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/editor/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface IEditorConfiguration {
export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
private editorControl: IEditor;
private _editorContainer: HTMLElement;
private hasPendingConfigurationChange: boolean;
private hasPendingConfigurationChange: boolean | undefined;
private lastAppliedEditorOptions?: IEditorOptions;
private editorMemento: IEditorMemento<IEditorViewState>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class NotificationsList extends Themable {
private listContainer: HTMLElement;
private list: WorkbenchList<INotificationViewItem>;
private viewModel: INotificationViewItem[];
private isVisible: boolean;
private isVisible: boolean | undefined;

constructor(
private container: HTMLElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class NotificationsToasts extends Themable {

private notificationsToastsContainer: HTMLElement;
private workbenchDimensions: Dimension;
private isNotificationsCenterVisible: boolean;
private isNotificationsCenterVisible: boolean | undefined;
private mapNotificationToToast: Map<INotificationViewItem, INotificationToast>;
private notificationsToastsVisibleContextKey: IContextKey<boolean>;

Expand Down
14 changes: 7 additions & 7 deletions src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class StatusbarViewModel extends Disposable {
private readonly _entries: IStatusbarViewModelEntry[] = [];
get entries(): IStatusbarViewModelEntry[] { return this._entries; }

private hidden: Set<string>;
private hidden!: Set<string>;

constructor(private storageService: IStorageService) {
super();
Expand Down Expand Up @@ -334,14 +334,14 @@ export class StatusbarPart extends Part implements IStatusbarService {

//#endregion

private styleElement: HTMLStyleElement;
private styleElement!: HTMLStyleElement;

private pendingEntries: IPendingStatusbarEntry[] = [];

private readonly viewModel: StatusbarViewModel;

private leftItemsContainer: HTMLElement;
private rightItemsContainer: HTMLElement;
private leftItemsContainer!: HTMLElement;
private rightItemsContainer!: HTMLElement;

constructor(
@IInstantiationService private readonly instantiationService: IInstantiationService,
Expand Down Expand Up @@ -627,10 +627,10 @@ export class StatusbarPart extends Part implements IStatusbarService {
}

class StatusbarEntryItem extends Disposable {
private entry: IStatusbarEntry;
private entry!: IStatusbarEntry;

private labelContainer: HTMLElement;
private label: OcticonLabel;
private labelContainer!: HTMLElement;
private label!: OcticonLabel;

private readonly foregroundListener = this._register(new MutableDisposable());
private readonly backgroundListener = this._register(new MutableDisposable());
Expand Down
14 changes: 7 additions & 7 deletions src/vs/workbench/common/editor/editorGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export class EditorGroup extends Disposable {

//#endregion

private _id: GroupIdentifier;
private _id!: GroupIdentifier;
get id(): GroupIdentifier { return this._id; }

private editors: EditorInput[] = [];
private mru: EditorInput[] = [];
Expand All @@ -97,8 +98,8 @@ export class EditorGroup extends Disposable {
private preview: EditorInput | null = null; // editor in preview state
private active: EditorInput | null = null; // editor in active state

private editorOpenPositioning: 'left' | 'right' | 'first' | 'last';
private focusRecentEditorAfterClose: boolean;
private editorOpenPositioning: ('left' | 'right' | 'first' | 'last') | undefined;
private focusRecentEditorAfterClose: boolean | undefined;

constructor(
labelOrSerializedGroup: ISerializedEditorGroup,
Expand Down Expand Up @@ -126,10 +127,6 @@ export class EditorGroup extends Disposable {
this.focusRecentEditorAfterClose = this.configurationService.getValue('workbench.editor.focusRecentEditorAfterClose');
}

get id(): GroupIdentifier {
return this._id;
}

get count(): number {
return this.editors.length;
}
Expand Down Expand Up @@ -689,8 +686,11 @@ export class EditorGroup extends Disposable {

return null;
}));

this.mru = data.mru.map(i => this.editors[i]);

this.active = this.mru[0];

if (typeof data.preview === 'number') {
this.preview = this.editors[data.preview];
}
Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/common/editor/textDiffEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { DiffEditorModel } from 'vs/workbench/common/editor/diffEditorModel';
*/
export class TextDiffEditorModel extends DiffEditorModel {

protected readonly _originalModel: BaseTextEditorModel;
protected readonly _modifiedModel: BaseTextEditorModel;
protected readonly _originalModel: BaseTextEditorModel | null = null;
protected readonly _modifiedModel: BaseTextEditorModel | null = null;

private _textDiffEditorModel: IDiffEditorModel | null = null;

Expand All @@ -25,11 +25,11 @@ export class TextDiffEditorModel extends DiffEditorModel {
this.updateTextDiffEditorModel();
}

get originalModel(): BaseTextEditorModel {
get originalModel(): BaseTextEditorModel | null {
return this._originalModel;
}

get modifiedModel(): BaseTextEditorModel {
get modifiedModel(): BaseTextEditorModel | null {
return this._modifiedModel;
}

Expand All @@ -42,7 +42,7 @@ export class TextDiffEditorModel extends DiffEditorModel {
}

private updateTextDiffEditorModel(): void {
if (this.originalModel.isResolved() && this.modifiedModel.isResolved()) {
if (this.originalModel && this.originalModel.isResolved() && this.modifiedModel && this.modifiedModel.isResolved()) {

// Create new
if (!this._textDiffEditorModel) {
Expand All @@ -69,7 +69,7 @@ export class TextDiffEditorModel extends DiffEditorModel {
}

isReadonly(): boolean {
return this.modifiedModel.isReadonly();
return !!this.modifiedModel && this.modifiedModel.isReadonly();
}

dispose(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CommandsHistory extends Disposable {
private static readonly PREF_KEY_CACHE = 'commandPalette.mru.cache';
private static readonly PREF_KEY_COUNTER = 'commandPalette.mru.counter';

private commandHistoryLength: number;
private commandHistoryLength!: number;

constructor(
@IStorageService private readonly storageService: IStorageService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class OpenAnythingHandler extends QuickOpenHandler {
private openSymbolHandler: OpenSymbolHandler;
private openFileHandler: OpenFileHandler;
private searchDelayer: ThrottledDelayer<QuickOpenModel | null>;
private isClosed: boolean;
private isClosed: boolean | undefined;
private scorerCache: ScorerCache;
private includeSymbols: boolean;
private includeSymbols: boolean | undefined;

constructor(
@INotificationService private readonly notificationService: INotificationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class HideWelcomeOverlayAction extends Action {
class WelcomeOverlay extends Disposable {

private _overlayVisible: IContextKey<boolean>;
private _overlay: HTMLElement;
private _overlay!: HTMLElement;

constructor(
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
Expand Down
36 changes: 17 additions & 19 deletions src/vs/workbench/services/history/browser/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ export class HistoryService extends Disposable implements IHistoryService {

private lastEditLocation: IStackEntry | undefined;

private history: Array<IEditorInput | IResourceInput>;
private history: Array<IEditorInput | IResourceInput> | undefined;
private recentlyClosedFiles: IRecentlyClosedFile[];
private loaded: boolean;
private resourceFilter: ResourceGlobMatcher;

private fileInputFactory: IFileInputFactory;
Expand Down Expand Up @@ -155,7 +154,6 @@ export class HistoryService extends Disposable implements IHistoryService {
this.lastIndex = -1;
this.stack = [];
this.recentlyClosedFiles = [];
this.loaded = false;
this.resourceFilter = this._register(instantiationService.createInstance(
ResourceGlobMatcher,
(root?: URI) => this.getExcludes(root),
Expand Down Expand Up @@ -489,17 +487,17 @@ export class HistoryService extends Disposable implements IHistoryService {
return;
}

this.ensureHistoryLoaded();
const history = this.ensureHistoryLoaded();

const historyInput = this.preferResourceInput(input);

// Remove any existing entry and add to the beginning
this.removeFromHistory(input);
this.history.unshift(historyInput);
history.unshift(historyInput);

// Respect max entries setting
if (this.history.length > HistoryService.MAX_HISTORY_ITEMS) {
this.clearOnEditorDispose(this.history.pop()!, this.editorHistoryListeners);
if (history.length > HistoryService.MAX_HISTORY_ITEMS) {
this.clearOnEditorDispose(history.pop()!, this.editorHistoryListeners);
}

// Remove this from the history unless the history input is a resource
Expand Down Expand Up @@ -555,9 +553,9 @@ export class HistoryService extends Disposable implements IHistoryService {
}

private removeExcludedFromHistory(): void {
this.ensureHistoryLoaded();
const history = this.ensureHistoryLoaded();

this.history = this.history.filter(e => {
this.history = history.filter(e => {
const include = this.include(e);

// Cleanup any listeners associated with the input when removing from history
Expand All @@ -570,9 +568,9 @@ export class HistoryService extends Disposable implements IHistoryService {
}

private removeFromHistory(arg1: IEditorInput | IResourceInput | FileChangesEvent): void {
this.ensureHistoryLoaded();
const history = this.ensureHistoryLoaded();

this.history = this.history.filter(e => {
this.history = history.filter(e => {
const matches = this.matches(arg1, e);

// Cleanup any listeners associated with the input when removing from history
Expand Down Expand Up @@ -849,17 +847,17 @@ export class HistoryService extends Disposable implements IHistoryService {
}

getHistory(): Array<IEditorInput | IResourceInput> {
this.ensureHistoryLoaded();
const history = this.ensureHistoryLoaded();

return this.history.slice(0);
return history.slice(0);
}

private ensureHistoryLoaded(): void {
if (!this.loaded) {
this.loadHistory();
private ensureHistoryLoaded(): Array<IEditorInput | IResourceInput> {
if (!this.history) {
this.history = this.loadHistory();
}

this.loaded = true;
return this.history;
}

private saveState(): void {
Expand Down Expand Up @@ -893,7 +891,7 @@ export class HistoryService extends Disposable implements IHistoryService {
this.storageService.store(HistoryService.STORAGE_KEY, JSON.stringify(entries), StorageScope.WORKSPACE);
}

private loadHistory(): void {
private loadHistory(): Array<IEditorInput | IResourceInput> {
let entries: ISerializedEditorHistoryEntry[] = [];

const entriesRaw = this.storageService.get(HistoryService.STORAGE_KEY, StorageScope.WORKSPACE);
Expand All @@ -903,7 +901,7 @@ export class HistoryService extends Disposable implements IHistoryService {

const registry = Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories);

this.history = coalesce(entries.map(entry => {
return coalesce(entries.map(entry => {
try {
return this.safeLoadHistoryEntry(registry, entry);
} catch (error) {
Expand Down

1 comment on commit 309b492

@joaomoreno
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a pro.

Please sign in to comment.