Skip to content

Commit 2fe87d6

Browse files
committed
More strict null checks (microsoft#60565)
1 parent 850c030 commit 2fe87d6

44 files changed

Lines changed: 220 additions & 213 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"./vs/base/node/**/*.ts",
1111
"./vs/editor/common/**/*.ts",
1212
"./vs/editor/browser/**/*.ts",
13+
"./vs/editor/test/**/*.ts",
1314
"./vs/editor/contrib/smartSelect/**/*.ts"
1415
],
1516
"files": [

src/vs/editor/browser/controller/coreCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
2929
const CORE_WEIGHT = KeybindingWeight.EditorCore;
3030

3131
export abstract class CoreEditorCommand extends EditorCommand {
32-
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
32+
public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void {
3333
const cursors = editor._getCursors();
3434
if (!cursors) {
3535
// the editor has no view => has no cursors

src/vs/editor/browser/editorExtensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export abstract class EditorCommand extends Command {
166166
});
167167
}
168168

169-
public abstract runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Thenable<void>;
169+
public abstract runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void | Thenable<void>;
170170
}
171171

172172
//#endregion EditorCommand

src/vs/editor/common/core/position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class Position {
6969
/**
7070
* Test if position `a` equals position `b`
7171
*/
72-
public static equals(a: IPosition, b: IPosition): boolean {
72+
public static equals(a: IPosition | null, b: IPosition | null): boolean {
7373
if (!a && !b) {
7474
return true;
7575
}

src/vs/editor/common/model/editStack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class EditStack {
145145
this.pushStackElement();
146146
}
147147

148-
public pushEditOperation(beforeCursorState: Selection[], editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null {
148+
public pushEditOperation(beforeCursorState: Selection[], editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer | null): Selection[] | null {
149149
// No support for parallel universes :(
150150
this.future = [];
151151

@@ -174,7 +174,7 @@ export class EditStack {
174174
return stackElement!.afterCursorState;
175175
}
176176

177-
private static _computeCursorState(cursorStateComputer: ICursorStateComputer, inverseEditOperations: IIdentifiedSingleEditOperation[]): Selection[] | null {
177+
private static _computeCursorState(cursorStateComputer: ICursorStateComputer | null, inverseEditOperations: IIdentifiedSingleEditOperation[]): Selection[] | null {
178178
try {
179179
return cursorStateComputer ? cursorStateComputer(inverseEditOperations) : null;
180180
} catch (e) {

src/vs/editor/common/model/textModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ export class TextModel extends Disposable implements model.ITextModel {
11661166
}
11671167
}
11681168

1169-
public pushEditOperations(beforeCursorState: Selection[], editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer): Selection[] | null {
1169+
public pushEditOperations(beforeCursorState: Selection[], editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
11701170
try {
11711171
this._onDidChangeDecorations.beginDeferredEmit();
11721172
this._eventEmitter.beginDeferredEmit();
@@ -1177,7 +1177,7 @@ export class TextModel extends Disposable implements model.ITextModel {
11771177
}
11781178
}
11791179

1180-
private _pushEditOperations(beforeCursorState: Selection[], editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer): Selection[] | null {
1180+
private _pushEditOperations(beforeCursorState: Selection[], editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
11811181
if (this._options.trimAutoWhitespace && this._trimAutoWhitespaceLines) {
11821182
// Go through each saved line number and insert a trim whitespace edit
11831183
// if it is safe to do so (no conflicts with other edits).

src/vs/editor/common/modes/linkComputer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ export class LinkComputer {
301301
* document. *Note* that this operation is computational
302302
* expensive and should not run in the UI thread.
303303
*/
304-
export function computeLinks(model: ILinkComputerTarget): ILink[] {
304+
export function computeLinks(model: ILinkComputerTarget | null): ILink[] {
305305
if (!model || typeof model.getLineCount !== 'function' || typeof model.getLineContent !== 'function') {
306306
// Unknown caller!
307307
return [];

src/vs/editor/common/modes/supports/electricCharacter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class BracketElectricCharacterSupport {
2727
private readonly _richEditBrackets: RichEditBrackets | null;
2828
private readonly _complexAutoClosePairs: StandardAutoClosingPairConditional[];
2929

30-
constructor(richEditBrackets: RichEditBrackets | null, autoClosePairs: IAutoClosingPairConditional[], contribution: IBracketElectricCharacterContribution | undefined) {
30+
constructor(richEditBrackets: RichEditBrackets | null, autoClosePairs: IAutoClosingPairConditional[], contribution: IBracketElectricCharacterContribution | null | undefined) {
3131
contribution = contribution || {};
3232
this._richEditBrackets = richEditBrackets;
3333
this._complexAutoClosePairs = autoClosePairs.filter(pair => pair.open.length > 1 && !!pair.close).map(el => new StandardAutoClosingPairConditional(el));

src/vs/editor/common/services/modelServiceImpl.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ const DEFAULT_EOL = (platform.isLinux || platform.isMacintosh) ? DefaultEndOfLin
256256
export class ModelServiceImpl extends Disposable implements IModelService {
257257
public _serviceBrand: any;
258258

259-
private _markerService: IMarkerService;
259+
private _markerService: IMarkerService | null;
260260
private _markerServiceSubscription: IDisposable;
261261
private _configurationService: IConfigurationService;
262262
private _configurationServiceSubscription: IDisposable;
@@ -281,7 +281,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
281281
private _models: { [modelId: string]: ModelData; };
282282

283283
constructor(
284-
@IMarkerService markerService: IMarkerService,
284+
@IMarkerService markerService: IMarkerService | null,
285285
@IConfigurationService configurationService: IConfigurationService,
286286
@ITextResourcePropertiesService resourcePropertiesService: ITextResourcePropertiesService,
287287
) {
@@ -351,7 +351,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
351351
};
352352
}
353353

354-
public getCreationOptions(language: string, resource: URI | undefined, isForSimpleWidget: boolean): ITextModelCreationOptions {
354+
public getCreationOptions(language: string, resource: URI | null | undefined, isForSimpleWidget: boolean): ITextModelCreationOptions {
355355
let creationOptions = this._modelCreationOptionsByLanguageAndResource[language + resource];
356356
if (!creationOptions) {
357357
const editor = this._configurationService.getValue<IRawEditorConfig>('editor', { overrideIdentifier: language, resource });
@@ -419,7 +419,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
419419
if (!modelData) {
420420
return;
421421
}
422-
ModelMarkerHandler.setMarkers(modelData, this._markerService);
422+
ModelMarkerHandler.setMarkers(modelData, this._markerService!);
423423
});
424424
}
425425

@@ -429,7 +429,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
429429
|| model.uri.scheme === network.Schemas.internal
430430
|| model.uri.scheme === network.Schemas.vscode) {
431431
if (this._markerService) {
432-
this._markerService.read({ resource: model.uri }).map(marker => marker.owner).forEach(owner => this._markerService.remove(owner, [model.uri]));
432+
this._markerService.read({ resource: model.uri }).map(marker => marker.owner).forEach(owner => this._markerService!.remove(owner, [model.uri]));
433433
}
434434
}
435435

@@ -439,7 +439,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
439439

440440
// --- begin IModelService
441441

442-
private _createModelData(value: string | ITextBufferFactory, languageIdentifier: LanguageIdentifier, resource: URI | undefined, isForSimpleWidget: boolean): ModelData {
442+
private _createModelData(value: string | ITextBufferFactory, languageIdentifier: LanguageIdentifier, resource: URI | null | undefined, isForSimpleWidget: boolean): ModelData {
443443
// create & save the model
444444
const options = this.getCreationOptions(languageIdentifier.language, resource, isForSimpleWidget);
445445
const model: TextModel = new TextModel(value, options, languageIdentifier, resource);
@@ -530,7 +530,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
530530
return [EditOperation.replaceMove(oldRange, textBuffer.getValueInRange(newRange, EndOfLinePreference.TextDefined))];
531531
}
532532

533-
public createModel(value: string | ITextBufferFactory, languageSelection: ILanguageSelection | null, resource: URI | undefined, isForSimpleWidget: boolean = false): ITextModel {
533+
public createModel(value: string | ITextBufferFactory, languageSelection: ILanguageSelection | null, resource: URI | null | undefined, isForSimpleWidget: boolean = false): ITextModel {
534534
let modelData: ModelData;
535535

536536
if (languageSelection) {

src/vs/editor/common/services/resourceConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ export interface ITextResourcePropertiesService {
4343
/**
4444
* Returns the End of Line characters for the given resource
4545
*/
46-
getEOL(resource: URI | undefined, language?: string): string;
46+
getEOL(resource: URI | null | undefined, language?: string): string;
4747
}

0 commit comments

Comments
 (0)