Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/commands/node/commandService.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { ChatLocation } from '../../../platform/chat/common/commonTypes';
7
import { createServiceIdentifier } from '../../../util/common/services';
8
import { IIntentService } from '../../intents/node/intentService';
9
import { CommandDetails } from '../../prompt/node/intentRegistry';
10
11
export const ICommandService = createServiceIdentifier<ICommandService>('ICommandService');
12
13
export interface ICommandService {
14
readonly _serviceBrand: undefined;
15
getCommands(location: ChatLocation): CommandDetails[];
16
getCommand(commandId: string, location: ChatLocation): CommandDetails | undefined;
17
}
18
19
export class CommandServiceImpl implements ICommandService {
20
21
declare _serviceBrand: undefined;
22
23
24
constructor(
25
@IIntentService private readonly intentService: IIntentService
26
) { }
27
28
public getCommands(location: ChatLocation): CommandDetails[] {
29
return this.intentService.getIntents(location)
30
.filter(candidate => !candidate.commandInfo || !candidate.commandInfo.hiddenFromUser)
31
.map(intent => ({ commandId: intent.id, intent, details: intent.description, locations: intent.locations, toolEquivalent: intent.commandInfo?.toolEquivalent } satisfies CommandDetails));
32
}
33
34
public getCommand(id: string, location: ChatLocation): CommandDetails | undefined {
35
return this.getCommands(location).find(c => c.commandId === id);
36
}
37
}
38
39