Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chatSessions/common/skillConfigLocations.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 { IConfigurationService } from '../../../platform/configuration/common/configurationService';
7
import { SKILLS_LOCATION_KEY } from '../../../platform/customInstructions/common/promptTypes';
8
import { INativeEnvService } from '../../../platform/env/common/envService';
9
import { IWorkspaceService } from '../../../platform/workspace/common/workspaceService';
10
import { isAbsolute } from '../../../util/vs/base/common/path';
11
import { isObject } from '../../../util/vs/base/common/types';
12
import { URI } from '../../../util/vs/base/common/uri';
13
14
/**
15
* Resolves skill directory locations from the `chat.agentSkillsLocations` config setting.
16
* Handles `~/` expansion, absolute paths, and relative paths (joined to each workspace folder).
17
*/
18
export function resolveSkillConfigLocations(
19
configurationService: IConfigurationService,
20
envService: INativeEnvService,
21
workspaceService: IWorkspaceService,
22
): URI[] {
23
const results: URI[] = [];
24
const locations = configurationService.getNonExtensionConfig<Record<string, boolean>>(SKILLS_LOCATION_KEY);
25
if (!isObject(locations)) {
26
return results;
27
}
28
29
const userHome = envService.userHome;
30
const workspaceFolders = workspaceService.getWorkspaceFolders();
31
for (const key in locations) {
32
const location = key.trim();
33
if (locations[key] !== true) {
34
continue;
35
}
36
if (location.startsWith('~/')) {
37
results.push(URI.joinPath(userHome, location.substring(2)));
38
} else if (isAbsolute(location)) {
39
results.push(URI.file(location));
40
} else {
41
for (const workspaceFolder of workspaceFolders) {
42
results.push(URI.joinPath(workspaceFolder, location));
43
}
44
}
45
}
46
47
return results;
48
}
49
50