提交 b72fede4 编写于 作者: A Alex Dima

strict null checks (#60565)

上级 655682c0
...@@ -271,6 +271,7 @@ ...@@ -271,6 +271,7 @@
"./vs/editor/contrib/caretOperations/moveCaretCommand.ts", "./vs/editor/contrib/caretOperations/moveCaretCommand.ts",
"./vs/editor/contrib/caretOperations/transpose.ts", "./vs/editor/contrib/caretOperations/transpose.ts",
"./vs/editor/contrib/clipboard/clipboard.ts", "./vs/editor/contrib/clipboard/clipboard.ts",
"./vs/editor/contrib/codeAction/codeAction.ts",
"./vs/editor/contrib/codeAction/codeActionTrigger.ts", "./vs/editor/contrib/codeAction/codeActionTrigger.ts",
"./vs/editor/contrib/colorPicker/color.ts", "./vs/editor/contrib/colorPicker/color.ts",
"./vs/editor/contrib/colorPicker/colorPickerModel.ts", "./vs/editor/contrib/colorPicker/colorPickerModel.ts",
...@@ -300,6 +301,7 @@ ...@@ -300,6 +301,7 @@
"./vs/editor/contrib/folding/test/foldingModel.test.ts", "./vs/editor/contrib/folding/test/foldingModel.test.ts",
"./vs/editor/contrib/fontZoom/fontZoom.ts", "./vs/editor/contrib/fontZoom/fontZoom.ts",
"./vs/editor/contrib/goToDefinition/clickLinkGesture.ts", "./vs/editor/contrib/goToDefinition/clickLinkGesture.ts",
"./vs/editor/contrib/goToDefinition/goToDefinition.ts",
"./vs/editor/contrib/hover/getHover.ts", "./vs/editor/contrib/hover/getHover.ts",
"./vs/editor/contrib/hover/hoverOperation.ts", "./vs/editor/contrib/hover/hoverOperation.ts",
"./vs/editor/contrib/hover/hoverWidgets.ts", "./vs/editor/contrib/hover/hoverWidgets.ts",
...@@ -310,6 +312,8 @@ ...@@ -310,6 +312,8 @@
"./vs/editor/contrib/linesOperations/sortLinesCommand.ts", "./vs/editor/contrib/linesOperations/sortLinesCommand.ts",
"./vs/editor/contrib/links/getLinks.ts", "./vs/editor/contrib/links/getLinks.ts",
"./vs/editor/contrib/links/links.ts", "./vs/editor/contrib/links/links.ts",
"./vs/editor/contrib/message/messageController.ts",
"./vs/editor/contrib/parameterHints/provideSignatureHelp.ts",
"./vs/editor/contrib/quickOpen/quickOpen.ts", "./vs/editor/contrib/quickOpen/quickOpen.ts",
"./vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode.ts", "./vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode.ts",
"./vs/editor/contrib/wordHighlighter/wordHighlighter.ts", "./vs/editor/contrib/wordHighlighter/wordHighlighter.ts",
...@@ -327,12 +331,16 @@ ...@@ -327,12 +331,16 @@
"./vs/editor/standalone/common/monarch/monarchTypes.ts", "./vs/editor/standalone/common/monarch/monarchTypes.ts",
"./vs/editor/standalone/common/standaloneThemeService.ts", "./vs/editor/standalone/common/standaloneThemeService.ts",
"./vs/editor/standalone/common/themes.ts", "./vs/editor/standalone/common/themes.ts",
"./vs/editor/test/browser/controller/imeTester.ts",
"./vs/editor/test/browser/editorTestServices.ts",
"./vs/editor/test/browser/view/minimapFontCreator.ts",
"./vs/editor/test/common/commentMode.ts", "./vs/editor/test/common/commentMode.ts",
"./vs/editor/test/common/core/viewLineToken.ts", "./vs/editor/test/common/core/viewLineToken.ts",
"./vs/editor/test/common/editorTestUtils.ts", "./vs/editor/test/common/editorTestUtils.ts",
"./vs/editor/test/common/mocks/mockMode.ts", "./vs/editor/test/common/mocks/mockMode.ts",
"./vs/editor/test/common/mocks/testConfiguration.ts", "./vs/editor/test/common/mocks/testConfiguration.ts",
"./vs/editor/test/common/model/benchmark/benchmarkUtils.ts", "./vs/editor/test/common/model/benchmark/benchmarkUtils.ts",
"./vs/editor/test/common/model/editableTextModelTestUtils.ts",
"./vs/editor/test/common/modes/supports/javascriptOnEnterRules.ts", "./vs/editor/test/common/modes/supports/javascriptOnEnterRules.ts",
"./vs/editor/test/common/modesTestUtils.ts", "./vs/editor/test/common/modesTestUtils.ts",
"./vs/editor/test/common/view/minimapCharRendererFactory.ts", "./vs/editor/test/common/view/minimapCharRendererFactory.ts",
...@@ -465,6 +473,7 @@ ...@@ -465,6 +473,7 @@
"./vs/workbench/services/keybinding/common/macLinuxFallbackKeyboardMapper.ts", "./vs/workbench/services/keybinding/common/macLinuxFallbackKeyboardMapper.ts",
"./vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts", "./vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts",
"./vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts", "./vs/workbench/services/keybinding/common/windowsKeyboardMapper.ts",
"./vs/workbench/services/mode/common/workbenchModeService.ts",
"./vs/workbench/services/panel/common/panelService.ts", "./vs/workbench/services/panel/common/panelService.ts",
"./vs/workbench/services/scm/common/scm.ts", "./vs/workbench/services/scm/common/scm.ts",
"./vs/workbench/services/scm/common/scmService.ts", "./vs/workbench/services/scm/common/scmService.ts",
......
...@@ -299,6 +299,10 @@ export interface IMouseTarget { ...@@ -299,6 +299,10 @@ export interface IMouseTarget {
* A mouse event originating from the editor. * A mouse event originating from the editor.
*/ */
export interface IEditorMouseEvent { export interface IEditorMouseEvent {
readonly event: IMouseEvent;
readonly target: IMouseTarget;
}
export interface IPartialEditorMouseEvent {
readonly event: IMouseEvent; readonly event: IMouseEvent;
readonly target: IMouseTarget | null; readonly target: IMouseTarget | null;
} }
...@@ -441,7 +445,7 @@ export interface ICodeEditor extends editorCommon.IEditor { ...@@ -441,7 +445,7 @@ export interface ICodeEditor extends editorCommon.IEditor {
* @internal * @internal
* @event * @event
*/ */
onMouseDrop(listener: (e: IEditorMouseEvent) => void): IDisposable; onMouseDrop(listener: (e: IPartialEditorMouseEvent) => void): IDisposable;
/** /**
* An event emitted on a "contextmenu". * An event emitted on a "contextmenu".
* @event * @event
...@@ -456,7 +460,7 @@ export interface ICodeEditor extends editorCommon.IEditor { ...@@ -456,7 +460,7 @@ export interface ICodeEditor extends editorCommon.IEditor {
* An event emitted on a "mouseleave". * An event emitted on a "mouseleave".
* @event * @event
*/ */
onMouseLeave(listener: (e: IEditorMouseEvent) => void): IDisposable; onMouseLeave(listener: (e: IPartialEditorMouseEvent) => void): IDisposable;
/** /**
* An event emitted on a "keyup". * An event emitted on a "keyup".
* @event * @event
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
import { Selection } from 'vs/editor/common/core/selection'; import { Selection } from 'vs/editor/common/core/selection';
import { IEditorMouseEvent } from 'vs/editor/browser/editorBrowser'; import { IEditorMouseEvent, IPartialEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents'; import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents';
import { CoreNavigationCommands, CoreEditorCommand } from 'vs/editor/browser/controller/coreCommands'; import { CoreNavigationCommands, CoreEditorCommand } from 'vs/editor/browser/controller/coreCommands';
...@@ -293,7 +293,7 @@ export class ViewController { ...@@ -293,7 +293,7 @@ export class ViewController {
this.outgoingEvents.emitMouseMove(e); this.outgoingEvents.emitMouseMove(e);
} }
public emitMouseLeave(e: IEditorMouseEvent): void { public emitMouseLeave(e: IPartialEditorMouseEvent): void {
this.outgoingEvents.emitMouseLeave(e); this.outgoingEvents.emitMouseLeave(e);
} }
...@@ -309,7 +309,7 @@ export class ViewController { ...@@ -309,7 +309,7 @@ export class ViewController {
this.outgoingEvents.emitMouseDrag(e); this.outgoingEvents.emitMouseDrag(e);
} }
public emitMouseDrop(e: IEditorMouseEvent): void { public emitMouseDrop(e: IPartialEditorMouseEvent): void {
this.outgoingEvents.emitMouseDrop(e); this.outgoingEvents.emitMouseDrop(e);
} }
} }
...@@ -9,7 +9,7 @@ import { Position } from 'vs/editor/common/core/position'; ...@@ -9,7 +9,7 @@ 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 { IViewModel } from 'vs/editor/common/viewModel/viewModel'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
import { IScrollEvent } from 'vs/editor/common/editorCommon'; import { IScrollEvent } from 'vs/editor/common/editorCommon';
import { IEditorMouseEvent, IMouseTarget, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { IEditorMouseEvent, IMouseTarget, MouseTargetType, IPartialEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
import { MouseTarget } from 'vs/editor/browser/controller/mouseTarget'; import { MouseTarget } from 'vs/editor/browser/controller/mouseTarget';
import * as viewEvents from 'vs/editor/common/view/viewEvents'; import * as viewEvents from 'vs/editor/common/view/viewEvents';
...@@ -26,11 +26,11 @@ export class ViewOutgoingEvents extends Disposable { ...@@ -26,11 +26,11 @@ export class ViewOutgoingEvents extends Disposable {
public onKeyUp: EventCallback<IKeyboardEvent> | null = null; public onKeyUp: EventCallback<IKeyboardEvent> | null = null;
public onContextMenu: EventCallback<IEditorMouseEvent> | null = null; public onContextMenu: EventCallback<IEditorMouseEvent> | null = null;
public onMouseMove: EventCallback<IEditorMouseEvent> | null = null; public onMouseMove: EventCallback<IEditorMouseEvent> | null = null;
public onMouseLeave: EventCallback<IEditorMouseEvent> | null = null; public onMouseLeave: EventCallback<IPartialEditorMouseEvent> | null = null;
public onMouseUp: EventCallback<IEditorMouseEvent> | null = null; public onMouseUp: EventCallback<IEditorMouseEvent> | null = null;
public onMouseDown: EventCallback<IEditorMouseEvent> | null = null; public onMouseDown: EventCallback<IEditorMouseEvent> | null = null;
public onMouseDrag: EventCallback<IEditorMouseEvent> | null = null; public onMouseDrag: EventCallback<IEditorMouseEvent> | null = null;
public onMouseDrop: EventCallback<IEditorMouseEvent> | null = null; public onMouseDrop: EventCallback<IPartialEditorMouseEvent> | null = null;
private _viewModel: IViewModel; private _viewModel: IViewModel;
...@@ -81,7 +81,7 @@ export class ViewOutgoingEvents extends Disposable { ...@@ -81,7 +81,7 @@ export class ViewOutgoingEvents extends Disposable {
} }
} }
public emitMouseLeave(e: IEditorMouseEvent): void { public emitMouseLeave(e: IPartialEditorMouseEvent): void {
if (this.onMouseLeave) { if (this.onMouseLeave) {
this.onMouseLeave(this._convertViewToModelMouseEvent(e)); this.onMouseLeave(this._convertViewToModelMouseEvent(e));
} }
...@@ -105,13 +105,15 @@ export class ViewOutgoingEvents extends Disposable { ...@@ -105,13 +105,15 @@ export class ViewOutgoingEvents extends Disposable {
} }
} }
public emitMouseDrop(e: IEditorMouseEvent): void { public emitMouseDrop(e: IPartialEditorMouseEvent): void {
if (this.onMouseDrop) { if (this.onMouseDrop) {
this.onMouseDrop(this._convertViewToModelMouseEvent(e)); this.onMouseDrop(this._convertViewToModelMouseEvent(e));
} }
} }
private _convertViewToModelMouseEvent(e: IEditorMouseEvent): IEditorMouseEvent { private _convertViewToModelMouseEvent(e: IEditorMouseEvent): IEditorMouseEvent;
private _convertViewToModelMouseEvent(e: IPartialEditorMouseEvent): IPartialEditorMouseEvent;
private _convertViewToModelMouseEvent(e: IEditorMouseEvent | IPartialEditorMouseEvent): IEditorMouseEvent | IPartialEditorMouseEvent {
if (e.target) { if (e.target) {
return { return {
event: e.event, event: e.event,
......
...@@ -173,8 +173,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE ...@@ -173,8 +173,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
private readonly _onMouseDrag: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>()); private readonly _onMouseDrag: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>());
public readonly onMouseDrag: Event<editorBrowser.IEditorMouseEvent> = this._onMouseDrag.event; public readonly onMouseDrag: Event<editorBrowser.IEditorMouseEvent> = this._onMouseDrag.event;
private readonly _onMouseDrop: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>()); private readonly _onMouseDrop: Emitter<editorBrowser.IPartialEditorMouseEvent> = this._register(new Emitter<editorBrowser.IPartialEditorMouseEvent>());
public readonly onMouseDrop: Event<editorBrowser.IEditorMouseEvent> = this._onMouseDrop.event; public readonly onMouseDrop: Event<editorBrowser.IPartialEditorMouseEvent> = this._onMouseDrop.event;
private readonly _onContextMenu: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>()); private readonly _onContextMenu: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>());
public readonly onContextMenu: Event<editorBrowser.IEditorMouseEvent> = this._onContextMenu.event; public readonly onContextMenu: Event<editorBrowser.IEditorMouseEvent> = this._onContextMenu.event;
...@@ -182,8 +182,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE ...@@ -182,8 +182,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
private readonly _onMouseMove: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>()); private readonly _onMouseMove: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>());
public readonly onMouseMove: Event<editorBrowser.IEditorMouseEvent> = this._onMouseMove.event; public readonly onMouseMove: Event<editorBrowser.IEditorMouseEvent> = this._onMouseMove.event;
private readonly _onMouseLeave: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>()); private readonly _onMouseLeave: Emitter<editorBrowser.IPartialEditorMouseEvent> = this._register(new Emitter<editorBrowser.IPartialEditorMouseEvent>());
public readonly onMouseLeave: Event<editorBrowser.IEditorMouseEvent> = this._onMouseLeave.event; public readonly onMouseLeave: Event<editorBrowser.IPartialEditorMouseEvent> = this._onMouseLeave.event;
private readonly _onKeyUp: Emitter<IKeyboardEvent> = this._register(new Emitter<IKeyboardEvent>()); private readonly _onKeyUp: Emitter<IKeyboardEvent> = this._register(new Emitter<IKeyboardEvent>());
public readonly onKeyUp: Event<IKeyboardEvent> = this._onKeyUp.event; public readonly onKeyUp: Event<IKeyboardEvent> = this._onKeyUp.event;
......
...@@ -70,7 +70,7 @@ function codeActionsComparator(a: CodeAction, b: CodeAction): number { ...@@ -70,7 +70,7 @@ function codeActionsComparator(a: CodeAction, b: CodeAction): number {
const bHasDiags = !isFalsyOrEmpty(b.diagnostics); const bHasDiags = !isFalsyOrEmpty(b.diagnostics);
if (aHasDiags) { if (aHasDiags) {
if (bHasDiags) { if (bHasDiags) {
return a.diagnostics[0].message.localeCompare(b.diagnostics[0].message); return a.diagnostics![0].message.localeCompare(b.diagnostics![0].message);
} else { } else {
return -1; return -1;
} }
......
...@@ -22,7 +22,7 @@ function hasModifier(e: { ctrlKey: boolean; shiftKey: boolean; altKey: boolean; ...@@ -22,7 +22,7 @@ function hasModifier(e: { ctrlKey: boolean; shiftKey: boolean; altKey: boolean;
*/ */
export class ClickLinkMouseEvent { export class ClickLinkMouseEvent {
public readonly target: IMouseTarget | null; public readonly target: IMouseTarget;
public readonly hasTriggerModifier: boolean; public readonly hasTriggerModifier: boolean;
public readonly hasSideBySideModifier: boolean; public readonly hasSideBySideModifier: boolean;
public readonly isNoneOrSingleMouseDown: boolean; public readonly isNoneOrSingleMouseDown: boolean;
......
...@@ -17,12 +17,12 @@ function getDefinitions<T>( ...@@ -17,12 +17,12 @@ function getDefinitions<T>(
model: ITextModel, model: ITextModel,
position: Position, position: Position,
registry: LanguageFeatureRegistry<T>, registry: LanguageFeatureRegistry<T>,
provide: (provider: T, model: ITextModel, position: Position) => DefinitionLink | DefinitionLink[] | Thenable<DefinitionLink | DefinitionLink[]> provide: (provider: T, model: ITextModel, position: Position) => DefinitionLink | DefinitionLink[] | null | undefined | Thenable<DefinitionLink | DefinitionLink[] | null | undefined>
): Thenable<DefinitionLink[]> { ): Thenable<DefinitionLink[]> {
const provider = registry.ordered(model); const provider = registry.ordered(model);
// get results // get results
const promises = provider.map((provider): Thenable<DefinitionLink | DefinitionLink[]> => { const promises = provider.map((provider): Thenable<DefinitionLink | DefinitionLink[] | null | undefined> => {
return Promise.resolve(provide(provider, model, position)).then(undefined, err => { return Promise.resolve(provide(provider, model, position)).then(undefined, err => {
onUnexpectedExternalError(err); onUnexpectedExternalError(err);
return null; return null;
......
...@@ -289,7 +289,7 @@ class LinkDetector implements editorCommon.IEditorContribution { ...@@ -289,7 +289,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
const useMetaKey = (this.editor.getConfiguration().multiCursorModifier === 'altKey'); const useMetaKey = (this.editor.getConfiguration().multiCursorModifier === 'altKey');
if (this.isEnabled(mouseEvent, withKey)) { if (this.isEnabled(mouseEvent, withKey)) {
this.cleanUpActiveLinkDecoration(); // always remove previous link decoration as their can only be one this.cleanUpActiveLinkDecoration(); // always remove previous link decoration as their can only be one
const occurrence = this.getLinkOccurrence(mouseEvent.target!.position); const occurrence = this.getLinkOccurrence(mouseEvent.target.position);
if (occurrence) { if (occurrence) {
this.editor.changeDecorations((changeAccessor) => { this.editor.changeDecorations((changeAccessor) => {
occurrence.activate(changeAccessor, useMetaKey); occurrence.activate(changeAccessor, useMetaKey);
...@@ -319,7 +319,7 @@ class LinkDetector implements editorCommon.IEditorContribution { ...@@ -319,7 +319,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
if (!this.isEnabled(mouseEvent)) { if (!this.isEnabled(mouseEvent)) {
return; return;
} }
const occurrence = this.getLinkOccurrence(mouseEvent.target!.position); const occurrence = this.getLinkOccurrence(mouseEvent.target.position);
if (!occurrence) { if (!occurrence) {
return; return;
} }
...@@ -374,7 +374,7 @@ class LinkDetector implements editorCommon.IEditorContribution { ...@@ -374,7 +374,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
private isEnabled(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent | null): boolean { private isEnabled(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent | null): boolean {
return Boolean( return Boolean(
(mouseEvent.target && mouseEvent.target.type === MouseTargetType.CONTENT_TEXT) (mouseEvent.target.type === MouseTargetType.CONTENT_TEXT)
&& (mouseEvent.hasTriggerModifier || (withKey && withKey.keyCodeIsTriggerKey)) && (mouseEvent.hasTriggerModifier || (withKey && withKey.keyCodeIsTriggerKey))
); );
} }
......
...@@ -100,7 +100,9 @@ export class MessageController extends Disposable implements editorCommon.IEdito ...@@ -100,7 +100,9 @@ export class MessageController extends Disposable implements editorCommon.IEdito
} }
private _onDidAttemptReadOnlyEdit(): void { private _onDidAttemptReadOnlyEdit(): void {
this.showMessage(nls.localize('editor.readonly', "Cannot edit in read-only editor"), this._editor.getPosition()); if (this._editor.hasModel()) {
this.showMessage(nls.localize('editor.readonly', "Cannot edit in read-only editor"), this._editor.getPosition());
}
} }
} }
......
...@@ -17,7 +17,7 @@ export const Context = { ...@@ -17,7 +17,7 @@ export const Context = {
MultipleSignatures: new RawContextKey<boolean>('parameterHintsMultipleSignatures', false), MultipleSignatures: new RawContextKey<boolean>('parameterHintsMultipleSignatures', false),
}; };
export function provideSignatureHelp(model: ITextModel, position: Position, context: modes.SignatureHelpContext, token: CancellationToken): Promise<modes.SignatureHelp> { export function provideSignatureHelp(model: ITextModel, position: Position, context: modes.SignatureHelpContext, token: CancellationToken): Promise<modes.SignatureHelp | null | undefined> {
const supports = modes.SignatureHelpProviderRegistry.ordered(model); const supports = modes.SignatureHelpProviderRegistry.ordered(model);
......
...@@ -100,7 +100,7 @@ function doCreateTest(description: string, inputStr: string, expectedStr: string ...@@ -100,7 +100,7 @@ function doCreateTest(description: string, inputStr: string, expectedStr: string
return PagedScreenReaderStrategy.fromEditorSelection(currentState, model, selection, true); return PagedScreenReaderStrategy.fromEditorSelection(currentState, model, selection, true);
}, },
deduceModelPosition: (viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position => { deduceModelPosition: (viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position => {
return null; return null!;
} }
}; };
......
...@@ -15,14 +15,14 @@ import { IResourceInput } from 'vs/platform/editor/common/editor'; ...@@ -15,14 +15,14 @@ import { IResourceInput } from 'vs/platform/editor/common/editor';
export class TestCodeEditorService extends AbstractCodeEditorService { export class TestCodeEditorService extends AbstractCodeEditorService {
public lastInput: IResourceInput; public lastInput: IResourceInput;
public getActiveCodeEditor(): ICodeEditor { return null; } public getActiveCodeEditor(): ICodeEditor | null { return null; }
public openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): TPromise<ICodeEditor> { public openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): TPromise<ICodeEditor | null> {
this.lastInput = input; this.lastInput = input;
return TPromise.as(null); return TPromise.as(null);
} }
public registerDecorationType(key: string, options: IDecorationRenderOptions, parentTypeKey?: string): void { } public registerDecorationType(key: string, options: IDecorationRenderOptions, parentTypeKey?: string): void { }
public removeDecorationType(key: string): void { } public removeDecorationType(key: string): void { }
public resolveDecorationOptions(decorationTypeKey: string, writable: boolean): IModelDecorationOptions { return null; } public resolveDecorationOptions(decorationTypeKey: string, writable: boolean): IModelDecorationOptions { return {}; }
} }
export class TestCommandService implements ICommandService { export class TestCommandService implements ICommandService {
......
...@@ -9,7 +9,7 @@ import { getOrCreateMinimapCharRenderer } from 'vs/editor/common/view/runtimeMin ...@@ -9,7 +9,7 @@ import { getOrCreateMinimapCharRenderer } from 'vs/editor/common/view/runtimeMin
import { RGBA8 } from 'vs/editor/common/core/rgba'; import { RGBA8 } from 'vs/editor/common/core/rgba';
let canvas = <HTMLCanvasElement>document.getElementById('my-canvas'); let canvas = <HTMLCanvasElement>document.getElementById('my-canvas');
let ctx = canvas.getContext('2d'); let ctx = canvas.getContext('2d')!;
canvas.style.height = 100 + 'px'; canvas.style.height = 100 + 'px';
canvas.height = 100; canvas.height = 100;
......
...@@ -87,7 +87,7 @@ function assertLineMapping(model: TextModel, msg: string): void { ...@@ -87,7 +87,7 @@ function assertLineMapping(model: TextModel, msg: string): void {
} }
export function assertSyncedModels(text: string, callback: (model: TextModel, assertMirrorModels: () => void) => void, setup: (model: TextModel) => void = null): void { export function assertSyncedModels(text: string, callback: (model: TextModel, assertMirrorModels: () => void) => void, setup: ((model: TextModel) => void) | null = null): void {
let model = new TextModel(text, TextModel.DEFAULT_CREATION_OPTIONS, null); let model = new TextModel(text, TextModel.DEFAULT_CREATION_OPTIONS, null);
model.setEOL(EndOfLineSequence.LF); model.setEOL(EndOfLineSequence.LF);
assertLineMapping(model, 'model'); assertLineMapping(model, 'model');
...@@ -97,7 +97,7 @@ export function assertSyncedModels(text: string, callback: (model: TextModel, as ...@@ -97,7 +97,7 @@ export function assertSyncedModels(text: string, callback: (model: TextModel, as
assertLineMapping(model, 'model'); assertLineMapping(model, 'model');
} }
let mirrorModel2 = new MirrorTextModel(null, model.getLinesContent(), model.getEOL(), model.getVersionId()); let mirrorModel2 = new MirrorTextModel(null!, model.getLinesContent(), model.getEOL(), model.getVersionId());
let mirrorModel2PrevVersionId = model.getVersionId(); let mirrorModel2PrevVersionId = model.getVersionId();
model.onDidChangeContent((e: IModelContentChangedEvent) => { model.onDidChangeContent((e: IModelContentChangedEvent) => {
......
...@@ -15,7 +15,7 @@ export function testViewModel(text: string[], options: IEditorOptions, callback: ...@@ -15,7 +15,7 @@ export function testViewModel(text: string[], options: IEditorOptions, callback:
let model = TextModel.createFromString(text.join('\n')); let model = TextModel.createFromString(text.join('\n'));
let viewModel = new ViewModel(EDITOR_ID, configuration, model, null); let viewModel = new ViewModel(EDITOR_ID, configuration, model, null!);
callback(viewModel, model); callback(viewModel, model);
......
...@@ -1111,7 +1111,7 @@ declare namespace monaco.editor { ...@@ -1111,7 +1111,7 @@ declare namespace monaco.editor {
export interface IContextKey<T> { export interface IContextKey<T> {
set(value: T): void; set(value: T): void;
reset(): void; reset(): void;
get(): T; get(): T | undefined;
} }
export interface IEditorOverrideServices { export interface IEditorOverrideServices {
...@@ -3741,6 +3741,11 @@ declare namespace monaco.editor { ...@@ -3741,6 +3741,11 @@ declare namespace monaco.editor {
* A mouse event originating from the editor. * A mouse event originating from the editor.
*/ */
export interface IEditorMouseEvent { export interface IEditorMouseEvent {
readonly event: IMouseEvent;
readonly target: IMouseTarget;
}
export interface IPartialEditorMouseEvent {
readonly event: IMouseEvent; readonly event: IMouseEvent;
readonly target: IMouseTarget | null; readonly target: IMouseTarget | null;
} }
...@@ -3846,7 +3851,7 @@ declare namespace monaco.editor { ...@@ -3846,7 +3851,7 @@ declare namespace monaco.editor {
* An event emitted on a "mouseleave". * An event emitted on a "mouseleave".
* @event * @event
*/ */
onMouseLeave(listener: (e: IEditorMouseEvent) => void): IDisposable; onMouseLeave(listener: (e: IPartialEditorMouseEvent) => void): IDisposable;
/** /**
* An event emitted on a "keyup". * An event emitted on a "keyup".
* @event * @event
......
...@@ -549,7 +549,7 @@ export interface IContext { ...@@ -549,7 +549,7 @@ export interface IContext {
export interface IContextKey<T> { export interface IContextKey<T> {
set(value: T): void; set(value: T): void;
reset(): void; reset(): void;
get(): T; get(): T | undefined;
} }
export interface IContextKeyServiceTarget { export interface IContextKeyServiceTarget {
......
...@@ -13,15 +13,15 @@ import { OS } from 'vs/base/common/platform'; ...@@ -13,15 +13,15 @@ import { OS } from 'vs/base/common/platform';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem'; import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
class MockKeybindingContextKey<T> implements IContextKey<T> { class MockKeybindingContextKey<T> implements IContextKey<T> {
private _defaultValue: T; private _defaultValue: T | undefined;
private _value: T; private _value: T | undefined;
constructor(defaultValue: T) { constructor(defaultValue: T | undefined) {
this._defaultValue = defaultValue; this._defaultValue = defaultValue;
this._value = this._defaultValue; this._value = this._defaultValue;
} }
public set(value: T): void { public set(value: T | undefined): void {
this._value = value; this._value = value;
} }
...@@ -29,7 +29,7 @@ class MockKeybindingContextKey<T> implements IContextKey<T> { ...@@ -29,7 +29,7 @@ class MockKeybindingContextKey<T> implements IContextKey<T> {
this._value = this._defaultValue; this._value = this._defaultValue;
} }
public get(): T { public get(): T | undefined {
return this._value; return this._value;
} }
} }
...@@ -42,7 +42,7 @@ export class MockContextKeyService implements IContextKeyService { ...@@ -42,7 +42,7 @@ export class MockContextKeyService implements IContextKeyService {
public dispose(): void { public dispose(): void {
// //
} }
public createKey<T>(key: string, defaultValue: T): IContextKey<T> { public createKey<T>(key: string, defaultValue: T | undefined): IContextKey<T> {
let ret = new MockKeybindingContextKey(defaultValue); let ret = new MockKeybindingContextKey(defaultValue);
this._keys.set(key, ret); this._keys.set(key, ret);
return ret; return ret;
...@@ -74,7 +74,7 @@ export class MockKeybindingService implements IKeybindingService { ...@@ -74,7 +74,7 @@ export class MockKeybindingService implements IKeybindingService {
} }
public getDefaultKeybindingsContent(): string { public getDefaultKeybindingsContent(): string {
return null; return '';
} }
public getDefaultKeybindings(): ResolvedKeybindingItem[] { public getDefaultKeybindings(): ResolvedKeybindingItem[] {
...@@ -108,7 +108,7 @@ export class MockKeybindingService implements IKeybindingService { ...@@ -108,7 +108,7 @@ export class MockKeybindingService implements IKeybindingService {
return []; return [];
} }
public lookupKeybinding(commandId: string): ResolvedKeybinding { public lookupKeybinding(commandId: string): ResolvedKeybinding | null {
return null; return null;
} }
...@@ -116,7 +116,7 @@ export class MockKeybindingService implements IKeybindingService { ...@@ -116,7 +116,7 @@ export class MockKeybindingService implements IKeybindingService {
return 0; return 0;
} }
public softDispatch(keybinding: IKeyboardEvent, target: IContextKeyServiceTarget): IResolveResult { public softDispatch(keybinding: IKeyboardEvent, target: IContextKeyServiceTarget): IResolveResult | null {
return null; return null;
} }
......
...@@ -49,7 +49,7 @@ export class ResourceContextKey extends Disposable implements IContextKey<URI> { ...@@ -49,7 +49,7 @@ export class ResourceContextKey extends Disposable implements IContextKey<URI> {
this._register(_fileService.onDidChangeFileSystemProviderRegistrations(() => { this._register(_fileService.onDidChangeFileSystemProviderRegistrations(() => {
const resource = this._resourceKey.get(); const resource = this._resourceKey.get();
this._isfileSystemResource.set(resource && _fileService.canHandleResource(resource)); this._isfileSystemResource.set(Boolean(resource && _fileService.canHandleResource(resource)));
this._isFileSystemResourceOrUntitled.set(this._isfileSystemResource.get() || this._schemeKey.get() === Schemas.untitled); this._isFileSystemResourceOrUntitled.set(this._isfileSystemResource.get() || this._schemeKey.get() === Schemas.untitled);
})); }));
} }
...@@ -74,7 +74,7 @@ export class ResourceContextKey extends Disposable implements IContextKey<URI> { ...@@ -74,7 +74,7 @@ export class ResourceContextKey extends Disposable implements IContextKey<URI> {
this._hasResource.reset(); this._hasResource.reset();
} }
get(): URI { get(): URI | undefined {
return this._resourceKey.get(); return this._resourceKey.get();
} }
} }
......
...@@ -43,11 +43,11 @@ export class SelectionClipboard extends Disposable implements IEditorContributio ...@@ -43,11 +43,11 @@ export class SelectionClipboard extends Disposable implements IEditorContributio
e.event.preventDefault(); e.event.preventDefault();
editor.focus(); editor.focus();
if (e.target && e.target.position) { if (e.target.position) {
editor.setPosition(e.target.position); editor.setPosition(e.target.position);
} }
if (e.target && e.target.type === MouseTargetType.SCROLLBAR) { if (e.target.type === MouseTargetType.SCROLLBAR) {
return; return;
} }
......
...@@ -13,7 +13,7 @@ import { Position } from 'vs/editor/common/core/position'; ...@@ -13,7 +13,7 @@ import { Position } from 'vs/editor/common/core/position';
import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model'; import { ITextModel } from 'vs/editor/common/model';
import { registerEditorAction, registerEditorContribution, EditorAction, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { registerEditorAction, registerEditorContribution, EditorAction, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { ICodeEditor, ContentWidgetPositionPreference, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor, ContentWidgetPositionPreference, IContentWidget, IContentWidgetPosition, IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { IGrammar, StackElement, IToken } from 'vscode-textmate'; import { IGrammar, StackElement, IToken } from 'vscode-textmate';
import { ITextMateService } from 'vs/workbench/services/textMate/electron-browser/textMateService'; import { ITextMateService } from 'vs/workbench/services/textMate/electron-browser/textMateService';
...@@ -40,7 +40,7 @@ class InspectTMScopesController extends Disposable implements IEditorContributio ...@@ -40,7 +40,7 @@ class InspectTMScopesController extends Disposable implements IEditorContributio
private _themeService: IWorkbenchThemeService; private _themeService: IWorkbenchThemeService;
private _modeService: IModeService; private _modeService: IModeService;
private _notificationService: INotificationService; private _notificationService: INotificationService;
private _widget: InspectTMScopesWidget; private _widget: InspectTMScopesWidget | null;
constructor( constructor(
editor: ICodeEditor, editor: ICodeEditor,
...@@ -75,7 +75,7 @@ class InspectTMScopesController extends Disposable implements IEditorContributio ...@@ -75,7 +75,7 @@ class InspectTMScopesController extends Disposable implements IEditorContributio
if (this._widget) { if (this._widget) {
return; return;
} }
if (!this._editor.getModel()) { if (!this._editor.hasModel()) {
return; return;
} }
this._widget = new InspectTMScopesWidget(this._editor, this._textMateService, this._modeService, this._themeService, this._notificationService); this._widget = new InspectTMScopesWidget(this._editor, this._textMateService, this._modeService, this._themeService, this._notificationService);
...@@ -174,7 +174,7 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget { ...@@ -174,7 +174,7 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
public readonly allowEditorOverflow = true; public readonly allowEditorOverflow = true;
private _isDisposed: boolean; private _isDisposed: boolean;
private readonly _editor: ICodeEditor; private readonly _editor: IActiveCodeEditor;
private readonly _modeService: IModeService; private readonly _modeService: IModeService;
private readonly _themeService: IWorkbenchThemeService; private readonly _themeService: IWorkbenchThemeService;
private readonly _notificationService: INotificationService; private readonly _notificationService: INotificationService;
...@@ -183,7 +183,7 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget { ...@@ -183,7 +183,7 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
private readonly _grammar: TPromise<IGrammar>; private readonly _grammar: TPromise<IGrammar>;
constructor( constructor(
editor: ICodeEditor, editor: IActiveCodeEditor,
textMateService: ITextMateService, textMateService: ITextMateService,
modeService: IModeService, modeService: IModeService,
themeService: IWorkbenchThemeService, themeService: IWorkbenchThemeService,
...@@ -292,14 +292,14 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget { ...@@ -292,14 +292,14 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
} }
private _decodeMetadata(metadata: number): IDecodedMetadata { private _decodeMetadata(metadata: number): IDecodedMetadata {
let colorMap = TokenizationRegistry.getColorMap(); let colorMap = TokenizationRegistry.getColorMap()!;
let languageId = TokenMetadata.getLanguageId(metadata); let languageId = TokenMetadata.getLanguageId(metadata);
let tokenType = TokenMetadata.getTokenType(metadata); let tokenType = TokenMetadata.getTokenType(metadata);
let fontStyle = TokenMetadata.getFontStyle(metadata); let fontStyle = TokenMetadata.getFontStyle(metadata);
let foreground = TokenMetadata.getForeground(metadata); let foreground = TokenMetadata.getForeground(metadata);
let background = TokenMetadata.getBackground(metadata); let background = TokenMetadata.getBackground(metadata);
return { return {
languageIdentifier: this._modeService.getLanguageIdentifier(languageId), languageIdentifier: this._modeService.getLanguageIdentifier(languageId)!,
tokenType: tokenType, tokenType: tokenType,
fontStyle: fontStyle, fontStyle: fontStyle,
foreground: colorMap[foreground], foreground: colorMap[foreground],
......
...@@ -115,7 +115,7 @@ export class WorkbenchModeServiceImpl extends ModeServiceImpl { ...@@ -115,7 +115,7 @@ export class WorkbenchModeServiceImpl extends ModeServiceImpl {
for (let j = 0, lenJ = extension.value.length; j < lenJ; j++) { for (let j = 0, lenJ = extension.value.length; j < lenJ; j++) {
let ext = extension.value[j]; let ext = extension.value[j];
if (isValidLanguageExtensionPoint(ext, extension.collector)) { if (isValidLanguageExtensionPoint(ext, extension.collector)) {
let configuration: URI; let configuration: URI | undefined = undefined;
if (ext.configuration) { if (ext.configuration) {
configuration = resources.joinPath(extension.description.extensionLocation, ext.configuration); configuration = resources.joinPath(extension.description.extensionLocation, ext.configuration);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册