Skip to content

Commit 1e2b78d

Browse files
committed
strict null checks (microsoft#60565)
1 parent 49f8bfb commit 1e2b78d

46 files changed

Lines changed: 260 additions & 150 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/tsconfig.strictNullChecks.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"strictNullChecks": true
66
},
77
"include": [
8-
"./typings",
8+
"./typings"
99
],
1010
"files": [
1111
"./vs/base/browser/browser.ts",
@@ -264,21 +264,36 @@
264264
"./vs/editor/common/viewModel/viewModel.ts",
265265
"./vs/editor/common/viewModel/viewModelDecorations.ts",
266266
"./vs/editor/common/viewModel/viewModelImpl.ts",
267+
"./vs/editor/contrib/bracketMatching/bracketMatching.ts",
268+
"./vs/editor/contrib/caretOperations/caretOperations.ts",
267269
"./vs/editor/contrib/caretOperations/moveCaretCommand.ts",
270+
"./vs/editor/contrib/caretOperations/transpose.ts",
271+
"./vs/editor/contrib/clipboard/clipboard.ts",
268272
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
269273
"./vs/editor/contrib/colorPicker/colorPickerModel.ts",
274+
"./vs/editor/contrib/comment/blockCommentCommand.ts",
275+
"./vs/editor/contrib/cursorUndo/cursorUndo.ts",
270276
"./vs/editor/contrib/dnd/dragAndDropCommand.ts",
271277
"./vs/editor/contrib/find/findState.ts",
272278
"./vs/editor/contrib/find/replaceAllCommand.ts",
273279
"./vs/editor/contrib/find/replacePattern.ts",
274280
"./vs/editor/contrib/fontZoom/fontZoom.ts",
281+
"./vs/editor/contrib/goToDefinition/clickLinkGesture.ts",
275282
"./vs/editor/contrib/hover/getHover.ts",
283+
"./vs/editor/contrib/hover/hoverOperation.ts",
284+
"./vs/editor/contrib/hover/hoverWidgets.ts",
276285
"./vs/editor/contrib/indentation/indentUtils.ts",
277286
"./vs/editor/contrib/inPlaceReplace/inPlaceReplaceCommand.ts",
278287
"./vs/editor/contrib/linesOperations/copyLinesCommand.ts",
288+
"./vs/editor/contrib/linesOperations/deleteLinesCommand.ts",
289+
"./vs/editor/contrib/linesOperations/sortLinesCommand.ts",
290+
"./vs/editor/contrib/links/getLinks.ts",
279291
"./vs/editor/contrib/quickOpen/quickOpen.ts",
280292
"./vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode.ts",
293+
"./vs/editor/contrib/wordOperations/wordOperations.ts",
281294
"./vs/editor/editor.worker.ts",
295+
"./vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts",
296+
"./vs/editor/standalone/browser/standaloneCodeServiceImpl.ts",
282297
"./vs/editor/standalone/common/monarch/monarchCommon.ts",
283298
"./vs/editor/standalone/common/monarch/monarchCompile.ts",
284299
"./vs/editor/standalone/common/monarch/monarchTypes.ts",

src/vs/editor/browser/editorBrowser.ts

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface IViewZone {
6464
/**
6565
* An optional dom node for the view zone that will be placed in the margin area.
6666
*/
67-
marginDomNode?: HTMLElement;
67+
marginDomNode?: HTMLElement | null;
6868
/**
6969
* Callback which gives the relative top of the view zone as it appears (taking scrolling into account).
7070
*/
@@ -121,12 +121,12 @@ export interface IContentWidgetPosition {
121121
* Desired position for the content widget.
122122
* `preference` will also affect the placement.
123123
*/
124-
position: IPosition;
124+
position: IPosition | null;
125125
/**
126126
* Optionally, a range can be provided to further
127127
* define the position of the content widget.
128128
*/
129-
range?: IRange;
129+
range?: IRange | null;
130130
/**
131131
* Placement preference for position, in order of preference.
132132
*/
@@ -154,7 +154,7 @@ export interface IContentWidget {
154154
* Get the placement of the content widget.
155155
* If null is returned, the content widget will be placed off screen.
156156
*/
157-
getPosition(): IContentWidgetPosition;
157+
getPosition(): IContentWidgetPosition | null;
158158
}
159159

160160
/**
@@ -201,7 +201,7 @@ export interface IOverlayWidget {
201201
* Get the placement of the overlay widget.
202202
* If null is returned, the overlay widget is responsible to place itself.
203203
*/
204-
getPosition(): IOverlayWidgetPosition;
204+
getPosition(): IOverlayWidgetPosition | null;
205205
}
206206

207207
/**
@@ -751,6 +751,74 @@ export interface ICodeEditor extends editorCommon.IEditor {
751751
* Apply the same font settings as the editor to `target`.
752752
*/
753753
applyFontInfo(target: HTMLElement): void;
754+
755+
/**
756+
* Check if the current instance has a model attached.
757+
* @internal
758+
*/
759+
hasModel(): this is IActiveCodeEditor;
760+
}
761+
762+
/**
763+
* @internal
764+
*/
765+
export interface IActiveCodeEditor extends ICodeEditor {
766+
/**
767+
* Returns the primary position of the cursor.
768+
*/
769+
getPosition(): Position;
770+
771+
/**
772+
* Returns the primary selection of the editor.
773+
*/
774+
getSelection(): Selection;
775+
776+
/**
777+
* Returns all the selections of the editor.
778+
*/
779+
getSelections(): Selection[];
780+
781+
/**
782+
* Saves current view state of the editor in a serializable object.
783+
*/
784+
saveViewState(): editorCommon.ICodeEditorViewState;
785+
786+
/**
787+
* Type the getModel() of IEditor.
788+
*/
789+
getModel(): ITextModel;
790+
791+
/**
792+
* @internal
793+
*/
794+
_getCursors(): ICursors;
795+
796+
/**
797+
* Get all the decorations on a line (filtering out decorations from other editors).
798+
*/
799+
getLineDecorations(lineNumber: number): IModelDecoration[];
800+
801+
/**
802+
* Returns the editor's dom node
803+
*/
804+
getDomNode(): HTMLElement;
805+
806+
/**
807+
* Get the hit test target at coordinates `clientX` and `clientY`.
808+
* The coordinates are relative to the top-left of the viewport.
809+
*
810+
* @returns Hit test target or null if the coordinates fall outside the editor or the editor has no model.
811+
*/
812+
getTargetAtClientPoint(clientX: number, clientY: number): IMouseTarget;
813+
814+
/**
815+
* Get the visible position for `position`.
816+
* The result position takes scrolling into account and is relative to the top left corner of the editor.
817+
* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.
818+
* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.
819+
* Warning: the results of this method are innacurate for positions that are outside the current editor viewport.
820+
*/
821+
getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number; };
754822
}
755823

