/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { Emitter, Event } from '../../../../vs/base/common/event'; import { ICodeEditor } from '../../../../vs/editor/browser/editorBrowser'; import { AbstractCodeEditorService } from '../../../../vs/editor/browser/services/abstractCodeEditorService'; import { IDecorationRenderOptions } from '../../../../vs/editor/common/editorCommon'; import { IModelDecorationOptions } from '../../../../vs/editor/common/model'; import { CommandsRegistry, ICommandEvent, ICommandService, } from '../../../../vs/platform/commands/common/commands'; import { IResourceEditorInput } from '../../../../vs/platform/editor/common/editor'; import { IInstantiationService } from '../../../../vs/platform/instantiation/common/instantiation'; export class TestCodeEditorService extends AbstractCodeEditorService { public lastInput?: IResourceEditorInput; public getActiveCodeEditor(): ICodeEditor | null { return null; } public openCodeEditor( input: IResourceEditorInput, source: ICodeEditor | null, sideBySide?: boolean ): Promise { this.lastInput = input; return Promise.resolve(null); } public registerDecorationType( description: string, key: string, options: IDecorationRenderOptions, parentTypeKey?: string ): void {} public removeDecorationType(key: string): void {} public resolveDecorationOptions( decorationTypeKey: string, writable: boolean ): IModelDecorationOptions { return { description: 'test' }; } public resolveDecorationCSSRules( decorationTypeKey: string ): CSSRuleList | null { return null; } } export class TestCommandService implements ICommandService { declare readonly _serviceBrand: undefined; private readonly _instantiationService: IInstantiationService; private readonly _onWillExecuteCommand = new Emitter(); public readonly onWillExecuteCommand: Event = this._onWillExecuteCommand.event; private readonly _onDidExecuteCommand = new Emitter(); public readonly onDidExecuteCommand: Event = this._onDidExecuteCommand.event; constructor(instantiationService: IInstantiationService) { this._instantiationService = instantiationService; } public executeCommand(id: string, ...args: any[]): Promise { const command = CommandsRegistry.getCommand(id); if (!command) { return Promise.reject(new Error(`command '${id}' not found`)); } try { this._onWillExecuteCommand.fire({ commandId: id, args }); const result = this._instantiationService.invokeFunction.apply( this._instantiationService, [command.handler, ...args] ) as T; this._onDidExecuteCommand.fire({ commandId: id, args }); return Promise.resolve(result); } catch (err) { return Promise.reject(err); } } }