From 2eac83315d29b4ff58b06bbef1b17a1944da4b8b Mon Sep 17 00:00:00 2001 From: Oleg Solomko Date: Thu, 30 Jan 2025 10:30:00 -0800 Subject: [PATCH] [config]: fix source location resolution for top-level folders of a workspace --- .../chatInstructionsFileLocator.ts | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts index 577e38c7c8164..74e2292ad9e26 100644 --- a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts +++ b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts @@ -63,21 +63,26 @@ export class ChatInstructionsFileLocator { // otherwise for each folder provided in the configuration, create // a URI per each folder in the current workspace const { folders } = this.workspaceService.getWorkspace(); + const workspaceRootUri = dirname(folders[0].uri); for (const folder of folders) { for (const sourceFolderName of sourceLocations) { - const folderUri = extUri.resolvePath(folder.uri, sourceFolderName); - result.push(folderUri); - } - } + // create the source path as a path relative to the workspace + // folder, or as an absolute path if the absolute value is provided + const sourceFolderUri = extUri.resolvePath(folder.uri, sourceFolderName); + result.push(sourceFolderUri); - // if inside a workspace, add the specified source locations inside the workspace - // root too, to allow users to use `.copilot/prompts` folder (or whatever they - // specify in the setting) in the workspace root - if (folders.length > 1) { - const workspaceRootUri = dirname(folders[0].uri); - for (const sourceFolderName of sourceLocations) { - const folderUri = extUri.resolvePath(workspaceRootUri, sourceFolderName); - result.push(folderUri); + // if not inside a workspace, we are done + if (folders.length <= 1) { + continue; + } + + // if inside a workspace, consider the specified source location inside + // the workspace root, to allow users to use some (e.g., `.github/prompts`) + // folder as a top-level folder in the workspace + const workspaceFolderUri = extUri.resolvePath(workspaceRootUri, sourceFolderName); + if (workspaceFolderUri.fsPath.startsWith(folder.uri.fsPath)) { + result.push(workspaceFolderUri); + } } }