Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix prompt file resolve logic for empty workspaces #239508

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Loading