From 3e2dd462014cb56cb36f26ea33326bd6232e1328 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 13 Dec 2018 14:14:47 +0100 Subject: [PATCH] debt - more strict null checks --- src/tsconfig.strictNullChecks.json | 14 ++++++------- .../contrib/referenceSearch/peekViewWidget.ts | 21 +++++++++---------- .../referenceSearch/referenceSearch.ts | 21 +++++++++++-------- .../referenceSearch/referencesWidget.ts | 6 +++--- .../test/referencesModel.test.ts | 10 ++++----- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 00c39f1328d..ce36015a0b5 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -11,7 +11,10 @@ "./vs/editor/common/**/*.ts", "./vs/editor/browser/**/*.ts", "./vs/editor/test/**/*.ts", - "./vs/editor/contrib/smartSelect/**/*.ts" + "./vs/editor/contrib/smartSelect/**/*.ts", + "./vs/editor/contrib/format/**/*.ts", + "./vs/editor/contrib/gotoError/**/*.ts", + "./vs/editor/contrib/inPlaceReplace/**/*.ts" ], "files": [ "./vs/base/browser/browser.ts", @@ -221,21 +224,14 @@ "./vs/editor/contrib/folding/test/indentRangeProvider.test.ts", "./vs/editor/contrib/folding/test/syntaxFold.test.ts", "./vs/editor/contrib/fontZoom/fontZoom.ts", - "./vs/editor/contrib/format/format.ts", - "./vs/editor/contrib/format/formatActions.ts", - "./vs/editor/contrib/format/formattingEdit.ts", "./vs/editor/contrib/goToDefinition/clickLinkGesture.ts", "./vs/editor/contrib/goToDefinition/goToDefinition.ts", - "./vs/editor/contrib/gotoError/gotoError.ts", - "./vs/editor/contrib/gotoError/gotoErrorWidget.ts", "./vs/editor/contrib/hover/getHover.ts", "./vs/editor/contrib/hover/hover.ts", "./vs/editor/contrib/hover/hoverOperation.ts", "./vs/editor/contrib/hover/hoverWidgets.ts", "./vs/editor/contrib/hover/modesContentHover.ts", "./vs/editor/contrib/hover/modesGlyphHover.ts", - "./vs/editor/contrib/inPlaceReplace/inPlaceReplace.ts", - "./vs/editor/contrib/inPlaceReplace/inPlaceReplaceCommand.ts", "./vs/editor/contrib/indentation/indentUtils.ts", "./vs/editor/contrib/indentation/indentation.ts", "./vs/editor/contrib/indentation/test/indentation.test.ts", @@ -258,7 +254,9 @@ "./vs/editor/contrib/parameterHints/test/parameterHintsModel.test.ts", "./vs/editor/contrib/quickOpen/quickOpen.ts", "./vs/editor/contrib/referenceSearch/referencesModel.ts", + "./vs/editor/contrib/referenceSearch/test/referencesModel.test.ts", "./vs/editor/contrib/referenceSearch/referencesTree.ts", + "./vs/editor/contrib/referenceSearch/peekViewWidget.ts", "./vs/editor/contrib/rename/rename.ts", "./vs/editor/contrib/rename/renameInputField.ts", "./vs/editor/contrib/snippet/snippetParser.ts", diff --git a/src/vs/editor/contrib/referenceSearch/peekViewWidget.ts b/src/vs/editor/contrib/referenceSearch/peekViewWidget.ts index 76d1b775f95..39429bdf72e 100644 --- a/src/vs/editor/contrib/referenceSearch/peekViewWidget.ts +++ b/src/vs/editor/contrib/referenceSearch/peekViewWidget.ts @@ -25,7 +25,7 @@ export namespace PeekContext { export const notInPeekEditor: ContextKeyExpr = inPeekEditor.toNegated(); } -export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor { +export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor | null { let editor = accessor.get(ICodeEditorService).getFocusedCodeEditor(); if (editor instanceof EmbeddedCodeEditorWidget) { return editor.getParentEditor(); @@ -34,13 +34,12 @@ export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor { } export interface IPeekViewStyles extends IStyles { - headerBackgroundColor?: Color; - primaryHeadingColor?: Color; - secondaryHeadingColor?: Color; + headerBackgroundColor?: Color | null; + primaryHeadingColor?: Color | null; + secondaryHeadingColor?: Color | null; } -export interface IPeekViewOptions extends IOptions, IPeekViewStyles { -} +export type IPeekViewOptions = IOptions & IPeekViewStyles; const defaultOptions: IPeekViewOptions = { headerBackgroundColor: Color.white, @@ -92,16 +91,16 @@ export abstract class PeekViewWidget extends ZoneWidget { protected _applyStyles(): void { super._applyStyles(); let options = this.options; - if (this._headElement) { + if (this._headElement && options.headerBackgroundColor) { this._headElement.style.backgroundColor = options.headerBackgroundColor.toString(); } - if (this._primaryHeading) { + if (this._primaryHeading && options.primaryHeadingColor) { this._primaryHeading.style.color = options.primaryHeadingColor.toString(); } - if (this._secondaryHeading) { + if (this._secondaryHeading && options.secondaryHeadingColor) { this._secondaryHeading.style.color = options.secondaryHeadingColor.toString(); } - if (this._bodyElement) { + if (this._bodyElement && options.frameColor) { this._bodyElement.style.borderColor = options.frameColor.toString(); } } @@ -138,7 +137,7 @@ export abstract class PeekViewWidget extends ZoneWidget { this._actionbarWidget.push(new Action('peekview.close', nls.localize('label.close', "Close"), 'close-peekview-action', true, () => { this.dispose(); - return null; + return Promise.resolve(); }), { label: false, icon: true }); } diff --git a/src/vs/editor/contrib/referenceSearch/referenceSearch.ts b/src/vs/editor/contrib/referenceSearch/referenceSearch.ts index 539d96078e6..fcee1228ee2 100644 --- a/src/vs/editor/contrib/referenceSearch/referenceSearch.ts +++ b/src/vs/editor/contrib/referenceSearch/referenceSearch.ts @@ -30,7 +30,7 @@ import { CancellationToken } from 'vs/base/common/cancellation'; export const defaultReferenceSearchOptions: RequestOptions = { getMetaTitle(model) { - return model.references.length > 1 && nls.localize('meta.titleReference', " – {0} references", model.references.length); + return model.references.length > 1 ? nls.localize('meta.titleReference', " – {0} references", model.references.length) : ''; } }; @@ -78,15 +78,17 @@ export class ReferenceAction extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { + public run(_accessor: ServicesAccessor, editor: ICodeEditor): void { let controller = ReferencesController.get(editor); if (!controller) { return; } - let range = editor.getSelection(); - let model = editor.getModel(); - let references = createCancelablePromise(token => provideReferences(model, range.getStartPosition(), token).then(references => new ReferencesModel(references))); - controller.toggleWidget(range, references, defaultReferenceSearchOptions); + if (editor.hasModel()) { + const range = editor.getSelection(); + const model = editor.getModel(); + const references = createCancelablePromise(token => provideReferences(model, range.getStartPosition(), token).then(references => new ReferencesModel(references))); + controller.toggleWidget(range, references, defaultReferenceSearchOptions); + } } } @@ -104,7 +106,7 @@ let findReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resour const codeEditorService = accessor.get(ICodeEditorService); return codeEditorService.openCodeEditor({ resource }, codeEditorService.getFocusedCodeEditor()).then(control => { - if (!isCodeEditor(control)) { + if (!isCodeEditor(control) || !control.hasModel()) { return undefined; } @@ -139,10 +141,11 @@ let showReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resour return undefined; } - return Promise.resolve(controller.toggleWidget( + return controller.toggleWidget( new Range(position.lineNumber, position.column, position.lineNumber, position.column), createCancelablePromise(_ => Promise.resolve(new ReferencesModel(references))), - defaultReferenceSearchOptions)).then(() => true); + defaultReferenceSearchOptions + ); }); }; diff --git a/src/vs/editor/contrib/referenceSearch/referencesWidget.ts b/src/vs/editor/contrib/referenceSearch/referencesWidget.ts index e27a095b0f4..cefcc1423f8 100644 --- a/src/vs/editor/contrib/referenceSearch/referencesWidget.ts +++ b/src/vs/editor/contrib/referenceSearch/referencesWidget.ts @@ -227,7 +227,7 @@ export const ctxReferenceWidgetSearchTreeFocused = new RawContextKey('r */ export class ReferenceWidget extends PeekViewWidget { - private _model: ReferencesModel; + private _model: ReferencesModel | undefined; private _decorationsManager: DecorationsManager; private _disposeOnNewModel: IDisposable[] = []; @@ -272,7 +272,7 @@ export class ReferenceWidget extends PeekViewWidget { } public dispose(): void { - this.setModel(null); + this.setModel(undefined); this._callOnDispose = dispose(this._callOnDispose); dispose(this._preview, this._previewNotAvailableMessage, this._tree, this._sash, this._previewModelReference); super.dispose(); @@ -441,7 +441,7 @@ export class ReferenceWidget extends PeekViewWidget { }); } - public setModel(newModel: ReferencesModel): Promise { + public setModel(newModel: ReferencesModel | undefined): Promise { // clean up this._disposeOnNewModel = dispose(this._disposeOnNewModel); this._model = newModel; diff --git a/src/vs/editor/contrib/referenceSearch/test/referencesModel.test.ts b/src/vs/editor/contrib/referenceSearch/test/referencesModel.test.ts index c5269c687f9..edd6fd01309 100644 --- a/src/vs/editor/contrib/referenceSearch/test/referencesModel.test.ts +++ b/src/vs/editor/contrib/referenceSearch/test/referencesModel.test.ts @@ -23,16 +23,16 @@ suite('references', function () { }]); let ref = model.nearestReference(URI.file('/src/can'), new Position(1, 1)); - assert.equal(ref.uri.path, '/src/can'); + assert.equal(ref!.uri.path, '/src/can'); ref = model.nearestReference(URI.file('/src/someOtherFileInSrc'), new Position(1, 1)); - assert.equal(ref.uri.path, '/src/can'); + assert.equal(ref!.uri.path, '/src/can'); ref = model.nearestReference(URI.file('/out/someOtherFile'), new Position(1, 1)); - assert.equal(ref.uri.path, '/out/obj/can'); + assert.equal(ref!.uri.path, '/out/obj/can'); ref = model.nearestReference(URI.file('/out/obj/can2222'), new Position(1, 1)); - assert.equal(ref.uri.path, '/out/obj/can2'); + assert.equal(ref!.uri.path, '/out/obj/can2'); }); -}); \ No newline at end of file +});