Skip to content

Commit 5b91a21

Browse files
authored
promptFileLocator: Use ISearchService (microsoft#249901)
* promptFIleLocator: Use ISearchService * polish
1 parent 42f0f08 commit 5b91a21

File tree

8 files changed

+363
-386
lines changed

8 files changed

+363
-386
lines changed

src/vs/workbench/contrib/chat/browser/actions/promptActions/chatAttachInstructionsAction.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { KeyMod, KeyCode } from '../../../../../../base/common/keyCodes.js';
3131
import { KeybindingWeight } from '../../../../../../platform/keybinding/common/keybindingsRegistry.js';
3232
import { ICodeEditorService } from '../../../../../../editor/browser/services/codeEditorService.js';
3333
import { INSTRUCTIONS_LANGUAGE_ID } from '../../../common/promptSyntax/constants.js';
34+
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
3435

3536
/**
3637
* Action ID for the `Attach Instruction` action.
@@ -130,7 +131,7 @@ class AttachInstructionsAction extends Action2 {
130131
}
131132

132133
// find all prompt files in the user workspace
133-
const promptFiles = await promptsService.listPromptFiles(PromptsType.instructions);
134+
const promptFiles = await promptsService.listPromptFiles(PromptsType.instructions, CancellationToken.None);
134135
const placeholder = localize(
135136
'commands.instructions.select-dialog.placeholder',
136137
'Select instructions files to attach',
@@ -202,7 +203,7 @@ export class ChatInstructionsPickerPick implements IChatContextPickerItem {
202203

203204
asPicker(): { readonly placeholder: string; readonly picks: Promise<ChatContextPick[]> } {
204205

205-
const picks = this.promptsService.listPromptFiles(PromptsType.instructions).then(value => {
206+
const picks = this.promptsService.listPromptFiles(PromptsType.instructions, CancellationToken.None).then(value => {
206207

207208
const result: (IChatContextPickerPickItem | IQuickPickSeparator)[] = [];
208209

src/vs/workbench/contrib/chat/browser/actions/promptActions/chatModeActions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Action2, MenuId, registerAction2 } from '../../../../../../platform/act
1616
import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js';
1717
import { PromptsType } from '../../../../../../platform/prompts/common/prompts.js';
1818
import { IOpenerService } from '../../../../../../platform/opener/common/opener.js';
19+
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
1920

2021
/**
2122
* Action ID for the `Manage Custom Chat Mode` action.
@@ -51,7 +52,7 @@ class ManageModeAction extends Action2 {
5152
const pickers = instaService.createInstance(PromptFilePickers);
5253

5354
// find all prompt files in the user workspace
54-
const promptFiles = await promptsService.listPromptFiles(PromptsType.mode);
55+
const promptFiles = await promptsService.listPromptFiles(PromptsType.mode, CancellationToken.None);
5556
const placeholder = localize(
5657
'commands.mode.select-dialog.placeholder',
5758
'Select the custom chat mode to edit'

src/vs/workbench/contrib/chat/browser/actions/promptActions/chatRunPromptAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { KeybindingWeight } from '../../../../../../platform/keybinding/common/k
3131
import { Action2, MenuId, registerAction2 } from '../../../../../../platform/actions/common/actions.js';
3232
import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js';
3333
import { PromptsType } from '../../../../../../platform/prompts/common/prompts.js';
34+
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
3435

3536
/**
3637
* Condition for the `Run Current Prompt` action.
@@ -209,7 +210,7 @@ class RunSelectedPromptAction extends Action2 {
209210
const pickers = instaService.createInstance(PromptFilePickers);
210211

211212
// find all prompt files in the user workspace
212-
const promptFiles = await promptsService.listPromptFiles(PromptsType.prompt);
213+
const promptFiles = await promptsService.listPromptFiles(PromptsType.prompt, CancellationToken.None);
213214
const placeholder = localize(
214215
'commands.prompt.select-dialog.placeholder',
215216
'Select the prompt file to run (hold {0}-key to use in new chat)',

src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsService.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { IInstantiationService } from '../../../../../../platform/instantiation/
2828
import { IUserDataProfileService } from '../../../../../services/userDataProfile/common/userDataProfile.js';
2929
import type { IChatPromptSlashCommand, ICustomChatMode, IMetadata, IPromptPath, IPromptsService, TPromptsStorage } from './types.js';
3030
import { Emitter, Event } from '../../../../../../base/common/event.js';
31+
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
3132

3233
/**
3334
* Provides prompt services.
@@ -111,13 +112,11 @@ export class PromptsService extends Disposable implements IPromptsService {
111112
return this.cache.get(model);
112113
}
113114

114-
public async listPromptFiles(type: PromptsType): Promise<readonly IPromptPath[]> {
115-
const userLocations = [this.userDataService.currentProfile.promptsHome];
116-
115+
public async listPromptFiles(type: PromptsType, token: CancellationToken): Promise<readonly IPromptPath[]> {
117116
const prompts = await Promise.all([
118-
this.fileLocator.listFilesIn(userLocations, type)
117+
this.fileLocator.listFiles(type, 'user', token)
119118
.then(withType('user', type)),
120-
this.fileLocator.listFiles(type)
119+
this.fileLocator.listFiles(type, 'local', token)
121120
.then(withType('local', type)),
122121
]);
123122

@@ -160,7 +159,7 @@ export class PromptsService extends Disposable implements IPromptsService {
160159
return data.promptPath.uri;
161160
}
162161

163-
const files = await this.listPromptFiles(PromptsType.prompt);
162+
const files = await this.listPromptFiles(PromptsType.prompt, CancellationToken.None);
164163
const command = data.command;
165164
const result = files.find(file => getPromptCommandName(file.uri.path) === command);
166165
if (result) {
@@ -174,7 +173,7 @@ export class PromptsService extends Disposable implements IPromptsService {
174173
}
175174

176175
public async findPromptSlashCommands(): Promise<IChatPromptSlashCommand[]> {
177-
const promptFiles = await this.listPromptFiles(PromptsType.prompt);
176+
const promptFiles = await this.listPromptFiles(PromptsType.prompt, CancellationToken.None);
178177
return promptFiles.map(promptPath => {
179178
const command = getPromptCommandName(promptPath.uri.path);
180179
return {
@@ -190,7 +189,7 @@ export class PromptsService extends Disposable implements IPromptsService {
190189
public readonly onDidChangeCustomChatModes: Event<void> = this._onDidChangeCustomChatModesEmitter.event;
191190

192191
public async getCustomChatModes(): Promise<readonly ICustomChatMode[]> {
193-
const modeFiles = await this.listPromptFiles(PromptsType.mode);
192+
const modeFiles = await this.listPromptFiles(PromptsType.mode, CancellationToken.None);
194193
const metaDatas = await this.getAllMetadata(modeFiles.map(promptPath => promptPath.uri));
195194
return metaDatas.map(metadata => {
196195
return {
@@ -206,7 +205,7 @@ export class PromptsService extends Disposable implements IPromptsService {
206205
public async findInstructionFilesFor(
207206
files: readonly URI[],
208207
): Promise<readonly URI[]> {
209-
const instructionFiles = await this.listPromptFiles(PromptsType.instructions);
208+
const instructionFiles = await this.listPromptFiles(PromptsType.instructions, CancellationToken.None);
210209
if (instructionFiles.length === 0) {
211210
return [];
212211
}

src/vs/workbench/contrib/chat/common/promptSyntax/service/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TextModelPromptParser } from '../parsers/textModelPromptParser.js';
1313
import { createDecorator } from '../../../../../../platform/instantiation/common/instantiation.js';
1414
import { PromptsType } from '../../../../../../platform/prompts/common/prompts.js';
1515
import { Event } from '../../../../../../base/common/event.js';
16+
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
1617

1718
/**
1819
* Provides prompt services.
@@ -152,7 +153,7 @@ export interface IPromptsService extends IDisposable {
152153
/**
153154
* List all available prompt files.
154155
*/
155-
listPromptFiles(type: PromptsType): Promise<readonly IPromptPath[]>;
156+
listPromptFiles(type: PromptsType, token: CancellationToken): Promise<readonly IPromptPath[]>;
156157

157158
/**
158159
* Get a list of prompt source folders based on the provided prompt type.

0 commit comments

Comments
 (0)