提交 480b838e 编写于 作者: M Matt Bierner

Strict null check apiCommands

上级 e3964c95
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
"./vs/workbench/api/electron-browser/mainThreadUrls.ts", "./vs/workbench/api/electron-browser/mainThreadUrls.ts",
"./vs/workbench/api/electron-browser/mainThreadWindow.ts", "./vs/workbench/api/electron-browser/mainThreadWindow.ts",
"./vs/workbench/api/electron-browser/mainThreadWorkspace.ts", "./vs/workbench/api/electron-browser/mainThreadWorkspace.ts",
"./vs/workbench/api/node/apiCommands.ts",
"./vs/workbench/api/node/extHost.protocol.ts", "./vs/workbench/api/node/extHost.protocol.ts",
"./vs/workbench/api/node/extHostClipboard.ts", "./vs/workbench/api/node/extHostClipboard.ts",
"./vs/workbench/api/node/extHostConfiguration.ts", "./vs/workbench/api/node/extHostConfiguration.ts",
......
...@@ -24,14 +24,14 @@ export class EditOperation { ...@@ -24,14 +24,14 @@ export class EditOperation {
}; };
} }
public static replace(range: Range, text: string): IIdentifiedSingleEditOperation { public static replace(range: Range, text: string | null): IIdentifiedSingleEditOperation {
return { return {
range: range, range: range,
text: text text: text
}; };
} }
public static replaceMove(range: Range, text: string): IIdentifiedSingleEditOperation { public static replaceMove(range: Range, text: string | null): IIdentifiedSingleEditOperation {
return { return {
range: range, range: range,
text: text, text: text,
......
...@@ -289,7 +289,7 @@ export interface ISingleEditOperation { ...@@ -289,7 +289,7 @@ export interface ISingleEditOperation {
/** /**
* The text to replace with. This can be null to emulate a simple delete. * The text to replace with. This can be null to emulate a simple delete.
*/ */
text: string; text: string | null;
/** /**
* This indicates that this operation has "insert" semantics. * This indicates that this operation has "insert" semantics.
* i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved. * i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved.
......
...@@ -45,7 +45,7 @@ export class FormattingEdit { ...@@ -45,7 +45,7 @@ export class FormattingEdit {
static execute(editor: ICodeEditor, _edits: TextEdit[]) { static execute(editor: ICodeEditor, _edits: TextEdit[]) {
editor.pushUndoStop(); editor.pushUndoStop();
let edits = FormattingEdit._handleEolEdits(editor, _edits); const edits = FormattingEdit._handleEolEdits(editor, _edits);
if (edits.length === 1 && FormattingEdit._isFullModelReplaceEdit(editor, edits[0])) { if (edits.length === 1 && FormattingEdit._isFullModelReplaceEdit(editor, edits[0])) {
// We use replace semantics and hope that markers stay put... // We use replace semantics and hope that markers stay put...
editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replace(Range.lift(edit.range), edit.text))); editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replace(Range.lift(edit.range), edit.text)));
......
...@@ -1387,7 +1387,7 @@ declare namespace monaco.editor { ...@@ -1387,7 +1387,7 @@ declare namespace monaco.editor {
/** /**
* The text to replace with. This can be null to emulate a simple delete. * The text to replace with. This can be null to emulate a simple delete.
*/ */
text: string; text: string | null;
/** /**
* This indicates that this operation has "insert" semantics. * This indicates that this operation has "insert" semantics.
* i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved. * i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved.
......
...@@ -16,8 +16,8 @@ import { EditOperation } from 'vs/editor/common/core/editOperation'; ...@@ -16,8 +16,8 @@ import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range'; import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection'; import { Selection } from 'vs/editor/common/core/selection';
import { IIdentifiedSingleEditOperation, ISingleEditOperation, ITextModel } from 'vs/editor/common/model'; import { IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/model';
import { CodeAction } from 'vs/editor/common/modes'; import { CodeAction, TextEdit } from 'vs/editor/common/modes';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { shouldSynchronizeModel } from 'vs/editor/common/services/modelService'; import { shouldSynchronizeModel } from 'vs/editor/common/services/modelService';
import { getCodeActions } from 'vs/editor/contrib/codeAction/codeAction'; import { getCodeActions } from 'vs/editor/contrib/codeAction/codeAction';
...@@ -234,7 +234,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant { ...@@ -234,7 +234,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
const timeout = this._configurationService.getValue<number>('editor.formatOnSaveTimeout', { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() }); const timeout = this._configurationService.getValue<number>('editor.formatOnSaveTimeout', { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() });
return new Promise<ISingleEditOperation[] | null | undefined>((resolve, reject) => { return new Promise<TextEdit[] | null | undefined>((resolve, reject) => {
let source = new CancellationTokenSource(); let source = new CancellationTokenSource();
let request = getDocumentFormattingEdits(this._telemetryService, this._editorWorkerService, model, model.getFormattingOptions(), FormatMode.Auto, source.token); let request = getDocumentFormattingEdits(this._telemetryService, this._editorWorkerService, model, model.getFormattingOptions(), FormatMode.Auto, source.token);
...@@ -257,11 +257,11 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant { ...@@ -257,11 +257,11 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
}); });
} }
private _editsWithEditor(editor: ICodeEditor, edits: ISingleEditOperation[]): void { private _editsWithEditor(editor: ICodeEditor, edits: TextEdit[]): void {
FormattingEdit.execute(editor, edits); FormattingEdit.execute(editor, edits);
} }
private _editWithModel(model: ITextModel, edits: ISingleEditOperation[]): void { private _editWithModel(model: ITextModel, edits: TextEdit[]): void {
const [{ range }] = edits; const [{ range }] = edits;
const initialSelection = new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn); const initialSelection = new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn);
...@@ -276,7 +276,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant { ...@@ -276,7 +276,7 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
}); });
} }
private static _asIdentEdit({ text, range }: ISingleEditOperation): IIdentifiedSingleEditOperation { private static _asIdentEdit({ text, range }: TextEdit): IIdentifiedSingleEditOperation {
return { return {
text, text,
range: Range.lift(range), range: Range.lift(range),
......
...@@ -17,7 +17,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha ...@@ -17,7 +17,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
private _disposables: Disposable[] = []; private _disposables: Disposable[] = [];
private _activeEditorId: string; private _activeEditorId: string | null;
private readonly _editors = new Map<string, ExtHostTextEditor>(); private readonly _editors = new Map<string, ExtHostTextEditor>();
private readonly _documents = new Map<string, ExtHostDocumentData>(); private readonly _documents = new Map<string, ExtHostDocumentData>();
...@@ -25,12 +25,12 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha ...@@ -25,12 +25,12 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
private readonly _onDidAddDocuments = new Emitter<ExtHostDocumentData[]>(); private readonly _onDidAddDocuments = new Emitter<ExtHostDocumentData[]>();
private readonly _onDidRemoveDocuments = new Emitter<ExtHostDocumentData[]>(); private readonly _onDidRemoveDocuments = new Emitter<ExtHostDocumentData[]>();
private readonly _onDidChangeVisibleTextEditors = new Emitter<ExtHostTextEditor[]>(); private readonly _onDidChangeVisibleTextEditors = new Emitter<ExtHostTextEditor[]>();
private readonly _onDidChangeActiveTextEditor = new Emitter<ExtHostTextEditor>(); private readonly _onDidChangeActiveTextEditor = new Emitter<ExtHostTextEditor | undefined>();
readonly onDidAddDocuments: Event<ExtHostDocumentData[]> = this._onDidAddDocuments.event; readonly onDidAddDocuments: Event<ExtHostDocumentData[]> = this._onDidAddDocuments.event;
readonly onDidRemoveDocuments: Event<ExtHostDocumentData[]> = this._onDidRemoveDocuments.event; readonly onDidRemoveDocuments: Event<ExtHostDocumentData[]> = this._onDidRemoveDocuments.event;
readonly onDidChangeVisibleTextEditors: Event<ExtHostTextEditor[]> = this._onDidChangeVisibleTextEditors.event; readonly onDidChangeVisibleTextEditors: Event<ExtHostTextEditor[]> = this._onDidChangeVisibleTextEditors.event;
readonly onDidChangeActiveTextEditor: Event<ExtHostTextEditor> = this._onDidChangeActiveTextEditor.event; readonly onDidChangeActiveTextEditor: Event<ExtHostTextEditor | undefined> = this._onDidChangeActiveTextEditor.event;
constructor( constructor(
private readonly _mainContext: IMainContext, private readonly _mainContext: IMainContext,
...@@ -93,14 +93,14 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha ...@@ -93,14 +93,14 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
assert.ok(this._documents.has(resource.toString()), `document '${resource}' does not exist`); assert.ok(this._documents.has(resource.toString()), `document '${resource}' does not exist`);
assert.ok(!this._editors.has(data.id), `editor '${data.id}' already exists!`); assert.ok(!this._editors.has(data.id), `editor '${data.id}' already exists!`);
const documentData = this._documents.get(resource.toString()); const documentData = this._documents.get(resource.toString())!;
const editor = new ExtHostTextEditor( const editor = new ExtHostTextEditor(
this._mainContext.getProxy(MainContext.MainThreadTextEditors), this._mainContext.getProxy(MainContext.MainThreadTextEditors),
data.id, data.id,
documentData, documentData,
data.selections.map(typeConverters.Selection.to), data.selections.map(typeConverters.Selection.to),
data.options, data.options,
data.visibleRanges.map(typeConverters.Range.to), data.visibleRanges.map(range => typeConverters.Range.to(range)),
typeof data.editorPosition === 'number' ? typeConverters.ViewColumn.to(data.editorPosition) : undefined typeof data.editorPosition === 'number' ? typeConverters.ViewColumn.to(data.editorPosition) : undefined
); );
this._editors.set(data.id, editor); this._editors.set(data.id, editor);
...@@ -131,7 +131,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha ...@@ -131,7 +131,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
} }
} }
getDocument(uri: URI): ExtHostDocumentData { getDocument(uri: URI): ExtHostDocumentData | undefined {
return this._documents.get(uri.toString()); return this._documents.get(uri.toString());
} }
...@@ -141,7 +141,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha ...@@ -141,7 +141,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
return result; return result;
} }
getEditor(id: string): ExtHostTextEditor { getEditor(id: string): ExtHostTextEditor | undefined {
return this._editors.get(id); return this._editors.get(id);
} }
......
...@@ -35,7 +35,7 @@ export class TextEditorDecorationType implements vscode.TextEditorDecorationType ...@@ -35,7 +35,7 @@ export class TextEditorDecorationType implements vscode.TextEditorDecorationType
export interface ITextEditOperation { export interface ITextEditOperation {
range: vscode.Range; range: vscode.Range;
text: string; text: string | null;
forceMoveMarkers: boolean; forceMoveMarkers: boolean;
} }
...@@ -105,7 +105,7 @@ export class TextEditorEdit { ...@@ -105,7 +105,7 @@ export class TextEditorEdit {
this._pushEdit(range, null, true); this._pushEdit(range, null, true);
} }
private _pushEdit(range: Range, text: string, forceMoveMarkers: boolean): void { private _pushEdit(range: Range, text: string | null, forceMoveMarkers: boolean): void {
let validRange = this._document.validateRange(range); let validRange = this._document.validateRange(range);
this._collectedEdits.push({ this._collectedEdits.push({
range: validRange, range: validRange,
...@@ -373,7 +373,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { ...@@ -373,7 +373,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
private _selections: Selection[]; private _selections: Selection[];
private _options: ExtHostTextEditorOptions; private _options: ExtHostTextEditorOptions;
private _visibleRanges: Range[]; private _visibleRanges: Range[];
private _viewColumn: vscode.ViewColumn; private _viewColumn: vscode.ViewColumn | undefined;
private _disposed: boolean = false; private _disposed: boolean = false;
private _hasDecorationsForKey: { [key: string]: boolean; }; private _hasDecorationsForKey: { [key: string]: boolean; };
...@@ -382,7 +382,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { ...@@ -382,7 +382,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
constructor( constructor(
proxy: MainThreadTextEditorsShape, id: string, document: ExtHostDocumentData, proxy: MainThreadTextEditorsShape, id: string, document: ExtHostDocumentData,
selections: Selection[], options: IResolvedTextEditorConfiguration, selections: Selection[], options: IResolvedTextEditorConfiguration,
visibleRanges: Range[], viewColumn: vscode.ViewColumn visibleRanges: Range[], viewColumn: vscode.ViewColumn | undefined
) { ) {
this._proxy = proxy; this._proxy = proxy;
this._id = id; this._id = id;
...@@ -451,7 +451,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { ...@@ -451,7 +451,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
// ---- view column // ---- view column
get viewColumn(): vscode.ViewColumn { get viewColumn(): vscode.ViewColumn | undefined {
return this._viewColumn; return this._viewColumn;
} }
...@@ -538,7 +538,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { ...@@ -538,7 +538,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
); );
} }
private _trySetSelection(): Promise<vscode.TextEditor> { private _trySetSelection(): Promise<vscode.TextEditor | null | undefined> {
let selection = this._selections.map(TypeConverters.Selection.from); let selection = this._selections.map(TypeConverters.Selection.from);
return this._runOnProxy(() => this._proxy.$trySetSelections(this._id, selection)); return this._runOnProxy(() => this._proxy.$trySetSelections(this._id, selection));
} }
...@@ -598,7 +598,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { ...@@ -598,7 +598,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
} }
// prepare data for serialization // prepare data for serialization
let edits: ISingleEditOperation[] = editData.edits.map((edit) => { const edits = editData.edits.map((edit): ISingleEditOperation => {
return { return {
range: TypeConverters.Range.from(edit.range), range: TypeConverters.Range.from(edit.range),
text: edit.text, text: edit.text,
...@@ -620,7 +620,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { ...@@ -620,7 +620,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
let ranges: IRange[]; let ranges: IRange[];
if (!where || (Array.isArray(where) && where.length === 0)) { if (!where || (Array.isArray(where) && where.length === 0)) {
ranges = this._selections.map(TypeConverters.Range.from); ranges = this._selections.map(range => TypeConverters.Range.from(range));
} else if (where instanceof Position) { } else if (where instanceof Position) {
const { lineNumber, column } = TypeConverters.Position.from(where); const { lineNumber, column } = TypeConverters.Position.from(where);
...@@ -645,7 +645,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { ...@@ -645,7 +645,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
// ---- util // ---- util
private _runOnProxy(callback: () => Promise<any>): Promise<ExtHostTextEditor> { private _runOnProxy(callback: () => Promise<any>): Promise<ExtHostTextEditor | undefined | null> {
if (this._disposed) { if (this._disposed) {
console.warn('TextEditor is closed/disposed'); console.warn('TextEditor is closed/disposed');
return Promise.resolve(undefined); return Promise.resolve(undefined);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册