Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotCLISkills.ts
13405 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 type { Uri } from 'vscode';
7
import { IConfigurationService } from '../../../../platform/configuration/common/configurationService';
8
import { INativeEnvService } from '../../../../platform/env/common/envService';
9
import { ILogService } from '../../../../platform/log/common/logService';
10
import { IWorkspaceService } from '../../../../platform/workspace/common/workspaceService';
11
import { createServiceIdentifier } from '../../../../util/common/services';
12
import { Disposable } from '../../../../util/vs/base/common/lifecycle';
13
import { ResourceSet } from '../../../../util/vs/base/common/map';
14
import { Schemas } from '../../../../util/vs/base/common/network';
15
import { dirname } from '../../../../util/vs/base/common/resources';
16
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';
17
import { IPromptsService } from '../../../../platform/promptFiles/common/promptsService';
18
import { CancellationToken } from '../../../../util/vs/base/common/cancellation';
19
import { isEnabledForCopilotCLI } from './copilotCli';
20
import { resolveSkillConfigLocations } from '../../common/skillConfigLocations';
21
22
export interface ICopilotCLISkills {
23
readonly _serviceBrand: undefined;
24
getSkillsLocations(token: CancellationToken): Promise<Uri[]>;
25
}
26
27
export const ICopilotCLISkills = createServiceIdentifier<ICopilotCLISkills>('ICopilotCLISkills');
28
29
export class CopilotCLISkills extends Disposable implements ICopilotCLISkills {
30
declare _serviceBrand: undefined;
31
constructor(
32
@ILogService protected readonly logService: ILogService,
33
@IInstantiationService protected readonly instantiationService: IInstantiationService,
34
@IConfigurationService private readonly configurationService: IConfigurationService,
35
@INativeEnvService private readonly envService: INativeEnvService,
36
@IWorkspaceService private readonly workspaceService: IWorkspaceService,
37
@IPromptsService private readonly promptsService: IPromptsService,
38
) {
39
super();
40
}
41
42
public async getSkillsLocations(token: CancellationToken): Promise<Uri[]> {
43
const configSkillLocationUris = new ResourceSet();
44
for (const uri of resolveSkillConfigLocations(this.configurationService, this.envService, this.workspaceService)) {
45
configSkillLocationUris.add(uri);
46
}
47
(await this.promptsService.getSkills(token))
48
.filter(isEnabledForCopilotCLI)
49
.filter(s => s.uri.scheme === Schemas.file)
50
.map(s => s.uri)
51
.map(uri => dirname(dirname(uri)))
52
.forEach(uri => configSkillLocationUris.add(uri));
53
54
return Array.from(configSkillLocationUris);
55
}
56
}
57
58