11import { glob } from 'glob' ;
2+ import path from 'path' ;
23import { BaseContextProvider } from './BaseContextProvider' ;
34import {
45 ContextItem ,
@@ -18,31 +19,37 @@ class RelativeFileContextProvider extends BaseContextProvider {
1819 async getContextItems ( query : string , extras : ContextProviderExtras ) : Promise < ContextItem [ ] > {
1920 query = query . trim ( ) ;
2021 if ( ! query ) { return [ ] ; }
21-
22- let firstMatch : string | undefined ;
22+ console . log ( 'will get relative files' ) ;
2323 const workspaceDirs = await extras . ide . getWorkspaceDirs ( ) ;
24- for ( const rootDir of workspaceDirs ) {
25- const matches = await glob ( `**/${ query } ` , {
26- cwd : rootDir ,
27- signal : AbortSignal . timeout ( 1000 ) ,
28- } ) ;
29- if ( matches . length > 0 ) {
30- firstMatch = matches [ 0 ] ;
31- break ;
32- }
33- }
34- if ( ! firstMatch ) { return [ ] ; }
35- const content = await extras . ide . readFile ( firstMatch ) ;
24+ const fullPath = await matchPathToWorkspaceDirs ( query , workspaceDirs ) ;
25+ if ( ! fullPath ) { return [ ] ; }
26+ const content = await extras . ide . readFile ( fullPath ) ;
3627 return [ {
3728 name : query . split ( / [ \\ / ] / ) . pop ( ) ?? query ,
38- description : firstMatch ,
29+ description : fullPath ,
3930 content : `\`\`\`${ query } \n${ content } \n\`\`\`` ,
4031 uri : {
4132 type : 'file' ,
42- value : firstMatch ,
33+ value : fullPath ,
4334 } ,
4435 } ] ;
4536 }
4637}
4738
39+ async function matchPathToWorkspaceDirs ( query : string , workspaceDirs : string [ ] ) {
40+ for ( const rootDir of workspaceDirs ) {
41+ const matches = await glob ( `**/${ query } ` , {
42+ cwd : rootDir ,
43+ signal : AbortSignal . timeout ( 1000 ) ,
44+ } ) ;
45+ if ( matches . length > 0 ) {
46+ console . log ( 'match' , matches [ 0 ] , path . join ( rootDir , matches [ 0 ] ) ) ;
47+ return path . join ( rootDir , matches [ 0 ] ) ; // Create full path
48+ } else {
49+ return null ;
50+ }
51+ }
52+ return null ;
53+ }
54+
4855export default RelativeFileContextProvider ;
0 commit comments