Skip to content

Commit

Permalink
strict init work, #78168
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Aug 5, 2019
1 parent 9afa70a commit e428bed
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 77 deletions.
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class InPlaceReplaceController implements IEditorContribution {
private readonly editor: ICodeEditor;
private readonly editorWorkerService: IEditorWorkerService;
private decorationIds: string[] = [];
private currentRequest: CancelablePromise<IInplaceReplaceSupportResult | null>;
private decorationRemover: CancelablePromise<void>;
private currentRequest?: CancelablePromise<IInplaceReplaceSupportResult | null>;
private decorationRemover?: CancelablePromise<void>;

constructor(
editor: ICodeEditor,
Expand Down
14 changes: 7 additions & 7 deletions src/vs/editor/contrib/referenceSearch/referencesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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();
}));
Expand Down Expand Up @@ -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
Expand Down
25 changes: 12 additions & 13 deletions src/vs/editor/contrib/referenceSearch/referencesWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -191,22 +191,21 @@ export const ctxReferenceWidgetSearchTreeFocused = new RawContextKey<boolean>('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<SelectionEvent>();

private _tree: WorkbenchAsyncDataTree<ReferencesModel | FileReferences, TreeElement, FuzzyScore>;
private _treeContainer: HTMLElement;
// private _sash: VSash;
private _splitView: SplitView;
private _preview: ICodeEditor;
private _previewModelReference: IReference<ITextEditorModel>;
private _previewNotAvailableMessage: TextModel;
private _previewContainer: HTMLElement;
private _messageContainer: HTMLElement;
private _tree!: WorkbenchAsyncDataTree<ReferencesModel | FileReferences, TreeElement, FuzzyScore>;
private _treeContainer!: HTMLElement;
private _splitView!: SplitView;
private _preview!: ICodeEditor;
private _previewModelReference!: IReference<ITextEditorModel>;
private _previewNotAvailableMessage!: TextModel;
private _previewContainer!: HTMLElement;
private _messageContainer!: HTMLElement;
private _dim: dom.Dimension = { height: 0, width: 0 };

constructor(
Expand Down
34 changes: 17 additions & 17 deletions src/vs/editor/contrib/rename/renameInputField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export const CONTEXT_RENAME_INPUT_VISIBLE = new RawContextKey<boolean>('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<boolean>;
private readonly _disposables = new DisposableStore();

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}

Expand All @@ -133,10 +133,10 @@ export class RenameInputField implements IContentWidget, IDisposable {
public getInput(where: IRange, value: string, selectionStart: number, selectionEnd: number): Promise<string | boolean> {

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 = () => {
Expand All @@ -154,15 +154,15 @@ 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;
}

this._currentAcceptInput = null;
this._currentCancelInput = null;
resolve(this._inputField.value);
resolve(this._inputField!.value);
};

let onCursorChanged = () => {
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/snippet/snippetController2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 12 additions & 12 deletions src/vs/editor/contrib/snippet/snippetSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class OneSnippet {
private readonly _snippet: TextmateSnippet;
private readonly _offset: number;

private _placeholderDecorations: Map<Placeholder, string>;
private _placeholderDecorations?: Map<Placeholder, string>;
private _placeholderGroups: Placeholder[][];
_placeholderGroupsIdx: number;
_nestingLevel: number = 1;
Expand Down Expand Up @@ -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);
}
});
}
Expand All @@ -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);

Expand Down Expand Up @@ -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));

Expand All @@ -161,15 +161,15 @@ 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);
}
}

// 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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/suggest/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Context = {

export class CompletionItem {

_brand: 'ISuggestionItem';
_brand!: 'ISuggestionItem';

readonly resolve: (token: CancellationToken) => Promise<void>;

Expand Down
6 changes: 3 additions & 3 deletions src/vs/editor/contrib/suggest/suggestMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/vs/editor/contrib/suggest/suggestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit e428bed

Please sign in to comment.