diff --git a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts index 99d0cf7dd3bc7..2d09533d6725d 100644 --- a/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts +++ b/src/vs/workbench/contrib/chat/browser/chatAttachmentModel/chatInstructionsFileLocator.ts @@ -7,8 +7,8 @@ import { URI } from '../../../../../base/common/uri.js'; import { PromptFilesConfig } from '../../common/promptSyntax/config.js'; import { dirname, extUri } from '../../../../../base/common/resources.js'; import { IFileService } from '../../../../../platform/files/common/files.js'; +import { IWorkspaceContextService } from '../../../../../platform/workspace/common/workspace.js'; import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js'; -import { IWorkspaceContextService, WorkbenchState } from '../../../../../platform/workspace/common/workspace.js'; import { PROMPT_SNIPPET_FILE_EXTENSION } from '../../common/promptSyntax/contentProviders/promptContentsProviderBase.js'; /** @@ -50,26 +50,26 @@ export class ChatInstructionsFileLocator { * @returns List of possible prompt instructions file locations. */ private getSourceLocations(): readonly URI[] { - const state = this.workspaceService.getWorkbenchState(); - - // nothing to do if the workspace is empty - if (state === WorkbenchState.EMPTY) { - return []; - } - const sourceLocations = PromptFilesConfig.sourceLocations(this.configService); const result = []; // 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) { + for (const sourceFolderName of sourceLocations) { + // if source folder is an absolute path, add the path as is + // without trying to resolve it against the workspace folders + const sourceFolderUri = URI.file(sourceFolderName); + if (sourceFolderUri.path === sourceFolderName) { + result.push(sourceFolderUri); + continue; + } + + const { folders } = this.workspaceService.getWorkspace(); + for (const folder of folders) { // 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); + const relativeFolderUri = extUri.resolvePath(folder.uri, sourceFolderName); + result.push(relativeFolderUri); // if not inside a workspace, we are done if (folders.length <= 1) { @@ -79,6 +79,7 @@ export class ChatInstructionsFileLocator { // 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 workspaceRootUri = dirname(folders[0].uri); const workspaceFolderUri = extUri.resolvePath(workspaceRootUri, sourceFolderName); if (workspaceFolderUri.fsPath.startsWith(folder.uri.fsPath)) { result.push(workspaceFolderUri);