@@ -7,7 +7,7 @@ import { flatten } from '../utils/treeUtils.js';
7
7
import { localize } from '../../../../../../nls.js' ;
8
8
import { PROMPT_LANGUAGE_ID } from '../constants.js' ;
9
9
import { PromptParser } from '../parsers/promptParser.js' ;
10
- import { match } from '../../../../../../base/common/glob.js' ;
10
+ import { match , splitGlobAware } from '../../../../../../base/common/glob.js' ;
11
11
import { pick } from '../../../../../../base/common/arrays.js' ;
12
12
import { type URI } from '../../../../../../base/common/uri.js' ;
13
13
import { type IPromptFileReference } from '../parsers/types.js' ;
@@ -268,23 +268,38 @@ export class PromptsService extends Disposable implements IPromptsService {
268
268
continue ;
269
269
}
270
270
271
- // if glob pattern is one of the special wildcard values,
272
- // add the instructions file event if no files are attached
273
- if ( ( applyTo === '**' ) || ( applyTo === '**/*' ) ) {
274
- foundFiles . add ( uri ) ;
275
-
276
- continue ;
277
- }
271
+ const patterns = splitGlobAware ( applyTo , ',' ) ;
272
+ const patterMatches = ( pattern : string ) => {
273
+ pattern = pattern . trim ( ) ;
274
+ if ( pattern . length === 0 ) {
275
+ // if glob pattern is empty, skip it
276
+ return false ;
277
+ }
278
+ if ( pattern === '**' || pattern === '**/*' || pattern === '*' ) {
279
+ // if glob pattern is one of the special wildcard values,
280
+ // add the instructions file event if no files are attached
281
+ return true ;
282
+ }
283
+ if ( ! pattern . startsWith ( '/' ) && ! pattern . startsWith ( '**/' ) ) {
284
+ // support relative glob patterns, e.g. `src/**/*.js`
285
+ pattern = '**/' + pattern ;
286
+ }
278
287
279
- // match each attached file with each glob pattern and
280
- // add the instructions file if its rule matches the file
281
- for ( const file of files ) {
282
- if ( match ( applyTo , file . fsPath ) ) {
283
- foundFiles . add ( uri ) ;
288
+ // match each attached file with each glob pattern and
289
+ // add the instructions file if its rule matches the file
290
+ for ( const file of files ) {
291
+ // if the file is not a valid URI, skip it
292
+ if ( match ( pattern , file . path ) ) {
293
+ return true ;
294
+ }
284
295
}
296
+ return false ;
297
+ } ;
298
+
299
+ if ( patterns . some ( patterMatches ) ) {
300
+ foundFiles . add ( uri ) ;
285
301
}
286
302
}
287
-
288
303
return [ ...foundFiles ] ;
289
304
}
290
305
0 commit comments