-
Notifications
You must be signed in to change notification settings - Fork 39.3k
Expand file tree
/
Copy pathcopilotCLISkills.ts
More file actions
80 lines (74 loc) · 3.72 KB
/
copilotCLISkills.ts
File metadata and controls
80 lines (74 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { Uri } from 'vscode';
import { IConfigurationService } from '../../../../platform/configuration/common/configurationService';
import { SKILLS_LOCATION_KEY } from '../../../../platform/customInstructions/common/promptTypes';
import { INativeEnvService } from '../../../../platform/env/common/envService';
import { ILogService } from '../../../../platform/log/common/logService';
import { IWorkspaceService } from '../../../../platform/workspace/common/workspaceService';
import { createServiceIdentifier } from '../../../../util/common/services';
import { Disposable } from '../../../../util/vs/base/common/lifecycle';
import { ResourceSet } from '../../../../util/vs/base/common/map';
import { Schemas } from '../../../../util/vs/base/common/network';
import { isAbsolute } from '../../../../util/vs/base/common/path';
import {
dirname
} from '../../../../util/vs/base/common/resources';
import { isObject } from '../../../../util/vs/base/common/types';
import { URI } from '../../../../util/vs/base/common/uri';
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';
import { IPromptsService } from '../../../../platform/promptFiles/common/promptsService';
import { CancellationToken } from '../../../../util/vs/base/common/cancellation';
export interface ICopilotCLISkills {
readonly _serviceBrand: undefined;
getSkillsLocations(token: CancellationToken): Promise<Uri[]>;
}
export const ICopilotCLISkills = createServiceIdentifier<ICopilotCLISkills>('ICopilotCLISkills');
export class CopilotCLISkills extends Disposable implements ICopilotCLISkills {
declare _serviceBrand: undefined;
constructor(
@ILogService protected readonly logService: ILogService,
@IInstantiationService protected readonly instantiationService: IInstantiationService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@INativeEnvService private readonly envService: INativeEnvService,
@IWorkspaceService private readonly workspaceService: IWorkspaceService,
@IPromptsService private readonly promptsService: IPromptsService,
) {
super();
}
public async getSkillsLocations(token: CancellationToken): Promise<Uri[]> {
// Get additional skill locations from config
const configSkillLocationUris = new ResourceSet();
const locations = this.configurationService.getNonExtensionConfig<Record<string, boolean>>(SKILLS_LOCATION_KEY);
const userHome = this.envService.userHome;
const workspaceFolders = this.workspaceService.getWorkspaceFolders();
if (isObject(locations)) {
for (const key in locations) {
const location = key.trim();
const value = locations[key];
if (value !== true) {
continue;
}
// Expand ~/ to user home directory
if (location.startsWith('~/')) {
configSkillLocationUris.add(URI.joinPath(userHome, location.substring(2)));
} else if (isAbsolute(location)) {
configSkillLocationUris.add(URI.file(location));
} else {
// Relative path - join to each workspace folder
for (const workspaceFolder of workspaceFolders) {
configSkillLocationUris.add(URI.joinPath(workspaceFolder, location));
}
}
}
}
(await this.promptsService.getSkills(token))
.filter(s => s.uri.scheme === Schemas.file)
.map(s => s.uri)
.map(uri => dirname(dirname(uri)))
.forEach(uri => configSkillLocationUris.add(uri));
return Array.from(configSkillLocationUris);
}
}