From db5e776d713d00c0615d84b78eaa8b9a986cb779 Mon Sep 17 00:00:00 2001 From: Oleg Solomko Date: Thu, 9 Jan 2025 15:05:03 -0800 Subject: [PATCH] [instruction attachments]: include worspace folder names when resolving specified prompt instruction file locations --- .../chatInstructionsFileLocator.ts | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts index 9f0532270ff..e31f5e0fe83 100644 --- a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts +++ b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { URI } from '../../../../../base/common/uri.js'; +import { dirname, extUri } from '../../../../../base/common/resources.js'; import { IFileService } from '../../../../../platform/files/common/files.js'; import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js'; import { IWorkspaceContextService, WorkbenchState } from '../../../../../platform/workspace/common/workspace.js'; @@ -69,13 +70,26 @@ export class ChatInstructionsFileLocator { return []; } + const sourceLocations = this.getSourceLocationsConfigValue(); + const result = []; + // otherwise for each folder provided in the configuration, create // a URI per each folder in the current workspace - const result = []; const { folders } = this.workspaceService.getWorkspace(); for (const folder of folders) { - for (const folderName of this.getSourceLocationsConfigValue()) { - const folderUri = URI.joinPath(folder.uri, folderName); + for (const sourceFolderName of sourceLocations) { + const folderUri = extUri.resolvePath(folder.uri, sourceFolderName); + result.push(folderUri); + } + } + + // 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); } }