4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import { 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' ;
8
8
import { PromptParser } from '../parsers/promptParser.js' ;
9
9
import { match , splitGlobAware } from '../../../../../../base/common/glob.js' ;
10
10
import { type URI } from '../../../../../../base/common/uri.js' ;
@@ -27,6 +27,8 @@ import { IUserDataProfileService } from '../../../../../services/userDataProfile
27
27
import type { IChatPromptSlashCommand , ICustomChatMode , IMetadata , IPromptParserResult , IPromptPath , IPromptsService , TPromptsStorage } from './promptsService.js' ;
28
28
import { getCleanPromptName , PROMPT_FILE_EXTENSION } from '../config/promptFileLocations.js' ;
29
29
import { ILanguageService } from '../../../../../../editor/common/languages/language.js' ;
30
+ import { PromptsConfig } from '../config/config.js' ;
31
+ import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js' ;
30
32
31
33
/**
32
34
* Provides prompt services.
@@ -57,6 +59,7 @@ export class PromptsService extends Disposable implements IPromptsService {
57
59
@IInstantiationService private readonly instantiationService : IInstantiationService ,
58
60
@IUserDataProfileService private readonly userDataService : IUserDataProfileService ,
59
61
@ILanguageService private readonly languageService : ILanguageService ,
62
+ @IConfigurationService private readonly configurationService : IConfigurationService ,
60
63
) {
61
64
super ( ) ;
62
65
@@ -126,6 +129,10 @@ export class PromptsService extends Disposable implements IPromptsService {
126
129
}
127
130
128
131
public async listPromptFiles ( type : PromptsType , token : CancellationToken ) : Promise < readonly IPromptPath [ ] > {
132
+ if ( ! PromptsConfig . enabled ( this . configurationService ) ) {
133
+ return [ ] ;
134
+ }
135
+
129
136
const prompts = await Promise . all ( [
130
137
this . fileLocator . listFiles ( type , 'user' , token )
131
138
. then ( withType ( 'user' , type ) ) ,
@@ -137,9 +144,9 @@ export class PromptsService extends Disposable implements IPromptsService {
137
144
}
138
145
139
146
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
+ }
143
150
144
151
const result : IPromptPath [ ] = [ ] ;
145
152
@@ -258,20 +265,25 @@ export class PromptsService extends Disposable implements IPromptsService {
258
265
public async findInstructionFilesFor ( files : readonly URI [ ] , ignoreInstructions ?: ResourceSet ) : Promise < readonly { uri : URI ; reason : string } [ ] > {
259
266
const instructionFiles = await this . listPromptFiles ( PromptsType . instructions , CancellationToken . None ) ;
260
267
if ( instructionFiles . length === 0 ) {
268
+ this . logger . trace ( '[PromptsService#findInstructionFilesFor] No instruction files available.' ) ;
261
269
return [ ] ;
262
270
}
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.` ) ;
263
273
264
274
const result : { uri : URI ; reason : string } [ ] = [ ] ;
265
275
const foundFiles = new ResourceSet ( ) ;
266
276
for ( const instructionFile of instructionFiles ) {
267
277
const { metadata, uri } = await this . parse ( instructionFile . uri , CancellationToken . None ) ;
268
278
269
279
if ( metadata ?. promptType !== PromptsType . instructions ) {
280
+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] Not an instruction file: ${ uri } ` ) ;
270
281
continue ;
271
282
}
272
283
273
284
if ( ignoreInstructions ?. has ( uri ) || foundFiles . has ( uri ) ) {
274
285
// 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 } ` ) ;
275
287
continue ;
276
288
}
277
289
@@ -310,6 +322,7 @@ export class PromptsService extends Disposable implements IPromptsService {
310
322
} ;
311
323
312
324
325
+ let matches = false ;
313
326
for ( const pattern of patterns ) {
314
327
const matchResult = patterMatches ( pattern ) ;
315
328
if ( matchResult !== false ) {
@@ -319,11 +332,14 @@ export class PromptsService extends Disposable implements IPromptsService {
319
332
320
333
result . push ( { uri, reason } ) ;
321
334
foundFiles . add ( uri ) ;
335
+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] ${ uri } selected: ${ reason } ` ) ;
336
+ matches = true ;
322
337
break ;
323
338
}
324
339
}
325
-
326
-
340
+ if ( ! matches ) {
341
+ this . logger . trace ( `[PromptsService#findInstructionFilesFor] ${ uri } no match: pattern: ${ applyTo } ` ) ;
342
+ }
327
343
}
328
344
return result ;
329
345
}
0 commit comments