Skip to content

Commit 654015a

Browse files
committed
editor/common strict null (#60565)
1 parent 380256b commit 654015a

40 files changed

+340
-275
lines changed

Diff for: src/tsconfig.strictNullChecks.json

+43
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"./vs/base/common/linkedList.ts",
5555
"./vs/base/common/map.ts",
5656
"./vs/base/common/marshalling.ts",
57+
"./vs/base/common/mime.ts",
5758
"./vs/base/common/network.ts",
5859
"./vs/base/common/normalization.ts",
5960
"./vs/base/common/numbers.ts",
@@ -96,13 +97,27 @@
9697
"./vs/editor/browser/config/charWidthReader.ts",
9798
"./vs/editor/browser/config/elementSizeObserver.ts",
9899
"./vs/editor/browser/controller/textAreaState.ts",
100+
"./vs/editor/common",
99101
"./vs/editor/common/commands/replaceCommand.ts",
102+
"./vs/editor/common/commands/shiftCommand.ts",
100103
"./vs/editor/common/commands/surroundSelectionCommand.ts",
101104
"./vs/editor/common/commands/trimTrailingWhitespaceCommand.ts",
105+
"./vs/editor/common/config/commonEditorConfig.ts",
102106
"./vs/editor/common/config/editorOptions.ts",
103107
"./vs/editor/common/config/editorZoom.ts",
104108
"./vs/editor/common/config/fontInfo.ts",
109+
"./vs/editor/common/controller/cursor.ts",
110+
"./vs/editor/common/controller/cursorCollection.ts",
111+
"./vs/editor/common/controller/cursorColumnSelection.ts",
112+
"./vs/editor/common/controller/cursorCommon.ts",
113+
"./vs/editor/common/controller/cursorDeleteOperations.ts",
105114
"./vs/editor/common/controller/cursorEvents.ts",
115+
"./vs/editor/common/controller/cursorEvents.ts",
116+
"./vs/editor/common/controller/cursorMoveCommands.ts",
117+
"./vs/editor/common/controller/cursorMoveOperations.ts",
118+
"./vs/editor/common/controller/cursorTypeOperations.ts",
119+
"./vs/editor/common/controller/cursorWordOperations.ts",
120+
"./vs/editor/common/controller/oneCursor.ts",
106121
"./vs/editor/common/controller/wordCharacterClassifier.ts",
107122
"./vs/editor/common/core/characterClassifier.ts",
108123
"./vs/editor/common/core/editOperation.ts",
@@ -139,6 +154,7 @@
139154
"./vs/editor/common/modes/languageFeatureRegistry.ts",
140155
"./vs/editor/common/modes/languageSelector.ts",
141156
"./vs/editor/common/modes/linkComputer.ts",
157+
"./vs/editor/common/modes/modesRegistry.ts",
142158
"./vs/editor/common/modes/nullMode.ts",
143159
"./vs/editor/common/modes/supports.ts",
144160
"./vs/editor/common/modes/supports/characterPair.ts",
@@ -150,17 +166,40 @@
150166
"./vs/editor/common/modes/supports/tokenization.ts",
151167
"./vs/editor/common/modes/textToHtmlTokenizer.ts",
152168
"./vs/editor/common/modes/tokenizationRegistry.ts",
169+
"./vs/editor/common/services/editorSimpleWorker.ts",
153170
"./vs/editor/common/services/editorWorkerService.ts",
171+
"./vs/editor/common/services/editorWorkerServiceImpl.ts",
172+
"./vs/editor/common/services/languagesRegistry.ts",
154173
"./vs/editor/common/services/modelService.ts",
174+
"./vs/editor/common/services/modelServiceImpl.ts",
155175
"./vs/editor/common/services/modeService.ts",
176+
"./vs/editor/common/services/modeServiceImpl.ts",
156177
"./vs/editor/common/services/resolverService.ts",
178+
"./vs/editor/common/services/resourceConfiguration.ts",
179+
"./vs/editor/common/services/resourceConfigurationImpl.ts",
180+
"./vs/editor/common/services/webWorker.ts",
157181
"./vs/editor/common/standalone/standaloneBase.ts",
182+
"./vs/editor/common/view/editorColorRegistry.ts",
158183
"./vs/editor/common/view/minimapCharRenderer.ts",
159184
"./vs/editor/common/view/overviewZoneManager.ts",
185+
"./vs/editor/common/view/renderingContext.ts",
160186
"./vs/editor/common/view/runtimeMinimapCharRenderer.ts",
187+
"./vs/editor/common/view/viewContext.ts",
188+
"./vs/editor/common/view/viewEventDispatcher.ts",
161189
"./vs/editor/common/view/viewEvents.ts",
190+
"./vs/editor/common/viewLayout/lineDecorations.ts",
191+
"./vs/editor/common/viewLayout/linesLayout.ts",
192+
"./vs/editor/common/viewLayout/viewLayout.ts",
193+
"./vs/editor/common/viewLayout/viewLineRenderer.ts",
194+
"./vs/editor/common/viewLayout/viewLinesViewportData.ts",
162195
"./vs/editor/common/viewLayout/whitespaceComputer.ts",
196+
"./vs/editor/common/viewModel/characterHardWrappingLineMapper.ts",
163197
"./vs/editor/common/viewModel/prefixSumComputer.ts",
198+
"./vs/editor/common/viewModel/splitLinesCollection.ts",
199+
"./vs/editor/common/viewModel/viewEventHandler.ts",
200+
"./vs/editor/common/viewModel/viewModel.ts",
201+
"./vs/editor/common/viewModel/viewModelDecorations.ts",
202+
"./vs/editor/common/viewModel/viewModelImpl.ts",
164203
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
165204
"./vs/editor/contrib/colorPicker/colorPickerModel.ts",
166205
"./vs/editor/contrib/find/findState.ts",
@@ -180,10 +219,13 @@
180219
"./vs/editor/test/common/modes/supports/javascriptOnEnterRules.ts",
181220
"./vs/editor/test/common/modesTestUtils.ts",
182221
"./vs/monaco.d.ts",
222+
"./vs/nls.d.ts",
183223
"./vs/nls.mock.ts",
184224
"./vs/platform/broadcast/electron-browser/broadcastService.ts",
185225
"./vs/platform/clipboard/common/clipboardService.ts",
186226
"./vs/platform/clipboard/electron-browser/clipboardService.ts",
227+
"./vs/platform/configuration/common/configuration.ts",
228+
"./vs/platform/configuration/common/configurationRegistry.ts",
187229
"./vs/platform/contextkey/common/contextkey.ts",
188230
"./vs/platform/download/common/download.ts",
189231
"./vs/platform/editor/common/editor.ts",
@@ -228,6 +270,7 @@
228270
"./vs/platform/url/common/url.ts",
229271
"./vs/platform/url/common/urlService.ts",
230272
"./vs/platform/workbench/common/contextkeys.ts",
273+
"./vs/platform/workspace/common/workspace.ts",
231274
"./vs/workbench/api/shared/tasks.ts",
232275
"./vs/workbench/browser/parts/statusbar/statusbar.ts",
233276
"./vs/workbench/common/activity.ts",

Diff for: src/vs/base/common/arrays.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,16 @@ function topStep<T>(array: T[], compare: (a: T, b: T) => number, result: T[], i:
299299
/**
300300
* @returns a new array with all undefined or null values removed. The original array is not modified at all.
301301
*/
302-
export function coalesce<T>(array: T[]): T[];
303-
export function coalesce<T>(array: T[], inplace: true): void;
304-
export function coalesce<T>(array: T[], inplace?: true): void | T[] {
302+
export function coalesce<T>(array: (T | undefined | null)[]): T[];
303+
export function coalesce<T>(array: (T | undefined | null)[], inplace: true): void;
304+
export function coalesce<T>(array: (T | undefined | null)[], inplace?: true): void | T[] {
305305
if (!array) {
306306
if (!inplace) {
307307
return array;
308308
}
309309
}
310310
if (!inplace) {
311-
return array.filter(e => !!e);
311+
return <T[]>array.filter(e => !!e);
312312

313313
} else {
314314
let to = 0;

Diff for: src/vs/base/common/mime.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import * as paths from 'vs/base/common/paths';
77
import * as strings from 'vs/base/common/strings';
8+
import * as arrays from 'vs/base/common/arrays';
89
import { match } from 'vs/base/common/glob';
910

1011
export const MIME_TEXT = 'text/plain';
@@ -136,10 +137,10 @@ export function guessMimeTypes(path: string, firstLine?: string): string[] {
136137
return [MIME_UNKNOWN];
137138
}
138139

139-
function guessMimeTypeByPath(path: string, filename: string, associations: ITextMimeAssociationItem[]): string {
140-
let filenameMatch: ITextMimeAssociationItem;
141-
let patternMatch: ITextMimeAssociationItem;
142-
let extensionMatch: ITextMimeAssociationItem;
140+
function guessMimeTypeByPath(path: string, filename: string, associations: ITextMimeAssociationItem[]): string | null {
141+
let filenameMatch: ITextMimeAssociationItem | null = null;
142+
let patternMatch: ITextMimeAssociationItem | null = null;
143+
let extensionMatch: ITextMimeAssociationItem | null = null;
143144

144145
// We want to prioritize associations based on the order they are registered so that the last registered
145146
// association wins over all other. This is for https://github.com/Microsoft/vscode/issues/20074
@@ -154,18 +155,18 @@ function guessMimeTypeByPath(path: string, filename: string, associations: IText
154155

155156
// Longest pattern match
156157
if (association.filepattern) {
157-
if (!patternMatch || association.filepattern.length > patternMatch.filepattern.length) {
158+
if (!patternMatch || association.filepattern.length > patternMatch.filepattern!.length) {
158159
const target = association.filepatternOnPath ? path : filename; // match on full path if pattern contains path separator
159-
if (match(association.filepatternLowercase, target)) {
160+
if (match(association.filepatternLowercase!, target)) {
160161
patternMatch = association;
161162
}
162163
}
163164
}
164165

165166
// Longest extension match
166167
if (association.extension) {
167-
if (!extensionMatch || association.extension.length > extensionMatch.extension.length) {
168-
if (strings.endsWith(filename, association.extensionLowercase)) {
168+
if (!extensionMatch || association.extension.length > extensionMatch.extension!.length) {
169+
if (strings.endsWith(filename, association.extensionLowercase!)) {
169170
extensionMatch = association;
170171
}
171172
}
@@ -190,7 +191,7 @@ function guessMimeTypeByPath(path: string, filename: string, associations: IText
190191
return null;
191192
}
192193

193-
function guessMimeTypeByFirstline(firstLine: string): string {
194+
function guessMimeTypeByFirstline(firstLine: string): string | null {
194195
if (strings.startsWithUTF8BOM(firstLine)) {
195196
firstLine = firstLine.substr(1);
196197
}
@@ -234,7 +235,7 @@ export function suggestFilename(langId: string, prefix: string): string {
234235
const extensions = registeredAssociations
235236
.filter(assoc => !assoc.userConfigured && assoc.extension && assoc.id === langId)
236237
.map(assoc => assoc.extension);
237-
const extensionsWithDotFirst = extensions
238+
const extensionsWithDotFirst = arrays.coalesce(extensions)
238239
.filter(assoc => strings.startsWith(assoc, '.'));
239240

240241
if (extensionsWithDotFirst.length > 0) {

Diff for: src/vs/base/common/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ export function isBoolean(obj: any): obj is boolean {
8282
/**
8383
* @returns whether the provided parameter is undefined.
8484
*/
85-
export function isUndefined(obj: any): boolean {
85+
export function isUndefined(obj: any): obj is undefined {
8686
return typeof (obj) === _typeof.undefined;
8787
}
8888

8989
/**
9090
* @returns whether the provided parameter is undefined or null.
9191
*/
92-
export function isUndefinedOrNull(obj: any): boolean {
92+
export function isUndefinedOrNull(obj: any): obj is undefined | null {
9393
return isUndefined(obj) || obj === null;
9494
}
9595

Diff for: src/vs/base/worker/defaultWorkerFactory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ export class DefaultWorkerFactory implements IWorkerFactory {
6767

6868
private static LAST_WORKER_ID = 0;
6969

70-
private _label: string;
70+
private _label: string | undefined;
7171
private _webWorkerFailedBeforeError: any;
7272

73-
constructor(label: string) {
73+
constructor(label: string | undefined) {
7474
this._label = label;
7575
this._webWorkerFailedBeforeError = false;
7676
}

Diff for: src/vs/editor/common/config/commonEditorConfig.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
8585
this._rawOptions.parameterHints = objects.mixin({}, this._rawOptions.parameterHints || {});
8686

8787
this._validatedOptions = editorOptions.EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS);
88-
this.editor = null;
8988
this._isDominatedByLongLines = false;
9089
this._lineNumbersDigitCount = 1;
9190

@@ -866,12 +865,12 @@ const editorConfiguration: IConfigurationNode = {
866865
}
867866
};
868867

869-
let cachedEditorConfigurationKeys: { [key: string]: boolean; } = null;
868+
let cachedEditorConfigurationKeys: { [key: string]: boolean; } | null = null;
870869
function getEditorConfigurationKeys(): { [key: string]: boolean; } {
871870
if (cachedEditorConfigurationKeys === null) {
872-
cachedEditorConfigurationKeys = Object.create(null);
873-
Object.keys(editorConfiguration.properties).forEach((prop) => {
874-
cachedEditorConfigurationKeys[prop] = true;
871+
cachedEditorConfigurationKeys = <{ [key: string]: boolean; }>Object.create(null);
872+
Object.keys(editorConfiguration.properties!).forEach((prop) => {
873+
cachedEditorConfigurationKeys![prop] = true;
875874
});
876875
}
877876
return cachedEditorConfigurationKeys;

0 commit comments

Comments
 (0)