Skip to content

Commit

Permalink
[config]: fix source location resolution for top-level folders of a w…
Browse files Browse the repository at this point in the history
…orkspace
  • Loading branch information
legomushroom committed Jan 30, 2025
1 parent 66772c0 commit 2eac833
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 2eac833

Please sign in to comment.