Skip to content

Commit ec485c8

Browse files
authored
[prompts][config]: fix source location resolution for top-level folders of a workspace (microsoft#239245)
[config]: fix source location resolution for top-level folders of a workspace
1 parent 77afd22 commit ec485c8

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,26 @@ export class ChatInstructionsFileLocator {
6363
// otherwise for each folder provided in the configuration, create
6464
// a URI per each folder in the current workspace
6565
const { folders } = this.workspaceService.getWorkspace();
66+
const workspaceRootUri = dirname(folders[0].uri);
6667
for (const folder of folders) {
6768
for (const sourceFolderName of sourceLocations) {
68-
const folderUri = extUri.resolvePath(folder.uri, sourceFolderName);
69-
result.push(folderUri);
70-
}
71-
}
69+
// create the source path as a path relative to the workspace
70+
// folder, or as an absolute path if the absolute value is provided
71+
const sourceFolderUri = extUri.resolvePath(folder.uri, sourceFolderName);
72+
result.push(sourceFolderUri);
7273

73-
// if inside a workspace, add the specified source locations inside the workspace
74-
// root too, to allow users to use `.copilot/prompts` folder (or whatever they
75-
// specify in the setting) in the workspace root
76-
if (folders.length > 1) {
77-
const workspaceRootUri = dirname(folders[0].uri);
78-
for (const sourceFolderName of sourceLocations) {
79-
const folderUri = extUri.resolvePath(workspaceRootUri, sourceFolderName);
80-
result.push(folderUri);
74+
// if not inside a workspace, we are done
75+
if (folders.length <= 1) {
76+
continue;
77+
}
78+
79+
// if inside a workspace, consider the specified source location inside
80+
// the workspace root, to allow users to use some (e.g., `.github/prompts`)
81+
// folder as a top-level folder in the workspace
82+
const workspaceFolderUri = extUri.resolvePath(workspaceRootUri, sourceFolderName);
83+
if (workspaceFolderUri.fsPath.startsWith(folder.uri.fsPath)) {
84+
result.push(workspaceFolderUri);
85+
}
8186
}
8287
}
8388

0 commit comments

Comments
 (0)