756824
/**
@@ -830,19 +898,19 @@ export interface IDiffEditor extends editorCommon.IEditor {
830898
/**
831899
* Get the computed diff information.
832900
*/
833-
getLineChanges(): editorCommon.ILineChange[];
901+
getLineChanges(): editorCommon.ILineChange[] | null;
834902

835903
/**
836904
* Get information based on computed diff about a line number from the original model.
837905
* If the diff computation is not finished or the model is missing, will return null.
838906
*/
839-
getDiffLineInformationForOriginal(lineNumber: number): IDiffLineInformation;
907+
getDiffLineInformationForOriginal(lineNumber: number): IDiffLineInformation | null;
840908

841909
/**
842910
* Get information based on computed diff about a line number from the modified model.
843911
* If the diff computation is not finished or the model is missing, will return null.
844912
*/
845-
getDiffLineInformationForModified(lineNumber: number): IDiffLineInformation;
913+
getDiffLineInformationForModified(lineNumber: number): IDiffLineInformation | null;
846914
}
847915

848916
/**

src/vs/editor/browser/editorExtensions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ export interface ICommandMenubarOptions {
3939
export interface ICommandOptions {
4040
id: string;
4141
precondition: ContextKeyExpr | null;
42-
kbOpts?: ICommandKeybindingsOptions;
42+
kbOpts?: ICommandKeybindingsOptions | null;
4343
description?: ICommandHandlerDescription;
4444
menubarOpts?: ICommandMenubarOptions;
4545
}
4646
export abstract class Command {
4747
public readonly id: string;
4848
public readonly precondition: ContextKeyExpr | null;
49-
private readonly _kbOpts: ICommandKeybindingsOptions | undefined;
50-
private readonly _menubarOpts: ICommandMenubarOptions | undefined;
51-
private readonly _description: ICommandHandlerDescription | undefined;
49+
private readonly _kbOpts: ICommandKeybindingsOptions | null | undefined;
50+
private readonly _menubarOpts: ICommandMenubarOptions | null | undefined;
51+
private readonly _description: ICommandHandlerDescription | null | undefined;
5252

5353
constructor(opts: ICommandOptions) {
5454
this.id = opts.id;
@@ -160,7 +160,7 @@ export abstract class EditorCommand extends Command {
160160
return;
161161
}
162162

163-
return this.runEditorCommand(editorAccessor, editor, args);
163+
return this.runEditorCommand(editorAccessor, editor!, args);
164164
});
165165
}
166166

src/vs/editor/browser/services/abstractCodeEditorService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ export abstract class AbstractCodeEditorService extends Disposable implements IC
125125
delete this._transientWatchers[w.uri];
126126
}
127127

128-
abstract getActiveCodeEditor(): ICodeEditor;
129-
abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor>;
128+
abstract getActiveCodeEditor(): ICodeEditor | null;
129+
abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor | null>;
130130
}
131131

132132
export class ModelTransientSettingWatcher {

src/vs/editor/browser/services/codeEditorService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ export interface ICodeEditorService {
4444
setTransientModelProperty(model: ITextModel, key: string, value: any): void;
4545
getTransientModelProperty(model: ITextModel, key: string): any;
4646

47-
getActiveCodeEditor(): ICodeEditor;
48-
openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor>;
47+
getActiveCodeEditor(): ICodeEditor | null;
48+
openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor | null>;
4949
}

src/vs/editor/browser/services/codeEditorServiceImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export abstract class CodeEditorServiceImpl extends AbstractCodeEditorService {
6666
return provider.getOptions(this, writable);
6767
}
6868

69-
abstract getActiveCodeEditor(): ICodeEditor;
70-
abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor>;
69+
abstract getActiveCodeEditor(): ICodeEditor | null;
70+
abstract openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor | null>;
7171
}
7272

7373
interface IModelDecorationOptionsProvider extends IDisposable {

src/vs/editor/browser/view/viewImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ import { IMouseEvent } from 'vs/base/browser/mouseEvent';
5151

5252
export interface IContentWidgetData {
5353
widget: editorBrowser.IContentWidget;
54-
position: editorBrowser.IContentWidgetPosition;
54+
position: editorBrowser.IContentWidgetPosition | null;
5555
}
5656

5757
export interface IOverlayWidgetData {
5858
widget: editorBrowser.IOverlayWidget;
59-
position: editorBrowser.IOverlayWidgetPosition;
59+
position: editorBrowser.IOverlayWidgetPosition | null;
6060
}
6161

6262
const invalidFunc = () => { throw new Error(`Invalid change accessor`); };

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,10 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
15191519
public getTelemetryData(): { [key: string]: any; } | null {
15201520
return this._telemetryData;
15211521
}
1522+
1523+
public hasModel(): this is editorBrowser.IActiveCodeEditor {
1524+
return (this._modelData !== null);
1525+
}
15221526
}
15231527

15241528
const enum BooleanEventValue {

0 commit comments

Comments
 (0)