@@ -51,21 +51,8 @@ export class PromptFilesLocator {
51
51
}
52
52
53
53
private async listFilesInUserData ( type : PromptsType , token : CancellationToken ) : Promise < readonly URI [ ] > {
54
- try {
55
- const info = await this . fileService . resolve ( this . userDataService . currentProfile . promptsHome ) ;
56
- if ( info . isDirectory && info . children && ! token . isCancellationRequested ) {
57
- const result : URI [ ] = [ ] ;
58
- for ( const child of info . children ) {
59
- if ( child . isFile && getPromptFileType ( child . resource ) === type ) {
60
- result . push ( child . resource ) ;
61
- }
62
- }
63
- return result ;
64
- }
65
- return [ ] ;
66
- } catch ( error ) {
67
- return [ ] ;
68
- }
54
+ const files = await this . resolveFilesAtLocation ( this . userDataService . currentProfile . promptsHome , token ) ;
55
+ return files . filter ( file => getPromptFileType ( file ) === type ) ;
69
56
}
70
57
71
58
/**
@@ -142,17 +129,13 @@ export class PromptFilesLocator {
142
129
) ;
143
130
144
131
const { parent, filePattern } = firstNonGlobParentAndPattern ( absoluteLocation ) ;
145
- if ( filePattern === undefined && await this . isExistingFile ( parent ) ) {
146
- // if the provided location points to a file, add it
147
- if ( getPromptFileType ( parent ) === type ) {
148
- paths . add ( parent ) ;
149
- }
150
- } else {
151
- const promptFiles = await this . searchFilesInLocation ( parent , filePattern , token ) ;
152
- for ( const file of promptFiles ) {
153
- if ( getPromptFileType ( file ) === type ) {
154
- paths . add ( file ) ;
155
- }
132
+
133
+ const files = ( filePattern === undefined )
134
+ ? await this . resolveFilesAtLocation ( parent , token ) // if the location does not contain a glob pattern, resolve the location directly
135
+ : await this . searchFilesInLocation ( parent , filePattern , token ) ;
136
+ for ( const file of files ) {
137
+ if ( getPromptFileType ( file ) === type ) {
138
+ paths . add ( file ) ;
156
139
}
157
140
}
158
141
if ( token . isCancellationRequested ) {
@@ -198,6 +181,31 @@ export class PromptFilesLocator {
198
181
return [ ...result ] ;
199
182
}
200
183
184
+ /**
185
+ * Uses the file service to resolve the provided location and return either the file at the location of files in the directory.
186
+ */
187
+ private async resolveFilesAtLocation ( location : URI , token : CancellationToken ) : Promise < URI [ ] > {
188
+ try {
189
+ const info = await this . fileService . resolve ( location ) ;
190
+ if ( info . isFile ) {
191
+ return [ info . resource ] ;
192
+ } else if ( info . isDirectory && info . children ) {
193
+ const result : URI [ ] = [ ] ;
194
+ for ( const child of info . children ) {
195
+ if ( child . isFile ) {
196
+ result . push ( child . resource ) ;
197
+ }
198
+ }
199
+ return result ;
200
+ }
201
+ } catch ( error ) {
202
+ }
203
+ return [ ] ;
204
+ }
205
+
206
+ /**
207
+ * Uses the search service to find all files at the provided location
208
+ */
201
209
private async searchFilesInLocation (
202
210
folder : URI ,
203
211
filePattern : string | undefined ,
@@ -230,14 +238,6 @@ export class PromptFilesLocator {
230
238
}
231
239
return [ ] ;
232
240
}
233
-
234
- private async isExistingFile ( uri : URI ) : Promise < boolean > {
235
- try {
236
- return ( await this . fileService . resolve ( uri ) ) . isFile ;
237
- } catch ( e ) {
238
- }
239
- return false ;
240
- }
241
241
}
242
242
243
243
@@ -341,6 +341,13 @@ const firstNonGlobParentAndPattern = (
341
341
// just find all prompt files in the provided location
342
342
return { parent : location , filePattern : undefined } ;
343
343
}
344
+ if ( i === segments . length - 1 && segments [ i ] === '*' || segments [ i ] === `` ) {
345
+ return {
346
+ parent : location . with ( { path : segments . slice ( 0 , i ) . join ( '/' ) } ) ,
347
+ filePattern : undefined
348
+ } ;
349
+ }
350
+
344
351
// the path contains a glob pattern, so we search in last folder that does not contain a glob pattern
345
352
return {
346
353
parent : location . with ( { path : segments . slice ( 0 , i ) . join ( '/' ) } ) ,
0 commit comments