From e428bed67d40bef5bb044509f654aa536360a0ab Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 5 Aug 2019 10:42:19 +0200 Subject: [PATCH] strict init work, #78168 --- .../contrib/inPlaceReplace/inPlaceReplace.ts | 4 +-- .../referenceSearch/referencesController.ts | 14 ++++---- .../referenceSearch/referencesWidget.ts | 25 +++++++------- .../editor/contrib/rename/renameInputField.ts | 34 +++++++++---------- .../contrib/snippet/snippetController2.ts | 2 +- .../editor/contrib/snippet/snippetSession.ts | 24 ++++++------- src/vs/editor/contrib/suggest/suggest.ts | 2 +- .../editor/contrib/suggest/suggestMemory.ts | 6 ++-- src/vs/editor/contrib/suggest/suggestModel.ts | 7 ++-- .../editor/contrib/suggest/suggestWidget.ts | 22 ++++++------ .../browser/menuEntryActionViewItem.ts | 4 +-- src/vs/platform/actions/common/menuService.ts | 4 +-- .../workbench/api/browser/mainThreadEditor.ts | 7 ++-- 13 files changed, 78 insertions(+), 77 deletions(-) diff --git a/src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts b/src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts index 195d83b849c3c..fce6fc23383fe 100644 --- a/src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts +++ b/src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts @@ -37,8 +37,8 @@ class InPlaceReplaceController implements IEditorContribution { private readonly editor: ICodeEditor; private readonly editorWorkerService: IEditorWorkerService; private decorationIds: string[] = []; - private currentRequest: CancelablePromise; - private decorationRemover: CancelablePromise; + private currentRequest?: CancelablePromise; + private decorationRemover?: CancelablePromise; constructor( editor: ICodeEditor, diff --git a/src/vs/editor/contrib/referenceSearch/referencesController.ts b/src/vs/editor/contrib/referenceSearch/referencesController.ts index 0f756a445509f..6f0dcdff9de8f 100644 --- a/src/vs/editor/contrib/referenceSearch/referencesController.ts +++ b/src/vs/editor/contrib/referenceSearch/referencesController.ts @@ -34,8 +34,8 @@ export abstract class ReferencesController implements editorCommon.IEditorContri private readonly _disposables = new DisposableStore(); private readonly _editor: ICodeEditor; - private _widget: ReferenceWidget | null; - private _model: ReferencesModel | null; + private _widget?: ReferenceWidget; + private _model?: ReferencesModel; private _requestIdPool = 0; private _ignoreModelChangeEvent = false; @@ -68,11 +68,11 @@ export abstract class ReferencesController implements editorCommon.IEditorContri dispose(this._disposables); if (this._widget) { dispose(this._widget); - this._widget = null; + this._widget = undefined; } if (this._model) { dispose(this._model); - this._model = null; + this._model = undefined; } } @@ -107,7 +107,7 @@ export abstract class ReferencesController implements editorCommon.IEditorContri modelPromise.cancel(); if (this._widget) { this._storageService.store(storageKey, JSON.stringify(this._widget.layoutData), StorageScope.GLOBAL); - this._widget = null; + this._widget = undefined; } this.closeWidget(); })); @@ -202,13 +202,13 @@ export abstract class ReferencesController implements editorCommon.IEditorContri public closeWidget(): void { if (this._widget) { dispose(this._widget); - this._widget = null; + this._widget = undefined; } this._referenceSearchVisible.reset(); this._disposables.clear(); if (this._model) { dispose(this._model); - this._model = null; + this._model = undefined; } this._editor.focus(); this._requestIdPool += 1; // Cancel pending requests diff --git a/src/vs/editor/contrib/referenceSearch/referencesWidget.ts b/src/vs/editor/contrib/referenceSearch/referencesWidget.ts index 20fc37f552e2d..78b59c046c2ea 100644 --- a/src/vs/editor/contrib/referenceSearch/referencesWidget.ts +++ b/src/vs/editor/contrib/referenceSearch/referencesWidget.ts @@ -158,8 +158,8 @@ class DecorationsManager implements IDisposable { } export class LayoutData { - ratio: number; - heightInLines: number; + ratio: number = 0.7; + heightInLines: number = 18; static fromJSON(raw: string): LayoutData { let ratio: number | undefined; @@ -191,22 +191,21 @@ export const ctxReferenceWidgetSearchTreeFocused = new RawContextKey('r */ export class ReferenceWidget extends PeekViewWidget { - private _model: ReferencesModel | undefined; - private _decorationsManager: DecorationsManager; + private _model?: ReferencesModel; + private _decorationsManager?: DecorationsManager; private readonly _disposeOnNewModel = new DisposableStore(); private readonly _callOnDispose = new DisposableStore(); private _onDidSelectReference = new Emitter(); - private _tree: WorkbenchAsyncDataTree; - private _treeContainer: HTMLElement; - // private _sash: VSash; - private _splitView: SplitView; - private _preview: ICodeEditor; - private _previewModelReference: IReference; - private _previewNotAvailableMessage: TextModel; - private _previewContainer: HTMLElement; - private _messageContainer: HTMLElement; + private _tree!: WorkbenchAsyncDataTree; + private _treeContainer!: HTMLElement; + private _splitView!: SplitView; + private _preview!: ICodeEditor; + private _previewModelReference!: IReference; + private _previewNotAvailableMessage!: TextModel; + private _previewContainer!: HTMLElement; + private _messageContainer!: HTMLElement; private _dim: dom.Dimension = { height: 0, width: 0 }; constructor( diff --git a/src/vs/editor/contrib/rename/renameInputField.ts b/src/vs/editor/contrib/rename/renameInputField.ts index 85e4c956911a0..c285d9707cd3a 100644 --- a/src/vs/editor/contrib/rename/renameInputField.ts +++ b/src/vs/editor/contrib/rename/renameInputField.ts @@ -19,10 +19,10 @@ export const CONTEXT_RENAME_INPUT_VISIBLE = new RawContextKey('renameIn export class RenameInputField implements IContentWidget, IDisposable { private _editor: ICodeEditor; - private _position: Position; - private _domNode: HTMLElement; - private _inputField: HTMLInputElement; - private _visible: boolean; + private _position?: Position; + private _domNode?: HTMLElement; + private _inputField?: HTMLInputElement; + private _visible?: boolean; private readonly _visibleContextKey: IContextKey; private readonly _disposables = new DisposableStore(); @@ -95,7 +95,7 @@ export class RenameInputField implements IContentWidget, IDisposable { this._inputField.style.borderStyle = border ? 'solid' : 'none'; this._inputField.style.borderColor = border ? border.toString() : 'none'; - this._domNode.style.boxShadow = widgetShadowColor ? ` 0 2px 8px ${widgetShadowColor}` : null; + this._domNode!.style.boxShadow = widgetShadowColor ? ` 0 2px 8px ${widgetShadowColor}` : null; } private updateFont(): void { @@ -111,7 +111,7 @@ export class RenameInputField implements IContentWidget, IDisposable { public getPosition(): IContentWidgetPosition | null { return this._visible - ? { position: this._position, preference: [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE] } + ? { position: this._position!, preference: [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE] } : null; } @@ -133,10 +133,10 @@ export class RenameInputField implements IContentWidget, IDisposable { public getInput(where: IRange, value: string, selectionStart: number, selectionEnd: number): Promise { this._position = new Position(where.startLineNumber, where.startColumn); - this._inputField.value = value; - this._inputField.setAttribute('selectionStart', selectionStart.toString()); - this._inputField.setAttribute('selectionEnd', selectionEnd.toString()); - this._inputField.size = Math.max((where.endColumn - where.startColumn) * 1.1, 20); + this._inputField!.value = value; + this._inputField!.setAttribute('selectionStart', selectionStart.toString()); + this._inputField!.setAttribute('selectionEnd', selectionEnd.toString()); + this._inputField!.size = Math.max((where.endColumn - where.startColumn) * 1.1, 20); const disposeOnDone = new DisposableStore(); const always = () => { @@ -154,7 +154,7 @@ export class RenameInputField implements IContentWidget, IDisposable { }; this._currentAcceptInput = () => { - if (this._inputField.value.trim().length === 0 || this._inputField.value === value) { + if (this._inputField!.value.trim().length === 0 || this._inputField!.value === value) { // empty or whitespace only or not changed this.cancelInput(true); return; @@ -162,7 +162,7 @@ export class RenameInputField implements IContentWidget, IDisposable { this._currentAcceptInput = null; this._currentCancelInput = null; - resolve(this._inputField.value); + resolve(this._inputField!.value); }; let onCursorChanged = () => { @@ -187,16 +187,16 @@ export class RenameInputField implements IContentWidget, IDisposable { } private _show(): void { - this._editor.revealLineInCenterIfOutsideViewport(this._position.lineNumber, ScrollType.Smooth); + this._editor.revealLineInCenterIfOutsideViewport(this._position!.lineNumber, ScrollType.Smooth); this._visible = true; this._visibleContextKey.set(true); this._editor.layoutContentWidget(this); setTimeout(() => { - this._inputField.focus(); - this._inputField.setSelectionRange( - parseInt(this._inputField.getAttribute('selectionStart')!), - parseInt(this._inputField.getAttribute('selectionEnd')!)); + this._inputField!.focus(); + this._inputField!.setSelectionRange( + parseInt(this._inputField!.getAttribute('selectionStart')!), + parseInt(this._inputField!.getAttribute('selectionEnd')!)); }, 100); } diff --git a/src/vs/editor/contrib/snippet/snippetController2.ts b/src/vs/editor/contrib/snippet/snippetController2.ts index c24659b44d282..cec786f46fea4 100644 --- a/src/vs/editor/contrib/snippet/snippetController2.ts +++ b/src/vs/editor/contrib/snippet/snippetController2.ts @@ -54,7 +54,7 @@ export class SnippetController2 implements IEditorContribution { private _session?: SnippetSession; private _snippetListener = new DisposableStore(); - private _modelVersionId: number; + private _modelVersionId: number = -1; private _currentChoice?: Choice; constructor( diff --git a/src/vs/editor/contrib/snippet/snippetSession.ts b/src/vs/editor/contrib/snippet/snippetSession.ts index 6140e44858a62..689b5567ed17b 100644 --- a/src/vs/editor/contrib/snippet/snippetSession.ts +++ b/src/vs/editor/contrib/snippet/snippetSession.ts @@ -41,7 +41,7 @@ export class OneSnippet { private readonly _snippet: TextmateSnippet; private readonly _offset: number; - private _placeholderDecorations: Map; + private _placeholderDecorations?: Map; private _placeholderGroups: Placeholder[][]; _placeholderGroupsIdx: number; _nestingLevel: number = 1; @@ -92,7 +92,7 @@ export class OneSnippet { ); const options = placeholder.isFinalTabstop ? OneSnippet._decor.inactiveFinal : OneSnippet._decor.inactive; const handle = accessor.addDecoration(range, options); - this._placeholderDecorations.set(placeholder, handle); + this._placeholderDecorations!.set(placeholder, handle); } }); } @@ -111,7 +111,7 @@ export class OneSnippet { for (const placeholder of this._placeholderGroups[this._placeholderGroupsIdx]) { // Check if the placeholder has a transformation if (placeholder.transform) { - const id = this._placeholderDecorations.get(placeholder)!; + const id = this._placeholderDecorations!.get(placeholder)!; const range = this._editor.getModel().getDecorationRange(id)!; const currentValue = this._editor.getModel().getValueInRange(range); @@ -148,7 +148,7 @@ export class OneSnippet { // Special case #2: placeholders enclosing active placeholders const selections: Selection[] = []; for (const placeholder of this._placeholderGroups[this._placeholderGroupsIdx]) { - const id = this._placeholderDecorations.get(placeholder)!; + const id = this._placeholderDecorations!.get(placeholder)!; const range = this._editor.getModel().getDecorationRange(id)!; selections.push(new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn)); @@ -161,7 +161,7 @@ export class OneSnippet { activePlaceholders.add(placeholder); for (const enclosingPlaceholder of this._snippet.enclosingPlaceholders(placeholder)) { - const id = this._placeholderDecorations.get(enclosingPlaceholder)!; + const id = this._placeholderDecorations!.get(enclosingPlaceholder)!; accessor.changeDecorationOptions(id, enclosingPlaceholder.isFinalTabstop ? OneSnippet._decor.activeFinal : OneSnippet._decor.active); activePlaceholders.add(enclosingPlaceholder); } @@ -169,7 +169,7 @@ export class OneSnippet { // change stickness to never grow when typing at its edges // so that in-active tabstops never grow - this._placeholderDecorations.forEach((id, placeholder) => { + this._placeholderDecorations!.forEach((id, placeholder) => { if (!activePlaceholders.has(placeholder)) { accessor.changeDecorationOptions(id, placeholder.isFinalTabstop ? OneSnippet._decor.inactiveFinal : OneSnippet._decor.inactive); } @@ -188,7 +188,7 @@ export class OneSnippet { let marker: Marker | undefined = placeholder; while (marker) { if (marker instanceof Placeholder) { - const id = this._placeholderDecorations.get(marker)!; + const id = this._placeholderDecorations!.get(marker)!; const range = this._editor.getModel().getDecorationRange(id)!; if (range.isEmpty() && marker.toString().length > 0) { return true; @@ -227,7 +227,7 @@ export class OneSnippet { result.set(placeholder.index, ranges); } - const id = this._placeholderDecorations.get(placeholder)!; + const id = this._placeholderDecorations!.get(placeholder)!; const range = this._editor.getModel().getDecorationRange(id); if (!range) { // one of the placeholder lost its decoration and @@ -278,9 +278,9 @@ export class OneSnippet { // Remove the placeholder at which position are inserting // the snippet and also remove its decoration. - const id = this._placeholderDecorations.get(placeholder)!; + const id = this._placeholderDecorations!.get(placeholder)!; accessor.removeDecoration(id); - this._placeholderDecorations.delete(placeholder); + this._placeholderDecorations!.delete(placeholder); // For each *new* placeholder we create decoration to monitor // how and if it grows/shrinks. @@ -292,7 +292,7 @@ export class OneSnippet { model.getPositionAt(nested._offset + placeholderOffset + placeholderLen) ); const handle = accessor.addDecoration(range, OneSnippet._decor.inactive); - this._placeholderDecorations.set(placeholder, handle); + this._placeholderDecorations!.set(placeholder, handle); } } @@ -304,7 +304,7 @@ export class OneSnippet { public getEnclosingRange(): Range | undefined { let result: Range | undefined; const model = this._editor.getModel(); - this._placeholderDecorations.forEach((decorationId) => { + this._placeholderDecorations!.forEach((decorationId) => { const placeholderRange = withNullAsUndefined(model.getDecorationRange(decorationId)); if (!result) { result = placeholderRange; diff --git a/src/vs/editor/contrib/suggest/suggest.ts b/src/vs/editor/contrib/suggest/suggest.ts index 241a826a54c10..d63e47c881163 100644 --- a/src/vs/editor/contrib/suggest/suggest.ts +++ b/src/vs/editor/contrib/suggest/suggest.ts @@ -27,7 +27,7 @@ export const Context = { export class CompletionItem { - _brand: 'ISuggestionItem'; + _brand!: 'ISuggestionItem'; readonly resolve: (token: CancellationToken) => Promise; diff --git a/src/vs/editor/contrib/suggest/suggestMemory.ts b/src/vs/editor/contrib/suggest/suggestMemory.ts index 7e19017b79e28..f8997401fdec0 100644 --- a/src/vs/editor/contrib/suggest/suggestMemory.ts +++ b/src/vs/editor/contrib/suggest/suggestMemory.ts @@ -204,9 +204,9 @@ export class SuggestMemoryService extends Disposable implements ISuggestMemorySe private readonly _storagePrefix = 'suggest/memories'; private readonly _persistSoon: RunOnceScheduler; - private _mode: MemMode; - private _shareMem: boolean; - private _strategy: Memory; + private _mode!: MemMode; + private _shareMem!: boolean; + private _strategy!: Memory; constructor( @IStorageService private readonly _storageService: IStorageService, diff --git a/src/vs/editor/contrib/suggest/suggestModel.ts b/src/vs/editor/contrib/suggest/suggestModel.ts index 63de4055d7ef4..cabf449d896ec 100644 --- a/src/vs/editor/contrib/suggest/suggestModel.ts +++ b/src/vs/editor/contrib/suggest/suggestModel.ts @@ -92,8 +92,8 @@ export const enum State { export class SuggestModel implements IDisposable { private readonly _toDispose = new DisposableStore(); - private _quickSuggestDelay: number; - private _triggerCharacterListener: IDisposable; + private _quickSuggestDelay: number = 10; + private _triggerCharacterListener?: IDisposable; private readonly _triggerQuickSuggest = new TimeoutTimer(); private _state: State = State.Idle; @@ -161,7 +161,8 @@ export class SuggestModel implements IDisposable { } dispose(): void { - dispose([this._onDidCancel, this._onDidSuggest, this._onDidTrigger, this._triggerCharacterListener, this._triggerQuickSuggest]); + dispose(this._triggerCharacterListener); + dispose([this._onDidCancel, this._onDidSuggest, this._onDidTrigger, this._triggerQuickSuggest]); this._toDispose.dispose(); this._completionDisposables.dispose(); this.cancel(); diff --git a/src/vs/editor/contrib/suggest/suggestWidget.ts b/src/vs/editor/contrib/suggest/suggestWidget.ts index e6ac05dab25a9..f14ccafe1154a 100644 --- a/src/vs/editor/contrib/suggest/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/suggestWidget.ts @@ -253,7 +253,7 @@ class SuggestionDetails { private docs: HTMLElement; private ariaLabel: string | null; private readonly disposables: DisposableStore; - private renderDisposeable: IDisposable; + private renderDisposeable?: IDisposable; private borderWidth: number = 1; constructor( @@ -435,20 +435,20 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate | null; + private currentSuggestionDetails: CancelablePromise | null = null; private focusedItem: CompletionItem | null; - private ignoreFocusEvents = false; - private completionModel: CompletionModel | null; + private ignoreFocusEvents: boolean = false; + private completionModel: CompletionModel | null = null; private element: HTMLElement; private messageElement: HTMLElement; private listElement: HTMLElement; private details: SuggestionDetails; private list: List; - private listHeight: number; + private listHeight?: number; private readonly suggestWidgetVisible: IContextKey; private readonly suggestWidgetMultipleSuggestions: IContextKey; @@ -470,13 +470,13 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate { private readonly _subscriptions = new DisposableStore(); - private _isPressed: boolean; + private _isPressed: boolean = false; private static instance: AlternativeKeyEmitter; private _suppressAltKeyUp: boolean = false; @@ -137,7 +137,7 @@ export class MenuEntryActionViewItem extends ActionViewItem { static readonly ICON_PATH_TO_CSS_RULES: Map = new Map(); - private _wantsAltCommand: boolean; + private _wantsAltCommand: boolean = false; private readonly _itemClassDispose = this._register(new MutableDisposable()); private readonly _altKey: AlternativeKeyEmitter; diff --git a/src/vs/platform/actions/common/menuService.ts b/src/vs/platform/actions/common/menuService.ts index e0ee881b7732e..352a1ed945f95 100644 --- a/src/vs/platform/actions/common/menuService.ts +++ b/src/vs/platform/actions/common/menuService.ts @@ -31,8 +31,8 @@ class Menu extends Disposable implements IMenu { private readonly _onDidChange = this._register(new Emitter()); - private _menuGroups: MenuItemGroup[]; - private _contextKeys: Set; + private _menuGroups!: MenuItemGroup[]; + private _contextKeys!: Set; constructor( private readonly _id: MenuId, diff --git a/src/vs/workbench/api/browser/mainThreadEditor.ts b/src/vs/workbench/api/browser/mainThreadEditor.ts index 669ff5063fa8f..ff8e1cd513813 100644 --- a/src/vs/workbench/api/browser/mainThreadEditor.ts +++ b/src/vs/workbench/api/browser/mainThreadEditor.ts @@ -178,7 +178,7 @@ export class MainThreadTextEditor { private readonly _focusTracker: IFocusTracker; private readonly _codeEditorListeners = new DisposableStore(); - private _properties: MainThreadTextEditorProperties; + private _properties: MainThreadTextEditorProperties | null; private readonly _onPropertiesChanged: Emitter; constructor( @@ -191,6 +191,7 @@ export class MainThreadTextEditor { this._id = id; this._model = model; this._codeEditor = null; + this._properties = null; this._focusTracker = focusTracker; this._modelService = modelService; @@ -289,7 +290,7 @@ export class MainThreadTextEditor { } public getProperties(): MainThreadTextEditorProperties { - return this._properties; + return this._properties!; } public get onPropertiesChanged(): Event { @@ -304,7 +305,7 @@ export class MainThreadTextEditor { const newSelections = selections.map(Selection.liftSelection); this._setProperties( - new MainThreadTextEditorProperties(newSelections, this._properties.options, this._properties.visibleRanges), + new MainThreadTextEditorProperties(newSelections, this._properties!.options, this._properties!.visibleRanges), null ); }