44 *--------------------------------------------------------------------------------------------*/
55
66import { localize } from '../../../../../../nls.js' ;
7- import { getPromptsTypeForLanguageId , isValidPromptType , PROMPT_LANGUAGE_ID , PromptsType } from '../promptTypes.js' ;
7+ import { getPromptsTypeForLanguageId , PROMPT_LANGUAGE_ID , PromptsType } from '../promptTypes.js' ;
88import { PromptParser } from '../parsers/promptParser.js' ;
99import { match , splitGlobAware } from '../../../../../../base/common/glob.js' ;
1010import { type URI } from '../../../../../../base/common/uri.js' ;
@@ -27,6 +27,8 @@ import { IUserDataProfileService } from '../../../../../services/userDataProfile
2727import type { IChatPromptSlashCommand , ICustomChatMode , IMetadata , IPromptParserResult , IPromptPath , IPromptsService , TPromptsStorage } from './promptsService.js' ;
2828import { getCleanPromptName , PROMPT_FILE_EXTENSION } from '../config/promptFileLocations.js' ;
2929import { ILanguageService } from '../../../../../../editor/common/languages/language.js' ;
30+ import { PromptsConfig } from '../config/config.js' ;
31+ import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js' ;
3032
3133/**
3234 * Provides prompt services.
@@ -57,6 +59,7 @@ export class PromptsService extends Disposable implements IPromptsService {
5759 @IInstantiationService private readonly instantiationService : IInstantiationService ,
5860 @IUserDataProfileService private readonly userDataService : IUserDataProfileService ,
5961 @ILanguageService private readonly languageService : ILanguageService ,
62+ @IConfigurationService private readonly configurationService : IConfigurationService ,
6063 ) {
6164 super ( ) ;
6265
@@ -126,6 +129,10 @@ export class PromptsService extends Disposable implements IPromptsService {
126129 }
127130
128131 public async listPromptFiles ( type : PromptsType , token : CancellationToken ) : Promise < readonly IPromptPath [ ] > {
132+ if ( ! PromptsConfig . enabled ( this . configurationService ) ) {
133+ return [ ] ;
134+ }
135+
129136 const prompts = await Promise . all ( [
130137 this . fileLocator . listFiles ( type , 'user' , token )
131138 . then ( withType ( 'user' , type ) ) ,
@@ -137,9 +144,9 @@ export class PromptsService extends Disposable implements IPromptsService {
137144 }
138145
139146 public getSourceFolders ( type : PromptsType ) : readonly IPromptPath [ ] {
140- // sanity check to make sure we don't miss a new
141- // prompt type that could be added in the future
142- assert ( isValidPromptType ( type ) , `Unknown prompt type ' ${ type } '.` ) ;
147+ if ( ! PromptsConfig . enabled ( this . configurationService ) ) {
148+ return [ ] ;
149+ }
143150
144151 const result : IPromptPath [ ] = [ ] ;
145152
@@ -258,20 +265,25 @@ export class PromptsService extends Disposable implements IPromptsService {
258265 public async findInstructionFilesFor ( files : readonly URI [ ] , ignoreInstructions ?: ResourceSet ) : Promise < readonly { uri : URI ; reason : string } [ ] > {
259266 const instructionFiles = await this . listPromptFiles ( PromptsType . instructions , CancellationToken . None ) ;
260267 if ( instructionFiles . length === 0 ) {
268+ this . logger . trace ( '[PromptsService#findInstructionFilesFor] No instruction files available.' ) ;
261269 return [ ] ;
262270 }
271+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] ${ files . length } input files provided. ${ files . map ( file => file . toString ( ) ) . join ( ', ' ) } ` ) ;
272+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] ${ instructionFiles . length } instruction files available.` ) ;
263273
264274 const result : { uri : URI ; reason : string } [ ] = [ ] ;
265275 const foundFiles = new ResourceSet ( ) ;
266276 for ( const instructionFile of instructionFiles ) {
267277 const { metadata, uri } = await this . parse ( instructionFile . uri , CancellationToken . None ) ;
268278
269279 if ( metadata ?. promptType !== PromptsType . instructions ) {
280+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] Not an instruction file: ${ uri } ` ) ;
270281 continue ;
271282 }
272283
273284 if ( ignoreInstructions ?. has ( uri ) || foundFiles . has ( uri ) ) {
274285 // the instruction file is already part of the input or has already been processed
286+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] Skipping already processed instruction file: ${ uri } ` ) ;
275287 continue ;
276288 }
277289
@@ -310,6 +322,7 @@ export class PromptsService extends Disposable implements IPromptsService {
310322 } ;
311323
312324
325+ let matches = false ;
313326 for ( const pattern of patterns ) {
314327 const matchResult = patterMatches ( pattern ) ;
315328 if ( matchResult !== false ) {
@@ -319,11 +332,14 @@ export class PromptsService extends Disposable implements IPromptsService {
319332
320333 result . push ( { uri, reason } ) ;
321334 foundFiles . add ( uri ) ;
335+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] ${ uri } selected: ${ reason } ` ) ;
336+ matches = true ;
322337 break ;
323338 }
324339 }
325-
326-
340+ if ( ! matches ) {
341+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] ${ uri } no match: pattern: ${ applyTo } ` ) ;
342+ }
327343 }
328344 return result ;
329345 }
0 commit comments