Skip to content

Commit 480b838

Browse files
committed
Strict null check apiCommands
1 parent e3964c9 commit 480b838

8 files changed

Lines changed: 28 additions & 27 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"./vs/workbench/api/electron-browser/mainThreadUrls.ts",
7575
"./vs/workbench/api/electron-browser/mainThreadWindow.ts",
7676
"./vs/workbench/api/electron-browser/mainThreadWorkspace.ts",
77+
"./vs/workbench/api/node/apiCommands.ts",
7778
"./vs/workbench/api/node/extHost.protocol.ts",
7879
"./vs/workbench/api/node/extHostClipboard.ts",
7980
"./vs/workbench/api/node/extHostConfiguration.ts",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export class EditOperation {
2424
};
2525
}
2626

27-
public static replace(range: Range, text: string): IIdentifiedSingleEditOperation {
27+
public static replace(range: Range, text: string | null): IIdentifiedSingleEditOperation {
2828
return {
2929
range: range,
3030
text: text
3131
};
3232
}
3333

34-
public static replaceMove(range: Range, text: string): IIdentifiedSingleEditOperation {
34+
public static replaceMove(range: Range, text: string | null): IIdentifiedSingleEditOperation {
3535
return {
3636
range: range,
3737
text: text,

src/vs/editor/common/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export interface ISingleEditOperation {
289289
/**
290290
* The text to replace with. This can be null to emulate a simple delete.
291291
*/
292-
text: string;
292+
text: string | null;
293293
/**
294294
* This indicates that this operation has "insert" semantics.
295295
* i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved.

src/vs/editor/contrib/format/formattingEdit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class FormattingEdit {
4545

4646
static execute(editor: ICodeEditor, _edits: TextEdit[]) {
4747
editor.pushUndoStop();
48-
let edits = FormattingEdit._handleEolEdits(editor, _edits);
48+
const edits = FormattingEdit._handleEolEdits(editor, _edits);
4949
if (edits.length === 1 && FormattingEdit._isFullModelReplaceEdit(editor, edits[0])) {
5050
// We use replace semantics and hope that markers stay put...
5151
editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replace(Range.lift(edit.range), edit.text)));

src/vs/monaco.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ declare namespace monaco.editor {
13871387
/**
13881388
* The text to replace with. This can be null to emulate a simple delete.
13891389
*/
1390-
text: string;
1390+
text: string | null;
13911391
/**
13921392
* This indicates that this operation has "insert" semantics.
13931393
* i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved.

src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { EditOperation } from 'vs/editor/common/core/editOperation';
1616
import { Position } from 'vs/editor/common/core/position';
1717
import { Range } from 'vs/editor/common/core/range';
1818
import { Selection } from 'vs/editor/common/core/selection';
19-
import { IIdentifiedSingleEditOperation, ISingleEditOperation, ITextModel } from 'vs/editor/common/model';
20-
import { CodeAction } from 'vs/editor/common/modes';
19+
import { IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/model';
20+
import { CodeAction, TextEdit } from 'vs/editor/common/modes';
2121
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
2222
import { shouldSynchronizeModel } from 'vs/editor/common/services/modelService';
2323
import { getCodeActions } from 'vs/editor/contrib/codeAction/codeAction';
@@ -234,7 +234,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
234234

235235
const timeout = this._configurationService.getValue<number>('editor.formatOnSaveTimeout', { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() });
236236

237-
return new Promise<ISingleEditOperation[] | null | undefined>((resolve, reject) => {
237+
return new Promise<TextEdit[] | null | undefined>((resolve, reject) => {
238238
let source = new CancellationTokenSource();
239239
let request = getDocumentFormattingEdits(this._telemetryService, this._editorWorkerService, model, model.getFormattingOptions(), FormatMode.Auto, source.token);
240240

@@ -257,11 +257,11 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
257257
});
258258
}
259259

260-
private _editsWithEditor(editor: ICodeEditor, edits: ISingleEditOperation[]): void {
260+
private _editsWithEditor(editor: ICodeEditor, edits: TextEdit[]): void {
261261
FormattingEdit.execute(editor, edits);
262262
}
263263

264-
private _editWithModel(model: ITextModel, edits: ISingleEditOperation[]): void {
264+
private _editWithModel(model: ITextModel, edits: TextEdit[]): void {
265265

266266
const [{ range }] = edits;
267267
const initialSelection = new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn);
@@ -276,7 +276,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
276276
});
277277
}
278278

279-
private static _asIdentEdit({ text, range }: ISingleEditOperation): IIdentifiedSingleEditOperation {
279+
private static _asIdentEdit({ text, range }: TextEdit): IIdentifiedSingleEditOperation {
280280
return {
281281
text,
282282
range: Range.lift(range),

src/vs/workbench/api/node/extHostDocumentsAndEditors.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
1717

1818
private _disposables: Disposable[] = [];
1919

20-
private _activeEditorId: string;
20+
private _activeEditorId: string | null;
2121

2222
private readonly _editors = new Map<string, ExtHostTextEditor>();
2323
private readonly _documents = new Map<string, ExtHostDocumentData>();
2424

2525
private readonly _onDidAddDocuments = new Emitter<ExtHostDocumentData[]>();
2626
private readonly _onDidRemoveDocuments = new Emitter<ExtHostDocumentData[]>();
2727
private readonly _onDidChangeVisibleTextEditors = new Emitter<ExtHostTextEditor[]>();
28-
private readonly _onDidChangeActiveTextEditor = new Emitter<ExtHostTextEditor>();
28+
private readonly _onDidChangeActiveTextEditor = new Emitter<ExtHostTextEditor | undefined>();
2929

3030
readonly onDidAddDocuments: Event<ExtHostDocumentData[]> = this._onDidAddDocuments.event;
3131
readonly onDidRemoveDocuments: Event<ExtHostDocumentData[]> = this._onDidRemoveDocuments.event;
3232
readonly onDidChangeVisibleTextEditors: Event<ExtHostTextEditor[]> = this._onDidChangeVisibleTextEditors.event;
33-
readonly onDidChangeActiveTextEditor: Event<ExtHostTextEditor> = this._onDidChangeActiveTextEditor.event;
33+
readonly onDidChangeActiveTextEditor: Event<ExtHostTextEditor | undefined> = this._onDidChangeActiveTextEditor.event;
3434

3535
constructor(
3636
private readonly _mainContext: IMainContext,
@@ -93,14 +93,14 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
9393
assert.ok(this._documents.has(resource.toString()), `document '${resource}' does not exist`);
9494
assert.ok(!this._editors.has(data.id), `editor '${data.id}' already exists!`);
9595

96-
const documentData = this._documents.get(resource.toString());
96+
const documentData = this._documents.get(resource.toString())!;
9797
const editor = new ExtHostTextEditor(
9898
this._mainContext.getProxy(MainContext.MainThreadTextEditors),
9999
data.id,
100100
documentData,
101101
data.selections.map(typeConverters.Selection.to),
102102
data.options,
103-
data.visibleRanges.map(typeConverters.Range.to),
103+
data.visibleRanges.map(range => typeConverters.Range.to(range)),
104104
typeof data.editorPosition === 'number' ? typeConverters.ViewColumn.to(data.editorPosition) : undefined
105105
);
106106
this._editors.set(data.id, editor);
@@ -131,7 +131,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
131131
}
132132
}
133133

134-
getDocument(uri: URI): ExtHostDocumentData {
134+
getDocument(uri: URI): ExtHostDocumentData | undefined {
135135
return this._documents.get(uri.toString());
136136
}
137137

@@ -141,7 +141,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
141141
return result;
142142
}
143143

144-
getEditor(id: string): ExtHostTextEditor {
144+
getEditor(id: string): ExtHostTextEditor | undefined {
145145
return this._editors.get(id);
146146
}
147147

src/vs/workbench/api/node/extHostTextEditor.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class TextEditorDecorationType implements vscode.TextEditorDecorationType
3535

3636
export interface ITextEditOperation {
3737
range: vscode.Range;
38-
text: string;
38+
text: string | null;
3939
forceMoveMarkers: boolean;
4040
}
4141

@@ -105,7 +105,7 @@ export class TextEditorEdit {
105105
this._pushEdit(range, null, true);
106106
}
107107

108-
private _pushEdit(range: Range, text: string, forceMoveMarkers: boolean): void {
108+
private _pushEdit(range: Range, text: string | null, forceMoveMarkers: boolean): void {
109109
let validRange = this._document.validateRange(range);
110110
this._collectedEdits.push({
111111
range: validRange,
@@ -373,7 +373,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
373373
private _selections: Selection[];
374374
private _options: ExtHostTextEditorOptions;
375375
private _visibleRanges: Range[];
376-
private _viewColumn: vscode.ViewColumn;
376+
private _viewColumn: vscode.ViewColumn | undefined;
377377
private _disposed: boolean = false;
378378
private _hasDecorationsForKey: { [key: string]: boolean; };
379379

@@ -382,7 +382,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
382382
constructor(
383383
proxy: MainThreadTextEditorsShape, id: string, document: ExtHostDocumentData,
384384
selections: Selection[], options: IResolvedTextEditorConfiguration,
385-
visibleRanges: Range[], viewColumn: vscode.ViewColumn
385+
visibleRanges: Range[], viewColumn: vscode.ViewColumn | undefined
386386
) {
387387
this._proxy = proxy;
388388
this._id = id;
@@ -451,7 +451,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
451451

452452
// ---- view column
453453

454-
get viewColumn(): vscode.ViewColumn {
454+
get viewColumn(): vscode.ViewColumn | undefined {
455455
return this._viewColumn;
456456
}
457457

@@ -538,7 +538,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
538538
);
539539
}
540540

541-
private _trySetSelection(): Promise<vscode.TextEditor> {
541+
private _trySetSelection(): Promise<vscode.TextEditor | null | undefined> {
542542
let selection = this._selections.map(TypeConverters.Selection.from);
543543
return this._runOnProxy(() => this._proxy.$trySetSelections(this._id, selection));
544544
}
@@ -598,7 +598,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
598598
}
599599

600600
// prepare data for serialization
601-
let edits: ISingleEditOperation[] = editData.edits.map((edit) => {
601+
const edits = editData.edits.map((edit): ISingleEditOperation => {
602602
return {
603603
range: TypeConverters.Range.from(edit.range),
604604
text: edit.text,
@@ -620,7 +620,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
620620
let ranges: IRange[];
621621

622622
if (!where || (Array.isArray(where) && where.length === 0)) {
623-
ranges = this._selections.map(TypeConverters.Range.from);
623+
ranges = this._selections.map(range => TypeConverters.Range.from(range));
624624

625625
} else if (where instanceof Position) {
626626
const { lineNumber, column } = TypeConverters.Position.from(where);
@@ -645,7 +645,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
645645

646646
// ---- util
647647

648-
private _runOnProxy(callback: () => Promise<any>): Promise<ExtHostTextEditor> {
648+
private _runOnProxy(callback: () => Promise<any>): Promise<ExtHostTextEditor | undefined | null> {
649649
if (this._disposed) {
650650
console.warn('TextEditor is closed/disposed');
651651
return Promise.resolve(undefined);

0 commit comments

Comments
 (0)