Path: blob/main/extensions/copilot/src/platform/promptFiles/test/common/mockPromptsService.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type { ChatCustomAgent, ChatHook, ChatInstruction, ChatPlugin, ChatSkill, ChatSlashCommand } from 'vscode';6import { CancellationToken } from '../../../../util/vs/base/common/cancellation';7import { Emitter, Event } from '../../../../util/vs/base/common/event';8import { Disposable } from '../../../../util/vs/base/common/lifecycle';9import { URI } from '../../../../util/vs/base/common/uri';10import { PromptFileParser } from '../../../../util/vs/workbench/contrib/chat/common/promptSyntax/promptFileParser';11import { IPromptsService, ParsedPromptFile } from '../../common/promptsService';12import { ResourceMap } from '../../../../util/vs/base/common/map';1314export class MockPromptsService extends Disposable implements IPromptsService {15declare readonly _serviceBrand: undefined;1617private readonly _onDidChangeCustomAgents = this._register(new Emitter<void>());18readonly onDidChangeCustomAgents: Event<void> = this._onDidChangeCustomAgents.event;1920private readonly _onDidChangeInstructions = this._register(new Emitter<void>());21readonly onDidChangeInstructions: Event<void> = this._onDidChangeInstructions.event;2223private readonly _onDidChangeSkills = this._register(new Emitter<void>());24readonly onDidChangeSkills: Event<void> = this._onDidChangeSkills.event;2526private readonly _onDidChangeHooks = this._register(new Emitter<void>());27readonly onDidChangeHooks: Event<void> = this._onDidChangeHooks.event;2829private readonly _onDidChangePlugins = this._register(new Emitter<void>());30readonly onDidChangePlugins: Event<void> = this._onDidChangePlugins.event;3132private _customAgents: readonly ChatCustomAgent[] = [];33private _slashCommands: readonly ChatSlashCommand[] = [];34private _instructions: readonly ChatInstruction[] = [];35private _skills: readonly ChatSkill[] = [];36private _hooks: readonly ChatHook[] = [];37private _plugins: readonly ChatPlugin[] = [];38private _fileContents = new ResourceMap<string>();3940setCustomAgents(agents: readonly ChatCustomAgent[]): void {41this._customAgents = agents;42this._onDidChangeCustomAgents.fire();43}4445fireCustomAgentsChanged(): void {46this._onDidChangeCustomAgents.fire();47}4849setSlashCommands(commands: readonly ChatSlashCommand[]): void {50this._slashCommands = commands;51}5253setInstructions(instructions: readonly ChatInstruction[]): void {54this._instructions = instructions;55this._onDidChangeInstructions.fire();56}5758fireInstructionsChanged(): void {59this._onDidChangeInstructions.fire();60}6162setSkills(skills: readonly ChatSkill[]): void {63this._skills = skills;64this._onDidChangeSkills.fire();65}6667fireSkillsChanged(): void {68this._onDidChangeSkills.fire();69}7071setHooks(hooks: readonly ChatHook[]): void {72this._hooks = hooks;73this._onDidChangeHooks.fire();74}7576firePluginsChanged(): void {77this._onDidChangePlugins.fire();78}7980setPlugins(plugins: readonly ChatPlugin[]): void {81this._plugins = plugins;82this._onDidChangePlugins.fire();83}8485getCustomAgents(_token: CancellationToken): Promise<readonly ChatCustomAgent[]> {86return Promise.resolve(this._customAgents);87}8889getSlashCommands(_token: CancellationToken): Promise<readonly ChatSlashCommand[]> {90return Promise.resolve(this._slashCommands);91}9293getInstructions(_token: CancellationToken): Promise<readonly ChatInstruction[]> {94return Promise.resolve(this._instructions);95}9697getSkills(_token: CancellationToken): Promise<readonly ChatSkill[]> {98return Promise.resolve(this._skills);99}100101getHooks(_token: CancellationToken): Promise<readonly ChatHook[]> {102return Promise.resolve(this._hooks);103}104105fireHooksChanged(): void {106this._onDidChangeHooks.fire();107}108109getPlugins(_token: CancellationToken): Promise<readonly ChatPlugin[]> {110return Promise.resolve(this._plugins);111}112113/** Register content so parseFile returns a parsed result for the given URI. */114setFileContent(uri: URI, content: string) {115this._fileContents.set(uri, content);116}117118parseFile(uri: URI, _token: CancellationToken): Promise<ParsedPromptFile> {119const content = this._fileContents.get(uri) ?? '';120return Promise.resolve(new PromptFileParser().parse(uri, content));121}122}123124125