diff --git a/src/vs/editor/browser/editorBrowser.ts b/src/vs/editor/browser/editorBrowser.ts index 6243c0b9dd6..1ea6a364128 100644 --- a/src/vs/editor/browser/editorBrowser.ts +++ b/src/vs/editor/browser/editorBrowser.ts @@ -595,7 +595,7 @@ export interface ICodeEditor extends editorCommon.IEditor { * @id Unique identifier of the contribution. * @return The contribution or null if contribution not found. */ - getContribution(id: string): T; + getContribution(id: string): T | null; /** * Execute `fn` with the editor's services. diff --git a/src/vs/editor/browser/editorExtensions.ts b/src/vs/editor/browser/editorExtensions.ts index 05e31b0ed79..435236bde0a 100644 --- a/src/vs/editor/browser/editorExtensions.ts +++ b/src/vs/editor/browser/editorExtensions.ts @@ -229,7 +229,7 @@ export abstract class EditorCommand extends Command { /** * Create a command class that is bound to a certain editor contribution. */ - public static bindToContribution(controllerGetter: (editor: ICodeEditor) => T): EditorControllerCommand { + public static bindToContribution(controllerGetter: (editor: ICodeEditor) => T | null): EditorControllerCommand { return class EditorControllerCommandImpl extends EditorCommand { private readonly _callback: (controller: T, args: any) => void; @@ -242,7 +242,7 @@ export abstract class EditorCommand extends Command { public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { const controller = controllerGetter(editor); if (controller) { - this._callback(controllerGetter(editor), args); + this._callback(controller, args); } } }; @@ -351,6 +351,25 @@ export abstract class EditorAction extends EditorCommand { public abstract run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Promise; } +interface IEditorContributionCtorWithGet { + get(editor: ICodeEditor): T | null; +} + +export abstract class EditorControllerAction extends EditorAction { + + protected abstract controller: IEditorContributionCtorWithGet; + + run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Promise { + const controller = this.controller.get(editor); + if (!controller) { + return; + } + return this.runControllerAction(accessor, editor, controller, args); + } + + abstract runControllerAction(accessor: ServicesAccessor, editor: ICodeEditor, controller: T, args: any): void | Promise; +} + export type EditorActionImplementation = (accessor: ServicesAccessor, editor: ICodeEditor, args: any) => boolean | Promise; export class MultiEditorAction extends EditorAction { diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 75756825872..e91453cfb65 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -976,7 +976,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE this._focusTracker.refreshState(); } - public getContribution(id: string): T { + public getContribution(id: string): T | null { return (this._contributions[id] || null); } diff --git a/src/vs/editor/contrib/anchorSelect/anchorSelect.ts b/src/vs/editor/contrib/anchorSelect/anchorSelect.ts index 6e8ee1dd046..5d9f449cb52 100644 --- a/src/vs/editor/contrib/anchorSelect/anchorSelect.ts +++ b/src/vs/editor/contrib/anchorSelect/anchorSelect.ts @@ -9,7 +9,7 @@ import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { IDisposable } from 'vs/base/common/lifecycle'; import 'vs/css!./anchorSelect'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { EditorAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; +import { EditorControllerAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { Selection } from 'vs/editor/common/core/selection'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; @@ -24,7 +24,7 @@ class SelectionAnchorController implements IEditorContribution { public static readonly ID = 'editor.contrib.selectionAnchorController'; - static get(editor: ICodeEditor): SelectionAnchorController { + static get(editor: ICodeEditor): SelectionAnchorController | null { return editor.getContribution(SelectionAnchorController.ID); } @@ -93,7 +93,11 @@ class SelectionAnchorController implements IEditorContribution { } } -class SetSelectionAnchor extends EditorAction { +abstract class SelectionAnchorAction extends EditorControllerAction { + controller = SelectionAnchorController; +} + +class SetSelectionAnchor extends SelectionAnchorAction { constructor() { super({ id: 'editor.action.setSelectionAnchor', @@ -108,13 +112,12 @@ class SetSelectionAnchor extends EditorAction { }); } - async run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { - const controller = SelectionAnchorController.get(editor); + async runControllerAction(_accessor: ServicesAccessor, editor: ICodeEditor, controller: SelectionAnchorController): Promise { controller.setSelectionAnchor(); } } -class GoToSelectionAnchor extends EditorAction { +class GoToSelectionAnchor extends SelectionAnchorAction { constructor() { super({ id: 'editor.action.goToSelectionAnchor', @@ -124,13 +127,12 @@ class GoToSelectionAnchor extends EditorAction { }); } - async run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { - const controller = SelectionAnchorController.get(editor); + async runControllerAction(_accessor: ServicesAccessor, editor: ICodeEditor, controller: SelectionAnchorController): Promise { controller.goToSelectionAnchor(); } } -class SelectFromAnchorToCursor extends EditorAction { +class SelectFromAnchorToCursor extends SelectionAnchorAction { constructor() { super({ id: 'editor.action.selectFromAnchorToCursor', @@ -145,13 +147,12 @@ class SelectFromAnchorToCursor extends EditorAction { }); } - async run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { - const controller = SelectionAnchorController.get(editor); + async runControllerAction(_accessor: ServicesAccessor, editor: ICodeEditor, controller: SelectionAnchorController): Promise { controller.selectFromAnchorToCursor(); } } -class CancelSelectionAnchor extends EditorAction { +class CancelSelectionAnchor extends SelectionAnchorAction { constructor() { super({ id: 'editor.action.cancelSelectionAnchor', @@ -166,8 +167,7 @@ class CancelSelectionAnchor extends EditorAction { }); } - async run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { - const controller = SelectionAnchorController.get(editor); + async runControllerAction(_accessor: ServicesAccessor, editor: ICodeEditor, controller: SelectionAnchorController): Promise { controller.cancelSelectionAnchor(); } } diff --git a/src/vs/editor/contrib/bracketMatching/bracketMatching.ts b/src/vs/editor/contrib/bracketMatching/bracketMatching.ts index 7dbc428c99e..c23d5790657 100644 --- a/src/vs/editor/contrib/bracketMatching/bracketMatching.ts +++ b/src/vs/editor/contrib/bracketMatching/bracketMatching.ts @@ -8,7 +8,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { Disposable } from 'vs/base/common/lifecycle'; import 'vs/css!./bracketMatching'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { EditorAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; +import { EditorControllerAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; @@ -26,7 +26,11 @@ import { registerThemingParticipant, themeColorFromId } from 'vs/platform/theme/ const overviewRulerBracketMatchForeground = registerColor('editorOverviewRuler.bracketMatchForeground', { dark: '#A0A0A0', light: '#A0A0A0', hc: '#A0A0A0' }, nls.localize('overviewRulerBracketMatchForeground', 'Overview ruler marker color for matching brackets.')); -class JumpToBracketAction extends EditorAction { +abstract class BracketMatchingAction extends EditorControllerAction { + controller = BracketMatchingController; +} + +class JumpToBracketAction extends BracketMatchingAction { constructor() { super({ id: 'editor.action.jumpToBracket', @@ -41,16 +45,12 @@ class JumpToBracketAction extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { - let controller = BracketMatchingController.get(editor); - if (!controller) { - return; - } + public runControllerAction(accessor: ServicesAccessor, editor: ICodeEditor, controller: BracketMatchingController): void { controller.jumpToBracket(); } } -class SelectToBracketAction extends EditorAction { +class SelectToBracketAction extends BracketMatchingAction { constructor() { super({ id: 'editor.action.selectToBracket', @@ -75,12 +75,7 @@ class SelectToBracketAction extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { - const controller = BracketMatchingController.get(editor); - if (!controller) { - return; - } - + public runControllerAction(accessor: ServicesAccessor, editor: ICodeEditor, controller: BracketMatchingController, args: any): void { let selectBrackets = true; if (args && args.selectBrackets === false) { selectBrackets = false; @@ -106,7 +101,7 @@ class BracketsData { export class BracketMatchingController extends Disposable implements IEditorContribution { public static readonly ID = 'editor.contrib.bracketMatchingController'; - public static get(editor: ICodeEditor): BracketMatchingController { + public static get(editor: ICodeEditor): BracketMatchingController | null { return editor.getContribution(BracketMatchingController.ID); } diff --git a/src/vs/editor/contrib/codeAction/codeActionCommands.ts b/src/vs/editor/contrib/codeAction/codeActionCommands.ts index b9f1c9d252d..165c8de3a89 100644 --- a/src/vs/editor/contrib/codeAction/codeActionCommands.ts +++ b/src/vs/editor/contrib/codeAction/codeActionCommands.ts @@ -69,7 +69,7 @@ export class QuickFixController extends Disposable implements IEditorContributio public static readonly ID = 'editor.contrib.quickFixController'; - public static get(editor: ICodeEditor): QuickFixController { + public static get(editor: ICodeEditor): QuickFixController | null { return editor.getContribution(QuickFixController.ID); } @@ -122,7 +122,7 @@ export class QuickFixController extends Disposable implements IEditorContributio return; } - MessageController.get(this._editor).closeMessage(); + MessageController.get(this._editor)?.closeMessage(); const triggerPosition = this._editor.getPosition(); this._trigger({ type: CodeActionTriggerType.Invoke, filter, autoApply, context: { notAvailableMessage, position: triggerPosition } }); } diff --git a/src/vs/editor/contrib/codeAction/codeActionUi.ts b/src/vs/editor/contrib/codeAction/codeActionUi.ts index f8ff35a52b0..166e6559d48 100644 --- a/src/vs/editor/contrib/codeAction/codeActionUi.ts +++ b/src/vs/editor/contrib/codeAction/codeActionUi.ts @@ -96,7 +96,7 @@ export class CodeActionUi extends Disposable { if (newState.trigger.context) { const invalidAction = this.getInvalidActionThatWouldHaveBeenApplied(newState.trigger, actions); if (invalidAction && invalidAction.action.disabled) { - MessageController.get(this._editor).showMessage(invalidAction.action.disabled, newState.trigger.context.position); + MessageController.get(this._editor)?.showMessage(invalidAction.action.disabled, newState.trigger.context.position); actions.dispose(); return; } @@ -106,7 +106,7 @@ export class CodeActionUi extends Disposable { const includeDisabledActions = !!newState.trigger.filter?.include; if (newState.trigger.context) { if (!actions.allActions.length || !includeDisabledActions && !actions.validActions.length) { - MessageController.get(this._editor).showMessage(newState.trigger.context.notAvailableMessage, newState.trigger.context.position); + MessageController.get(this._editor)?.showMessage(newState.trigger.context.notAvailableMessage, newState.trigger.context.position); this._activeCodeActions.value = actions; actions.dispose(); return; diff --git a/src/vs/editor/contrib/codelens/codelensController.ts b/src/vs/editor/contrib/codelens/codelensController.ts index 648fe143573..5c0b75ce168 100644 --- a/src/vs/editor/contrib/codelens/codelensController.ts +++ b/src/vs/editor/contrib/codelens/codelensController.ts @@ -469,6 +469,9 @@ registerEditorAction(class ShowLensesInCurrentLine extends EditorAction { const lineNumber = editor.getSelection().positionLineNumber; const codelensController = editor.getContribution(CodeLensContribution.ID); + if (!codelensController) { + return; + } const items: { label: string, command: Command }[] = []; for (let lens of codelensController.getLenses()) { diff --git a/src/vs/editor/contrib/colorPicker/colorContributions.ts b/src/vs/editor/contrib/colorPicker/colorContributions.ts index 1ff15f19841..0423698694f 100644 --- a/src/vs/editor/contrib/colorPicker/colorContributions.ts +++ b/src/vs/editor/contrib/colorPicker/colorContributions.ts @@ -47,6 +47,9 @@ export class ColorContribution extends Disposable implements IEditorContribution } const hoverController = this._editor.getContribution(ModesHoverController.ID); + if (!hoverController) { + return; + } if (!hoverController.isColorPickerVisible()) { const range = new Range(mouseEvent.target.range.startLineNumber, mouseEvent.target.range.startColumn + 1, mouseEvent.target.range.endLineNumber, mouseEvent.target.range.endColumn + 1); hoverController.showContentHover(range, HoverStartMode.Delayed, false); diff --git a/src/vs/editor/contrib/colorPicker/colorDetector.ts b/src/vs/editor/contrib/colorPicker/colorDetector.ts index fbbc2fe0103..32da1a4b832 100644 --- a/src/vs/editor/contrib/colorPicker/colorDetector.ts +++ b/src/vs/editor/contrib/colorPicker/colorDetector.ts @@ -89,7 +89,7 @@ export class ColorDetector extends Disposable implements IEditorContribution { return this._editor.getOption(EditorOption.colorDecorators); } - static get(editor: ICodeEditor): ColorDetector { + static get(editor: ICodeEditor): ColorDetector | null { return editor.getContribution(this.ID); } diff --git a/src/vs/editor/contrib/contextmenu/contextmenu.ts b/src/vs/editor/contrib/contextmenu/contextmenu.ts index 23a924fa17f..0d8805ef5e2 100644 --- a/src/vs/editor/contrib/contextmenu/contextmenu.ts +++ b/src/vs/editor/contrib/contextmenu/contextmenu.ts @@ -14,7 +14,7 @@ import { ResolvedKeybinding } from 'vs/base/common/keybindings'; import { DisposableStore } from 'vs/base/common/lifecycle'; import { isIOS } from 'vs/base/common/platform'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; -import { EditorAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; +import { EditorControllerAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { EditorOption } from 'vs/editor/common/config/editorOptions'; import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; @@ -30,7 +30,7 @@ export class ContextMenuController implements IEditorContribution { public static readonly ID = 'editor.contrib.contextmenu'; - public static get(editor: ICodeEditor): ContextMenuController { + public static get(editor: ICodeEditor): ContextMenuController | null { return editor.getContribution(ContextMenuController.ID); } @@ -264,7 +264,11 @@ export class ContextMenuController implements IEditorContribution { } } -class ShowContextMenu extends EditorAction { +abstract class ContextMenuControllerAction extends EditorControllerAction { + controller = ContextMenuController; +} + +class ShowContextMenu extends ContextMenuControllerAction { constructor() { super({ @@ -280,9 +284,8 @@ class ShowContextMenu extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICodeEditor): void { - let contribution = ContextMenuController.get(editor); - contribution.showContextMenu(); + public runControllerAction(accessor: ServicesAccessor, editor: ICodeEditor, controller: ContextMenuController): void { + controller.showContextMenu(); } } diff --git a/src/vs/editor/contrib/cursorUndo/cursorUndo.ts b/src/vs/editor/contrib/cursorUndo/cursorUndo.ts index dcb1a4cc1bc..feaa363904a 100644 --- a/src/vs/editor/contrib/cursorUndo/cursorUndo.ts +++ b/src/vs/editor/contrib/cursorUndo/cursorUndo.ts @@ -6,7 +6,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { Disposable } from 'vs/base/common/lifecycle'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { EditorAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; +import { EditorControllerAction, registerEditorAction, registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { Selection } from 'vs/editor/common/core/selection'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; @@ -47,7 +47,7 @@ export class CursorUndoRedoController extends Disposable implements IEditorContr public static readonly ID = 'editor.contrib.cursorUndoRedoController'; - public static get(editor: ICodeEditor): CursorUndoRedoController { + public static get(editor: ICodeEditor): CursorUndoRedoController | null { return editor.getContribution(CursorUndoRedoController.ID); } @@ -125,7 +125,11 @@ export class CursorUndoRedoController extends Disposable implements IEditorContr } } -export class CursorUndo extends EditorAction { +abstract class CursorUndoRedoControllerAction extends EditorControllerAction { + controller = CursorUndoRedoController; +} + +export class CursorUndo extends CursorUndoRedoControllerAction { constructor() { super({ id: 'cursorUndo', @@ -140,12 +144,12 @@ export class CursorUndo extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { - CursorUndoRedoController.get(editor).cursorUndo(); + public runControllerAction(accessor: ServicesAccessor, editor: ICodeEditor, controller: CursorUndoRedoController, args: any): void { + controller.cursorUndo(); } } -export class CursorRedo extends EditorAction { +export class CursorRedo extends CursorUndoRedoControllerAction { constructor() { super({ id: 'cursorRedo', @@ -155,8 +159,8 @@ export class CursorRedo extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void { - CursorUndoRedoController.get(editor).cursorRedo(); + public runControllerAction(accessor: ServicesAccessor, editor: ICodeEditor, controller: CursorUndoRedoController, args: any): void { + controller.cursorRedo(); } } diff --git a/src/vs/editor/contrib/dnd/dnd.ts b/src/vs/editor/contrib/dnd/dnd.ts index 3ae8b808eaf..9ec09a245cb 100644 --- a/src/vs/editor/contrib/dnd/dnd.ts +++ b/src/vs/editor/contrib/dnd/dnd.ts @@ -41,7 +41,7 @@ export class DragAndDropController extends Disposable implements IEditorContribu private _modifierPressed: boolean; static readonly TRIGGER_KEY_VALUE = isMacintosh ? KeyCode.Alt : KeyCode.Ctrl; - static get(editor: ICodeEditor): DragAndDropController { + static get(editor: ICodeEditor): DragAndDropController | null { return editor.getContribution(DragAndDropController.ID); } diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index 2fdb1df838d..99ef6085d50 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -98,7 +98,7 @@ export class CommonFindController extends Disposable implements IEditorContribut return this._editor; } - public static get(editor: ICodeEditor): CommonFindController { + public static get(editor: ICodeEditor): CommonFindController | null { return editor.getContribution(CommonFindController.ID); } @@ -583,7 +583,7 @@ export class StartFindWithArgsAction extends EditorAction { } public async run(accessor: ServicesAccessor | null, editor: ICodeEditor, args?: IFindStartArguments): Promise { - let controller = CommonFindController.get(editor); + const controller = CommonFindController.get(editor); if (controller) { const newState: INewFindReplaceState = args ? { searchString: args.searchString, @@ -635,7 +635,7 @@ export class StartFindWithSelectionAction extends EditorAction { } public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise { - let controller = CommonFindController.get(editor); + const controller = CommonFindController.get(editor); if (controller) { await controller.start({ forceRevealReplace: false, @@ -654,7 +654,7 @@ export class StartFindWithSelectionAction extends EditorAction { } export abstract class MatchFindAction extends EditorAction { public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise { - let controller = CommonFindController.get(editor); + const controller = CommonFindController.get(editor); if (controller && !this._run(controller)) { await controller.start({ forceRevealReplace: false, @@ -734,7 +734,7 @@ export class PreviousMatchFindAction extends MatchFindAction { export abstract class SelectionMatchFindAction extends EditorAction { public async run(accessor: ServicesAccessor | null, editor: ICodeEditor): Promise { - let controller = CommonFindController.get(editor); + const controller = CommonFindController.get(editor); if (!controller) { return; } diff --git a/src/vs/editor/contrib/folding/folding.ts b/src/vs/editor/contrib/folding/folding.ts index b9d811d55f5..67b387117e6 100644 --- a/src/vs/editor/contrib/folding/folding.ts +++ b/src/vs/editor/contrib/folding/folding.ts @@ -58,7 +58,7 @@ export class FoldingController extends Disposable implements IEditorContribution static readonly MAX_FOLDING_REGIONS = 5000; - public static get(editor: ICodeEditor): FoldingController { + public static get(editor: ICodeEditor): FoldingController | null { return editor.getContribution(FoldingController.ID); } @@ -511,11 +511,11 @@ abstract class FoldingAction extends EditorAction { abstract invoke(foldingController: FoldingController, foldingModel: FoldingModel, editor: ICodeEditor, args: T): void; public override runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: T): void | Promise { - let foldingController = FoldingController.get(editor); + const foldingController = FoldingController.get(editor); if (!foldingController) { return; } - let foldingModelPromise = foldingController.getFoldingModel(); + const foldingModelPromise = foldingController.getFoldingModel(); if (foldingModelPromise) { this.reportTelemetry(accessor, editor); return foldingModelPromise.then(foldingModel => { diff --git a/src/vs/editor/contrib/gotoError/gotoError.ts b/src/vs/editor/contrib/gotoError/gotoError.ts index f8079d8cf4f..10f4b12814c 100644 --- a/src/vs/editor/contrib/gotoError/gotoError.ts +++ b/src/vs/editor/contrib/gotoError/gotoError.ts @@ -29,7 +29,7 @@ export class MarkerController implements IEditorContribution { static readonly ID = 'editor.contrib.markerController'; - static get(editor: ICodeEditor): MarkerController { + static get(editor: ICodeEditor): MarkerController | null { return editor.getContribution(MarkerController.ID); } @@ -154,8 +154,8 @@ export class MarkerController implements IEditorContribution { }, this._editor); if (otherEditor) { - MarkerController.get(otherEditor).close(); - MarkerController.get(otherEditor).nagivate(next, multiFile); + MarkerController.get(otherEditor)?.close(); + MarkerController.get(otherEditor)?.nagivate(next, multiFile); } } else { @@ -178,7 +178,7 @@ class MarkerNavigationAction extends EditorAction { async run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { if (editor.hasModel()) { - MarkerController.get(editor).nagivate(this._next, this._multiFile); + MarkerController.get(editor)?.nagivate(this._next, this._multiFile); } } } diff --git a/src/vs/editor/contrib/gotoSymbol/goToCommands.ts b/src/vs/editor/contrib/gotoSymbol/goToCommands.ts index b1a4b7ef2cd..0f41d7e2c74 100644 --- a/src/vs/editor/contrib/gotoSymbol/goToCommands.ts +++ b/src/vs/editor/contrib/gotoSymbol/goToCommands.ts @@ -108,7 +108,7 @@ abstract class SymbolNavigationAction extends EditorAction { // no result -> show message if (!this._configuration.muteMessage) { const info = model.getWordAtPosition(pos); - MessageController.get(editor).showMessage(this._getNoResultFoundMessage(info), pos); + MessageController.get(editor)?.showMessage(this._getNoResultFoundMessage(info), pos); } } else if (referenceCount === 1 && altAction) { // already at the only result, run alternative @@ -202,7 +202,7 @@ abstract class SymbolNavigationAction extends EditorAction { } private _openInPeek(target: ICodeEditor, model: ReferencesModel) { - let controller = ReferencesController.get(target); + const controller = ReferencesController.get(target); if (controller && target.hasModel()) { controller.toggleWidget(target.getSelection(), createCancelablePromise(_ => Promise.resolve(model)), this._configuration.openInPeek); } else { diff --git a/src/vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition.ts b/src/vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition.ts index 655395a7aba..c078803a8cf 100644 --- a/src/vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition.ts +++ b/src/vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition.ts @@ -76,7 +76,7 @@ export class GotoDefinitionAtPositionEditorContribution implements IEditorContri })); } - static get(editor: ICodeEditor): GotoDefinitionAtPositionEditorContribution { + static get(editor: ICodeEditor): GotoDefinitionAtPositionEditorContribution | null { return editor.getContribution(GotoDefinitionAtPositionEditorContribution.ID); } diff --git a/src/vs/editor/contrib/gotoSymbol/peek/referencesController.ts b/src/vs/editor/contrib/gotoSymbol/peek/referencesController.ts index af4158ba55e..22115352c83 100644 --- a/src/vs/editor/contrib/gotoSymbol/peek/referencesController.ts +++ b/src/vs/editor/contrib/gotoSymbol/peek/referencesController.ts @@ -43,7 +43,7 @@ export abstract class ReferencesController implements IEditorContribution { private readonly _referenceSearchVisible: IContextKey; - static get(editor: ICodeEditor): ReferencesController { + static get(editor: ICodeEditor): ReferencesController | null { return editor.getContribution(ReferencesController.ID); } @@ -270,7 +270,7 @@ export abstract class ReferencesController implements IEditorContribution { this.closeWidget(); openedEditor.focus(); - other.toggleWidget( + other?.toggleWidget( range, createCancelablePromise(_ => Promise.resolve(model)), this._peekMode ?? false @@ -302,7 +302,7 @@ function withController(accessor: ServicesAccessor, fn: (controller: ReferencesC if (!outerEditor) { return; } - let controller = ReferencesController.get(outerEditor); + const controller = ReferencesController.get(outerEditor); if (controller) { fn(controller); } diff --git a/src/vs/editor/contrib/hover/colorHoverParticipant.ts b/src/vs/editor/contrib/hover/colorHoverParticipant.ts index 5160e65122f..9fc2d86c0c2 100644 --- a/src/vs/editor/contrib/hover/colorHoverParticipant.ts +++ b/src/vs/editor/contrib/hover/colorHoverParticipant.ts @@ -64,6 +64,9 @@ export class ColorHoverParticipant implements IEditorHoverParticipant; - static get(editor: ICodeEditor): ModesHoverController { + static get(editor: ICodeEditor): ModesHoverController | null { return editor.getContribution(ModesHoverController.ID); } @@ -283,7 +283,7 @@ class ShowDefinitionPreviewHoverAction extends EditorAction { } public run(accessor: ServicesAccessor, editor: ICodeEditor): void { - let controller = ModesHoverController.get(editor); + const controller = ModesHoverController.get(editor); if (!controller) { return; } @@ -295,6 +295,9 @@ class ShowDefinitionPreviewHoverAction extends EditorAction { const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column); const goto = GotoDefinitionAtPositionEditorContribution.get(editor); + if (!goto) { + return; + } const promise = goto.startFindDefinitionFromCursor(position); promise.then(() => { controller.showContentHover(range, HoverStartMode.Immediate, true); diff --git a/src/vs/editor/contrib/hover/markerHoverParticipant.ts b/src/vs/editor/contrib/hover/markerHoverParticipant.ts index d61e79b638f..fa17f20b7ff 100644 --- a/src/vs/editor/contrib/hover/markerHoverParticipant.ts +++ b/src/vs/editor/contrib/hover/markerHoverParticipant.ts @@ -173,7 +173,7 @@ export class MarkerHoverParticipant implements IEditorHoverParticipant { this._hover.hide(); - MarkerController.get(this._editor).showAtMarker(markerHover.marker); + MarkerController.get(this._editor)?.showAtMarker(markerHover.marker); this._editor.focus(); } }); @@ -225,7 +225,7 @@ export class MarkerHoverParticipant implements IEditorHoverParticipant(InPlaceReplaceController.ID); } diff --git a/src/vs/editor/contrib/inlineCompletions/ghostTextController.ts b/src/vs/editor/contrib/inlineCompletions/ghostTextController.ts index 2213989a1fc..2c17fadf7e7 100644 --- a/src/vs/editor/contrib/inlineCompletions/ghostTextController.ts +++ b/src/vs/editor/contrib/inlineCompletions/ghostTextController.ts @@ -27,7 +27,7 @@ export class GhostTextController extends Disposable { static ID = 'editor.contrib.ghostTextController'; - public static get(editor: ICodeEditor): GhostTextController { + public static get(editor: ICodeEditor): GhostTextController | null { return editor.getContribution(GhostTextController.ID); } diff --git a/src/vs/editor/contrib/linkedEditing/linkedEditing.ts b/src/vs/editor/contrib/linkedEditing/linkedEditing.ts index a029a2cb44d..37c47c71cf6 100644 --- a/src/vs/editor/contrib/linkedEditing/linkedEditing.ts +++ b/src/vs/editor/contrib/linkedEditing/linkedEditing.ts @@ -44,7 +44,7 @@ export class LinkedEditingContribution extends Disposable implements IEditorCont className: DECORATION_CLASS_NAME }); - static get(editor: ICodeEditor): LinkedEditingContribution { + static get(editor: ICodeEditor): LinkedEditingContribution | null { return editor.getContribution(LinkedEditingContribution.ID); } diff --git a/src/vs/editor/contrib/links/links.ts b/src/vs/editor/contrib/links/links.ts index 809085bb818..6c5170e8456 100644 --- a/src/vs/editor/contrib/links/links.ts +++ b/src/vs/editor/contrib/links/links.ts @@ -116,7 +116,7 @@ export class LinkDetector implements IEditorContribution { public static readonly ID: string = 'editor.linkDetector'; - public static get(editor: ICodeEditor): LinkDetector { + public static get(editor: ICodeEditor): LinkDetector | null { return editor.getContribution(LinkDetector.ID); } @@ -404,7 +404,7 @@ class OpenLinkAction extends EditorAction { } public run(accessor: ServicesAccessor, editor: ICodeEditor): void { - let linkDetector = LinkDetector.get(editor); + const linkDetector = LinkDetector.get(editor); if (!linkDetector) { return; } diff --git a/src/vs/editor/contrib/message/messageController.ts b/src/vs/editor/contrib/message/messageController.ts index 5efbb4e9be0..5bbc1908fb8 100644 --- a/src/vs/editor/contrib/message/messageController.ts +++ b/src/vs/editor/contrib/message/messageController.ts @@ -23,7 +23,7 @@ export class MessageController implements IEditorContribution { static readonly MESSAGE_VISIBLE = new RawContextKey('messageVisible', false, nls.localize('messageVisible', 'Whether the editor is currently showing an inline message')); - static get(editor: ICodeEditor): MessageController { + static get(editor: ICodeEditor): MessageController | null { return editor.getContribution(MessageController.ID); } diff --git a/src/vs/editor/contrib/multicursor/multicursor.ts b/src/vs/editor/contrib/multicursor/multicursor.ts index 9eebf15826b..805900d7da0 100644 --- a/src/vs/editor/contrib/multicursor/multicursor.ts +++ b/src/vs/editor/contrib/multicursor/multicursor.ts @@ -458,7 +458,7 @@ export class MultiCursorSelectionController extends Disposable implements IEdito private _session: MultiCursorSession | null; private readonly _sessionDispose = this._register(new DisposableStore()); - public static get(editor: ICodeEditor): MultiCursorSelectionController { + public static get(editor: ICodeEditor): MultiCursorSelectionController | null { return editor.getContribution(MultiCursorSelectionController.ID); } @@ -897,9 +897,12 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut this.updateSoon.schedule(); } })); - this._register(CommonFindController.get(editor).getState().onFindReplaceStateChange((e) => { - this._update(); - })); + const findController = CommonFindController.get(editor); + if (findController) { + this._register(findController.getState().onFindReplaceStateChange((e) => { + this._update(); + })); + } } private _update(): void { diff --git a/src/vs/editor/contrib/parameterHints/parameterHints.ts b/src/vs/editor/contrib/parameterHints/parameterHints.ts index 13c86afa0bf..3ca7c6023cb 100644 --- a/src/vs/editor/contrib/parameterHints/parameterHints.ts +++ b/src/vs/editor/contrib/parameterHints/parameterHints.ts @@ -22,7 +22,7 @@ class ParameterHintsController extends Disposable implements IEditorContribution public static readonly ID = 'editor.controller.parameterHints'; - public static get(editor: ICodeEditor): ParameterHintsController { + public static get(editor: ICodeEditor): ParameterHintsController | null { return editor.getContribution(ParameterHintsController.ID); } diff --git a/src/vs/editor/contrib/rename/rename.ts b/src/vs/editor/contrib/rename/rename.ts index 9a71f4ef868..1c7bfc2fb6d 100644 --- a/src/vs/editor/contrib/rename/rename.ts +++ b/src/vs/editor/contrib/rename/rename.ts @@ -124,7 +124,7 @@ class RenameController implements IEditorContribution { public static readonly ID = 'editor.contrib.renameController'; - static get(editor: ICodeEditor): RenameController { + static get(editor: ICodeEditor): RenameController | null { return editor.getContribution(RenameController.ID); } @@ -173,7 +173,7 @@ class RenameController implements IEditorContribution { this._progressService.showWhile(resolveLocationOperation, 250); loc = await resolveLocationOperation; } catch (e) { - MessageController.get(this.editor).showMessage(e || nls.localize('resolveRenameLocationFailed', "An unknown error occurred while resolving rename location"), position); + MessageController.get(this.editor)?.showMessage(e || nls.localize('resolveRenameLocationFailed', "An unknown error occurred while resolving rename location"), position); return undefined; } @@ -182,7 +182,7 @@ class RenameController implements IEditorContribution { } if (loc.rejectReason) { - MessageController.get(this.editor).showMessage(loc.rejectReason, position); + MessageController.get(this.editor)?.showMessage(loc.rejectReason, position); return undefined; } diff --git a/src/vs/editor/contrib/smartSelect/smartSelect.ts b/src/vs/editor/contrib/smartSelect/smartSelect.ts index 496ed00c9ca..0e6b5eaed60 100644 --- a/src/vs/editor/contrib/smartSelect/smartSelect.ts +++ b/src/vs/editor/contrib/smartSelect/smartSelect.ts @@ -50,7 +50,7 @@ class SmartSelectController implements IEditorContribution { static readonly ID = 'editor.contrib.smartSelectController'; - static get(editor: ICodeEditor): SmartSelectController { + static get(editor: ICodeEditor): SmartSelectController | null { return editor.getContribution(SmartSelectController.ID); } diff --git a/src/vs/editor/contrib/snippet/snippetController2.ts b/src/vs/editor/contrib/snippet/snippetController2.ts index a67846f68d1..273eb1d80ea 100644 --- a/src/vs/editor/contrib/snippet/snippetController2.ts +++ b/src/vs/editor/contrib/snippet/snippetController2.ts @@ -45,7 +45,7 @@ export class SnippetController2 implements IEditorContribution { public static readonly ID = 'snippetController2'; - static get(editor: ICodeEditor): SnippetController2 { + static get(editor: ICodeEditor): SnippetController2 | null { return editor.getContribution(SnippetController2.ID); } diff --git a/src/vs/editor/contrib/suggest/suggest.ts b/src/vs/editor/contrib/suggest/suggest.ts index 36c02a93d6f..429582cf807 100644 --- a/src/vs/editor/contrib/suggest/suggest.ts +++ b/src/vs/editor/contrib/suggest/suggest.ts @@ -409,7 +409,7 @@ modes.CompletionProviderRegistry.register('*', _provider); export function showSimpleSuggestions(editor: ICodeEditor, suggestions: modes.CompletionItem[]) { setTimeout(() => { _provider.onlyOnceSuggestions.push(...suggestions); - editor.getContribution('editor.contrib.suggestController').triggerSuggest(new Set().add(_provider)); + editor.getContribution('editor.contrib.suggestController')?.triggerSuggest(new Set().add(_provider)); }, 0); } diff --git a/src/vs/editor/contrib/suggest/suggestController.ts b/src/vs/editor/contrib/suggest/suggestController.ts index 42e2561cef1..01c74016008 100644 --- a/src/vs/editor/contrib/suggest/suggestController.ts +++ b/src/vs/editor/contrib/suggest/suggestController.ts @@ -104,7 +104,7 @@ export class SuggestController implements IEditorContribution { public static readonly ID: string = 'editor.contrib.suggestController'; - public static get(editor: ICodeEditor): SuggestController { + public static get(editor: ICodeEditor): SuggestController | null { return editor.getContribution(SuggestController.ID); } @@ -284,6 +284,10 @@ export class SuggestController implements IEditorContribution { if (!this.editor.hasModel()) { return; } + const snippetController = SnippetController2.get(this.editor); + if (!snippetController) { + return; + } const model = this.editor.getModel(); const modelVersionNow = model.getAlternativeVersionId(); @@ -377,7 +381,7 @@ export class SuggestController implements IEditorContribution { insertText = SnippetParser.escape(insertText); } - SnippetController2.get(this.editor).insert(insertText, { + snippetController.insert(insertText, { overwriteBefore: info.overwriteBefore, overwriteAfter: info.overwriteAfter, undoStopBefore: false, @@ -984,6 +988,6 @@ registerEditorAction(class extends EditorAction { } run(_accessor: ServicesAccessor, editor: ICodeEditor): void { - SuggestController.get(editor).resetWidgetSize(); + SuggestController.get(editor)?.resetWidgetSize(); } }); diff --git a/src/vs/editor/contrib/suggest/suggestModel.ts b/src/vs/editor/contrib/suggest/suggestModel.ts index af2703631f1..c519ea09ba2 100644 --- a/src/vs/editor/contrib/suggest/suggestModel.ts +++ b/src/vs/editor/contrib/suggest/suggestModel.ts @@ -378,7 +378,7 @@ export class SuggestModel implements IDisposable { return; } - if (this._editor.getOption(EditorOption.suggest).snippetsPreventQuickSuggestions && SnippetController2.get(this._editor).isInSnippet()) { + if (this._editor.getOption(EditorOption.suggest).snippetsPreventQuickSuggestions && SnippetController2.get(this._editor)?.isInSnippet()) { // no quick suggestion when in snippet mode return; } diff --git a/src/vs/editor/contrib/unicodeHighlighter/unicodeHighlighter.ts b/src/vs/editor/contrib/unicodeHighlighter/unicodeHighlighter.ts index 1d62875aa71..77b3b27492d 100644 --- a/src/vs/editor/contrib/unicodeHighlighter/unicodeHighlighter.ts +++ b/src/vs/editor/contrib/unicodeHighlighter/unicodeHighlighter.ts @@ -410,7 +410,9 @@ export class UnicodeHighlighterHoverParticipant implements IEditorHoverParticipa const model = this._editor.getModel(); const unicodeHighlighter = this._editor.getContribution(UnicodeHighlighter.ID); - + if (!unicodeHighlighter) { + return []; + } const result: MarkdownHover[] = []; let index = 300; diff --git a/src/vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens.ts b/src/vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens.ts index 5dcb8e25cc4..6f6da8943bd 100644 --- a/src/vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens.ts +++ b/src/vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens.ts @@ -22,7 +22,7 @@ class ViewportSemanticTokensContribution extends Disposable implements IEditorCo public static readonly ID = 'editor.contrib.viewportSemanticTokens'; - public static get(editor: ICodeEditor): ViewportSemanticTokensContribution { + public static get(editor: ICodeEditor): ViewportSemanticTokensContribution | null { return editor.getContribution(ViewportSemanticTokensContribution.ID); } diff --git a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts index 3b90014315b..747c815d70d 100644 --- a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts +++ b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts @@ -494,7 +494,7 @@ class WordHighlighterContribution extends Disposable implements IEditorContribut public static readonly ID = 'editor.contrib.wordHighlighter'; - public static get(editor: ICodeEditor): WordHighlighterContribution { + public static get(editor: ICodeEditor): WordHighlighterContribution | null { return editor.getContribution(WordHighlighterContribution.ID); } diff --git a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts index e9e8e4b9f59..a6fad0226d7 100644 --- a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts +++ b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts @@ -38,7 +38,7 @@ class AccessibilityHelpController extends Disposable implements IEditorContribution { public static readonly ID = 'editor.contrib.accessibilityHelpController'; - public static get(editor: ICodeEditor): AccessibilityHelpController { + public static get(editor: ICodeEditor): AccessibilityHelpController | null { return editor.getContribution( AccessibilityHelpController.ID ); diff --git a/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts b/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts index 416f9d9b2d3..e588b8c45d5 100644 --- a/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts +++ b/src/vs/editor/standalone/browser/inspectTokens/inspectTokens.ts @@ -29,7 +29,7 @@ class InspectTokensController extends Disposable implements IEditorContribution public static readonly ID = 'editor.contrib.inspectTokens'; - public static get(editor: ICodeEditor): InspectTokensController { + public static get(editor: ICodeEditor): InspectTokensController | null { return editor.getContribution(InspectTokensController.ID); } diff --git a/src/vs/editor/standalone/browser/quickInput/standaloneQuickInputServiceImpl.ts b/src/vs/editor/standalone/browser/quickInput/standaloneQuickInputServiceImpl.ts index 4c4bd06b51a..d215bfb802e 100644 --- a/src/vs/editor/standalone/browser/quickInput/standaloneQuickInputServiceImpl.ts +++ b/src/vs/editor/standalone/browser/quickInput/standaloneQuickInputServiceImpl.ts @@ -36,13 +36,18 @@ export class EditorScopedQuickInputServiceImpl extends QuickInputService { // Use the passed in code editor as host for the quick input widget const contribution = QuickInputEditorContribution.get(editor); - this.host = { - _serviceBrand: undefined, - get container() { return contribution.widget.getDomNode(); }, - get dimension() { return editor.getLayoutInfo(); }, - get onDidLayout() { return editor.onDidLayoutChange; }, - focus: () => editor.focus() - }; + if (contribution) { + const widget = contribution.widget; + this.host = { + _serviceBrand: undefined, + get container() { return widget.getDomNode(); }, + get dimension() { return editor.getLayoutInfo(); }, + get onDidLayout() { return editor.onDidLayoutChange; }, + focus: () => editor.focus() + }; + } else { + this.host = undefined; + } } protected override createController(): QuickInputController { @@ -135,7 +140,7 @@ export class QuickInputEditorContribution implements IEditorContribution { static readonly ID = 'editor.controller.quickInput'; - static get(editor: ICodeEditor): QuickInputEditorContribution { + static get(editor: ICodeEditor): QuickInputEditorContribution | null { return editor.getContribution(QuickInputEditorContribution.ID); } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 16dc9793744..180bbd2b319 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -4918,7 +4918,7 @@ declare namespace monaco.editor { * @id Unique identifier of the contribution. * @return The contribution or null if contribution not found. */ - getContribution(id: string): T; + getContribution(id: string): T | null; /** * Type the getModel() of IEditor. */ diff --git a/src/vs/workbench/api/browser/mainThreadEditor.ts b/src/vs/workbench/api/browser/mainThreadEditor.ts index 626c49bf09c..941611886ea 100644 --- a/src/vs/workbench/api/browser/mainThreadEditor.ts +++ b/src/vs/workbench/api/browser/mainThreadEditor.ts @@ -527,7 +527,7 @@ export class MainThreadTextEditor { this._codeEditor.focus(); // make modifications - snippetController.insert(template, { + snippetController?.insert(template, { overwriteBefore: 0, overwriteAfter: 0, undoStopBefore: opts.undoStopBefore, undoStopAfter: opts.undoStopAfter, clipboardText diff --git a/src/vs/workbench/browser/codeeditor.ts b/src/vs/workbench/browser/codeeditor.ts index 46ae4f0d265..9738fc2a492 100644 --- a/src/vs/workbench/browser/codeeditor.ts +++ b/src/vs/workbench/browser/codeeditor.ts @@ -211,7 +211,7 @@ export class FloatingClickWidget extends Widget implements IOverlayWidget { export class OpenWorkspaceButtonContribution extends Disposable implements IEditorContribution { - static get(editor: ICodeEditor): OpenWorkspaceButtonContribution { + static get(editor: ICodeEditor): OpenWorkspaceButtonContribution | null { return editor.getContribution(OpenWorkspaceButtonContribution.ID); } diff --git a/src/vs/workbench/contrib/callHierarchy/browser/callHierarchy.contribution.ts b/src/vs/workbench/contrib/callHierarchy/browser/callHierarchy.contribution.ts index 7be3cf0a6d5..7eed240c403 100644 --- a/src/vs/workbench/contrib/callHierarchy/browser/callHierarchy.contribution.ts +++ b/src/vs/workbench/contrib/callHierarchy/browser/callHierarchy.contribution.ts @@ -40,7 +40,7 @@ class CallHierarchyController implements IEditorContribution { static readonly Id = 'callHierarchy'; - static get(editor: ICodeEditor): CallHierarchyController { + static get(editor: ICodeEditor): CallHierarchyController | null { return editor.getContribution(CallHierarchyController.Id); } @@ -112,7 +112,7 @@ class CallHierarchyController implements IEditorContribution { const newModel = model.fork(call.item); this._sessionDisposables.clear(); - CallHierarchyController.get(newEditor)._showCallHierarchyWidget( + CallHierarchyController.get(newEditor)?._showCallHierarchyWidget( Range.lift(newModel.root.selectionRange).getStartPosition(), this._widget.direction, Promise.resolve(newModel), @@ -198,7 +198,7 @@ registerAction2(class extends EditorAction2 { } async runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { - return CallHierarchyController.get(editor).startCallHierarchyFromEditor(); + return CallHierarchyController.get(editor)?.startCallHierarchyFromEditor(); } }); @@ -223,7 +223,7 @@ registerAction2(class extends EditorAction2 { } runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) { - return CallHierarchyController.get(editor).showIncomingCalls(); + return CallHierarchyController.get(editor)?.showIncomingCalls(); } }); @@ -248,7 +248,7 @@ registerAction2(class extends EditorAction2 { } runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) { - return CallHierarchyController.get(editor).showOutgoingCalls(); + return CallHierarchyController.get(editor)?.showOutgoingCalls(); } }); @@ -268,7 +268,7 @@ registerAction2(class extends EditorAction2 { } async runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { - return CallHierarchyController.get(editor).startCallHierarchyFromCallHierarchy(); + return CallHierarchyController.get(editor)?.startCallHierarchyFromCallHierarchy(); } }); @@ -296,6 +296,6 @@ registerAction2(class extends EditorAction2 { } runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor): void { - return CallHierarchyController.get(editor).endCallHierarchy(); + return CallHierarchyController.get(editor)?.endCallHierarchy(); } }); diff --git a/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts b/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts index cbb37bd2383..344afbe6f33 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts @@ -41,7 +41,7 @@ export class AccessibilityHelpController extends Disposable implements IEditorCo public static readonly ID = 'editor.contrib.accessibilityHelpController'; - public static get(editor: ICodeEditor): AccessibilityHelpController { + public static get(editor: ICodeEditor): AccessibilityHelpController | null { return editor.getContribution(AccessibilityHelpController.ID); } diff --git a/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts b/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts index 015a2a1fe3d..61d4f2099de 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts @@ -39,7 +39,7 @@ class InspectEditorTokensController extends Disposable implements IEditorContrib public static readonly ID = 'editor.contrib.inspectEditorTokens'; - public static get(editor: ICodeEditor): InspectEditorTokensController { + public static get(editor: ICodeEditor): InspectEditorTokensController | null { return editor.getContribution(InspectEditorTokensController.ID); } @@ -249,7 +249,7 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget { this._notificationService.warn(err); setTimeout(() => { - InspectEditorTokensController.get(this._editor).stop(); + InspectEditorTokensController.get(this._editor)?.stop(); }); }); diff --git a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts index 80be1245cd9..0b292e13ec2 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts @@ -62,7 +62,7 @@ export class TrimWhitespaceParticipant implements ITextFileSaveParticipant { prevSelection = editor.getSelections(); if (isAutoSaved) { cursors = prevSelection.map(s => s.getPosition()); - const snippetsRange = SnippetController2.get(editor).getSessionEnclosingRange(); + const snippetsRange = SnippetController2.get(editor)?.getSessionEnclosingRange(); if (snippetsRange) { for (let lineNumber = snippetsRange.startLineNumber; lineNumber <= snippetsRange.endLineNumber; lineNumber++) { cursors.push(new Position(lineNumber, model.getLineMaxColumn(lineNumber))); diff --git a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts index 1114088c35c..a7de3166370 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts @@ -243,7 +243,7 @@ export class CommentController implements IEditorContribution { } } - public static get(editor: ICodeEditor): CommentController { + public static get(editor: ICodeEditor): CommentController | null { return editor.getContribution(ID); } diff --git a/src/vs/workbench/contrib/comments/browser/commentsView.ts b/src/vs/workbench/contrib/comments/browser/commentsView.ts index 914d1cfc22b..df677b00713 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsView.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsView.ts @@ -218,7 +218,7 @@ export class CommentsPanel extends ViewPane { const control = this.editorService.activeTextEditorControl; if (threadToReveal && isCodeEditor(control)) { const controller = CommentController.get(control); - controller.revealCommentThread(threadToReveal, commentToReveal, false); + controller?.revealCommentThread(threadToReveal, commentToReveal, false); } return true; @@ -239,7 +239,7 @@ export class CommentsPanel extends ViewPane { const control = editor.getControl(); if (threadToReveal && isCodeEditor(control)) { const controller = CommentController.get(control); - controller.revealCommentThread(threadToReveal, commentToReveal.uniqueIdInThread, true); + controller?.revealCommentThread(threadToReveal, commentToReveal.uniqueIdInThread, true); } } }); diff --git a/src/vs/workbench/contrib/debug/browser/breakpointsView.ts b/src/vs/workbench/contrib/debug/browser/breakpointsView.ts index 6c0226e8e4a..d911c850057 100644 --- a/src/vs/workbench/contrib/debug/browser/breakpointsView.ts +++ b/src/vs/workbench/contrib/debug/browser/breakpointsView.ts @@ -1365,7 +1365,7 @@ registerAction2(class extends ViewAction { if (editor) { const codeEditor = editor.getControl(); if (isCodeEditor(codeEditor)) { - codeEditor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID).showBreakpointWidget(breakpoint.lineNumber, breakpoint.column); + codeEditor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID)?.showBreakpointWidget(breakpoint.lineNumber, breakpoint.column); } } } else if (breakpoint instanceof FunctionBreakpoint) { diff --git a/src/vs/workbench/contrib/debug/browser/debugCommands.ts b/src/vs/workbench/contrib/debug/browser/debugCommands.ts index 94e5c948359..32415cab8ec 100644 --- a/src/vs/workbench/contrib/debug/browser/debugCommands.ts +++ b/src/vs/workbench/contrib/debug/browser/debugCommands.ts @@ -624,7 +624,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ if (editor && !created) { const codeEditor = editor.getControl(); if (codeEditor) { - await codeEditor.getContribution(EDITOR_CONTRIBUTION_ID).addLaunchConfiguration(); + await codeEditor.getContribution(EDITOR_CONTRIBUTION_ID)?.addLaunchConfiguration(); } } } diff --git a/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts b/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts index d4951da6c8b..f1f8e7f8606 100644 --- a/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts +++ b/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts @@ -96,7 +96,7 @@ class ConditionalBreakpointAction extends EditorAction2 { const position = editor.getPosition(); if (position && editor.hasModel() && debugService.canSetBreakpointsIn(editor.getModel())) { - editor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID).showBreakpointWidget(position.lineNumber, undefined, BreakpointWidgetContext.CONDITION); + editor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID)?.showBreakpointWidget(position.lineNumber, undefined, BreakpointWidgetContext.CONDITION); } } } @@ -127,7 +127,7 @@ class LogPointAction extends EditorAction2 { const position = editor.getPosition(); if (position && editor.hasModel() && debugService.canSetBreakpointsIn(editor.getModel())) { - editor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID).showBreakpointWidget(position.lineNumber, position.column, BreakpointWidgetContext.LOG_MESSAGE); + editor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID)?.showBreakpointWidget(position.lineNumber, position.column, BreakpointWidgetContext.LOG_MESSAGE); } } } @@ -326,7 +326,7 @@ class ShowDebugHoverAction extends EditorAction { } const range = new Range(position.lineNumber, position.column, position.lineNumber, word.endColumn); - return editor.getContribution(EDITOR_CONTRIBUTION_ID).showHover(range, true); + return editor.getContribution(EDITOR_CONTRIBUTION_ID)?.showHover(range, true); } } @@ -458,7 +458,7 @@ class CloseExceptionWidgetAction extends EditorAction { async run(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { const contribution = editor.getContribution(EDITOR_CONTRIBUTION_ID); - contribution.closeExceptionWidget(); + contribution?.closeExceptionWidget(); } } diff --git a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts index 5efdae15f8a..a04af1972d2 100644 --- a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts +++ b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts @@ -295,7 +295,7 @@ export class DebugEditorContribution implements IDebugEditorContribution { if (debugHoverWasVisible && this.hoverRange) { // If the debug hover was visible immediately show the editor hover for the alt transition to be smooth const hoverController = this.editor.getContribution(ModesHoverController.ID); - hoverController.showContentHover(this.hoverRange, HoverStartMode.Immediate, false); + hoverController?.showContentHover(this.hoverRange, HoverStartMode.Immediate, false); } const onKeyUp = new DomEmitter(document, 'keyup'); diff --git a/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts b/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts index 430143af84c..8f51b53ae79 100644 --- a/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts +++ b/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts @@ -82,7 +82,7 @@ export class ExceptionWidget extends ZoneWidget { const actionBar = new ActionBar(actions); actionBar.push(new Action('editor.closeExceptionWidget', nls.localize('close', "Close"), ThemeIcon.asClassName(widgetClose), true, async () => { const contribution = this.editor.getContribution(EDITOR_CONTRIBUTION_ID); - contribution.closeExceptionWidget(); + contribution?.closeExceptionWidget(); }), { label: false, icon: true }); dom.append(container, title); diff --git a/src/vs/workbench/contrib/debug/browser/repl.ts b/src/vs/workbench/contrib/debug/browser/repl.ts index 79bd4ebc43d..a6c347ead28 100644 --- a/src/vs/workbench/contrib/debug/browser/repl.ts +++ b/src/vs/workbench/contrib/debug/browser/repl.ts @@ -756,7 +756,7 @@ class AcceptReplInputAction extends EditorAction { } run(accessor: ServicesAccessor, editor: ICodeEditor): void | Promise { - SuggestController.get(editor).cancelSuggestWidget(); + SuggestController.get(editor)?.cancelSuggestWidget(); const repl = getReplView(accessor.get(IViewsService)); repl?.acceptReplInput(); } diff --git a/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts b/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts index 8e8cae61421..b47fcfcec0a 100644 --- a/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts +++ b/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts @@ -41,7 +41,7 @@ export class DefineKeybindingController extends Disposable implements IEditorCon public static readonly ID = 'editor.contrib.defineKeybinding'; - static get(editor: ICodeEditor): DefineKeybindingController { + static get(editor: ICodeEditor): DefineKeybindingController | null { return editor.getContribution(DefineKeybindingController.ID); } @@ -155,7 +155,7 @@ export class KeybindingWidgetRenderer extends Disposable { snippetText = smartInsertInfo.prepend + snippetText + smartInsertInfo.append; this._editor.setPosition(smartInsertInfo.position); - SnippetController2.get(this._editor).insert(snippetText, { overwriteBefore: 0, overwriteAfter: 0 }); + SnippetController2.get(this._editor)?.insert(snippetText, { overwriteBefore: 0, overwriteAfter: 0 }); } } } diff --git a/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts b/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts index 00f34c3fea9..63d2a63ceff 100644 --- a/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts +++ b/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts @@ -556,7 +556,7 @@ export class DirtyDiffController extends Disposable implements IEditorContributi public static readonly ID = 'editor.contrib.dirtydiff'; - static get(editor: ICodeEditor): DirtyDiffController { + static get(editor: ICodeEditor): DirtyDiffController | null { return editor.getContribution(DirtyDiffController.ID); } @@ -1410,7 +1410,9 @@ export class DirtyDiffWorkbenchController extends Disposable implements ext.IWor .map(editor => { const codeEditor = editor as CodeEditorWidget; const controller = DirtyDiffController.get(codeEditor); - controller.modelRegistry = this; + if (controller) { + controller.modelRegistry = this; + } return codeEditor.getModel(); }) diff --git a/src/vs/workbench/contrib/search/browser/searchView.ts b/src/vs/workbench/contrib/search/browser/searchView.ts index 6e08ef59abd..4efb971169f 100644 --- a/src/vs/workbench/contrib/search/browser/searchView.ts +++ b/src/vs/workbench/contrib/search/browser/searchView.ts @@ -23,7 +23,7 @@ import * as strings from 'vs/base/common/strings'; import { withNullAsUndefined } from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; import 'vs/css!./media/searchview'; -import { getCodeEditor, ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; +import { getCodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; @@ -912,8 +912,8 @@ export class SearchView extends ViewPane { updateTextFromFindWidgetOrSelection({ allowUnselectedWord = true, allowSearchOnType = true }): boolean { let activeEditor = this.editorService.activeTextEditorControl; if (isCodeEditor(activeEditor) && !activeEditor?.hasTextFocus()) { - const controller = CommonFindController.get(activeEditor as ICodeEditor); - if (controller.isFindInputFocused()) { + const controller = CommonFindController.get(activeEditor); + if (controller && controller.isFindInputFocused()) { return this.updateTextFromFindWidget(controller, { allowSearchOnType }); } @@ -1748,7 +1748,7 @@ export class SearchView extends ViewPane { const codeEditor = getCodeEditor(editor.getControl()); if (codeEditor) { const multiCursorController = MultiCursorSelectionController.get(codeEditor); - multiCursorController.selectAllUsingSelections(selections); + multiCursorController?.selectAllUsingSelections(selections); } } } diff --git a/src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts b/src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts index 90568d84e5c..fbef2f7a89e 100644 --- a/src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts +++ b/src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts @@ -557,7 +557,7 @@ export class SearchEditor extends BaseTextEditor { } const controller = ReferencesController.get(this.searchResultEditor); - controller.closeWidget(false); + controller?.closeWidget(false); const labelFormatter = (uri: URI): string => this.labelService.getUriLabel(uri, { relative: true }); const results = serializeSearchResultForEditor(this.searchModel.searchResult, startConfig.filesToInclude, startConfig.filesToExclude, startConfig.contextLines, labelFormatter, sortOrder, searchOperation?.limitHit); const { resultsModel } = await input.getModels(); diff --git a/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts b/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts index df0f7ee2307..7e0479f2f24 100644 --- a/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts @@ -144,7 +144,7 @@ class InsertSnippetAction extends EditorAction { if (snippet.needsClipboard) { clipboardText = await clipboardService.readText(); } - SnippetController2.get(editor).insert(snippet.codeSnippet, { clipboardText }); + SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); } private async _pickSnippet(snippetService: ISnippetsService, quickInputService: IQuickInputService, languageId: string): Promise { diff --git a/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts b/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts index db12da69bef..180ced69a13 100644 --- a/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts +++ b/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts @@ -27,7 +27,7 @@ export class TabCompletionController implements IEditorContribution { public static readonly ID = 'editor.tabCompletionController'; static readonly ContextKey = new RawContextKey('hasSnippetCompletions', undefined); - public static get(editor: ICodeEditor): TabCompletionController { + public static get(editor: ICodeEditor): TabCompletionController | null { return editor.getContribution(TabCompletionController.ID); } @@ -140,7 +140,7 @@ export class TabCompletionController implements IEditorContribution { return; } } - SnippetController2.get(this._editor).insert(snippet.codeSnippet, { + SnippetController2.get(this._editor)?.insert(snippet.codeSnippet, { overwriteBefore: snippet.prefix.length, overwriteAfter: 0, clipboardText }); diff --git a/src/vs/workbench/contrib/testing/browser/testingDecorations.ts b/src/vs/workbench/contrib/testing/browser/testingDecorations.ts index 2de88d4f960..b91ca23b4f0 100644 --- a/src/vs/workbench/contrib/testing/browser/testingDecorations.ts +++ b/src/vs/workbench/contrib/testing/browser/testingDecorations.ts @@ -271,7 +271,7 @@ export class TestingDecorations extends Disposable implements IEditorContributio /** * Gets the decorations associated with the given code editor. */ - public static get(editor: ICodeEditor): TestingDecorations { + public static get(editor: ICodeEditor): TestingDecorations | null { return editor.getContribution(Testing.DecorationsContributionId); } @@ -661,15 +661,16 @@ abstract class RunTestDecoration { let actions = this.getContextMenuActions(e); const editor = this.codeEditorService.listCodeEditors().find(e => e.getModel() === this.model); if (editor) { - actions = { - dispose: actions.dispose, - object: Separator.join( - actions.object, - editor - .getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID) - .getContextMenuActionsAtPosition(this.line, this.model) - ) - }; + const contribution = editor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID); + if (contribution) { + actions = { + dispose: actions.dispose, + object: Separator.join( + actions.object, + contribution.getContextMenuActionsAtPosition(this.line, this.model) + ) + }; + } } this.contextMenuService.showContextMenu({ diff --git a/src/vs/workbench/contrib/testing/browser/testingOutputPeek.ts b/src/vs/workbench/contrib/testing/browser/testingOutputPeek.ts index cd6af6cdda4..6f7edfb5a76 100644 --- a/src/vs/workbench/contrib/testing/browser/testingOutputPeek.ts +++ b/src/vs/workbench/contrib/testing/browser/testingOutputPeek.ts @@ -224,7 +224,7 @@ export class TestingPeekOpener extends Disposable implements ITestingPeekOpener } this.lastUri = uri; - TestingOutputPeekController.get(control).show(buildTestUri(this.lastUri)); + TestingOutputPeekController.get(control)?.show(buildTestUri(this.lastUri)); return true; } @@ -377,7 +377,7 @@ export class TestingOutputPeekController extends Disposable implements IEditorCo /** * Gets the controller associated with the given code editor. */ - public static get(editor: ICodeEditor): TestingOutputPeekController { + public static get(editor: ICodeEditor): TestingOutputPeekController | null { return editor.getContribution(Testing.OutputPeekContributionId); } @@ -501,8 +501,8 @@ export class TestingOutputPeekController extends Disposable implements IEditorCo }, this.editor); if (otherEditor) { - TestingOutputPeekController.get(otherEditor).removePeek(); - return TestingOutputPeekController.get(otherEditor).show(uri); + TestingOutputPeekController.get(otherEditor)?.removePeek(); + return TestingOutputPeekController.get(otherEditor)?.show(uri); } } @@ -1050,7 +1050,7 @@ export class CloseTestPeek extends EditorAction2 { runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): void { const parent = getOuterEditorFromDiffEditor(accessor); - TestingOutputPeekController.get(parent ?? editor).removePeek(); + TestingOutputPeekController.get(parent ?? editor)?.removePeek(); } } @@ -1316,7 +1316,7 @@ class OutputPeekTree extends Disposable { if (!dto.revealLocation) { peekController.showInPlace(dto); } else { - TestingOutputPeekController.get(editor).openAndShow(dto.messageUri); + TestingOutputPeekController.get(editor)?.openAndShow(dto.messageUri); } })); @@ -1584,7 +1584,7 @@ const navWhen = ContextKeyExpr.and( * editor is embedded (i.e. inside a peek already). */ const getPeekedEditor = (accessor: ServicesAccessor, editor: ICodeEditor) => { - if (TestingOutputPeekController.get(editor).isVisible) { + if (TestingOutputPeekController.get(editor)?.isVisible) { return editor; } @@ -1626,7 +1626,7 @@ export class GoToNextMessageAction extends EditorAction2 { } public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor) { - TestingOutputPeekController.get(getPeekedEditor(accessor, editor)).next(); + TestingOutputPeekController.get(getPeekedEditor(accessor, editor))?.next(); } } @@ -1656,7 +1656,7 @@ export class GoToPreviousMessageAction extends EditorAction2 { } public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor) { - TestingOutputPeekController.get(getPeekedEditor(accessor, editor)).previous(); + TestingOutputPeekController.get(getPeekedEditor(accessor, editor))?.previous(); } } @@ -1674,7 +1674,7 @@ export class OpenMessageInEditorAction extends EditorAction2 { } public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor) { - TestingOutputPeekController.get(getPeekedEditor(accessor, editor)).openCurrentInEditor(); + TestingOutputPeekController.get(getPeekedEditor(accessor, editor))?.openCurrentInEditor(); } } @@ -1702,6 +1702,8 @@ export class ToggleTestingPeekHistory extends EditorAction2 { public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor) { const ctrl = TestingOutputPeekController.get(getPeekedEditor(accessor, editor)); - ctrl.historyVisible.value = !ctrl.historyVisible.value; + if (ctrl) { + ctrl.historyVisible.value = !ctrl.historyVisible.value; + } } } diff --git a/src/vs/workbench/contrib/typeHierarchy/browser/typeHierarchy.contribution.ts b/src/vs/workbench/contrib/typeHierarchy/browser/typeHierarchy.contribution.ts index 1737c94a2b4..9b16dbfab2c 100644 --- a/src/vs/workbench/contrib/typeHierarchy/browser/typeHierarchy.contribution.ts +++ b/src/vs/workbench/contrib/typeHierarchy/browser/typeHierarchy.contribution.ts @@ -38,7 +38,7 @@ function sanitizedDirection(candidate: string): TypeHierarchyDirection { class TypeHierarchyController implements IEditorContribution { static readonly Id = 'typeHierarchy'; - static get(editor: ICodeEditor): TypeHierarchyController { + static get(editor: ICodeEditor): TypeHierarchyController | null { return editor.getContribution(TypeHierarchyController.Id); } @@ -140,7 +140,7 @@ class TypeHierarchyController implements IEditorContribution { const newModel = model.fork(typeItem.item); this._sessionDisposables.clear(); - TypeHierarchyController.get(newEditor)._showTypeHierarchyWidget( + TypeHierarchyController.get(newEditor)?._showTypeHierarchyWidget( Range.lift(newModel.root.selectionRange).getStartPosition(), this._widget.direction, Promise.resolve(newModel), @@ -191,7 +191,7 @@ registerAction2(class extends EditorAction2 { } async runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { - return TypeHierarchyController.get(editor).startTypeHierarchyFromEditor(); + return TypeHierarchyController.get(editor)?.startTypeHierarchyFromEditor(); } }); @@ -217,7 +217,7 @@ registerAction2(class extends EditorAction2 { } runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) { - return TypeHierarchyController.get(editor).showSupertypes(); + return TypeHierarchyController.get(editor)?.showSupertypes(); } }); @@ -242,7 +242,7 @@ registerAction2(class extends EditorAction2 { } runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) { - return TypeHierarchyController.get(editor).showSubtypes(); + return TypeHierarchyController.get(editor)?.showSubtypes(); } }); @@ -261,7 +261,7 @@ registerAction2(class extends EditorAction2 { } async runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor): Promise { - return TypeHierarchyController.get(editor).startTypeHierarchyFromTypeHierarchy(); + return TypeHierarchyController.get(editor)?.startTypeHierarchyFromTypeHierarchy(); } }); @@ -288,6 +288,6 @@ registerAction2(class extends EditorAction2 { } runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor): void { - return TypeHierarchyController.get(editor).endTypeHierarchy(); + return TypeHierarchyController.get(editor)?.endTypeHierarchy(); } }); diff --git a/src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts b/src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts index 605bfae3029..609f3618e06 100644 --- a/src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts +++ b/src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts @@ -1302,7 +1302,7 @@ class UserDataRemoteContentProvider implements ITextModelContentProvider { class AcceptChangesContribution extends Disposable implements IEditorContribution { - static get(editor: ICodeEditor): AcceptChangesContribution { + static get(editor: ICodeEditor): AcceptChangesContribution | null { return editor.getContribution(AcceptChangesContribution.ID); } diff --git a/src/vs/workbench/contrib/userDataSync/browser/userDataSyncMergesView.ts b/src/vs/workbench/contrib/userDataSync/browser/userDataSyncMergesView.ts index 699f7be30da..fc5f376f6b7 100644 --- a/src/vs/workbench/contrib/userDataSync/browser/userDataSyncMergesView.ts +++ b/src/vs/workbench/contrib/userDataSync/browser/userDataSyncMergesView.ts @@ -417,7 +417,7 @@ type AcceptChangesClassification = { class AcceptChangesContribution extends Disposable implements IEditorContribution { - static get(editor: ICodeEditor): AcceptChangesContribution { + static get(editor: ICodeEditor): AcceptChangesContribution | null { return editor.getContribution(AcceptChangesContribution.ID); }