@@ -509,40 +509,34 @@ export class ChatWebview extends EventEmitter {
509
509
listFileInWorkspace : async ( params : ListFilesInWorkspaceParams ) : Promise < ListFileItem [ ] > => {
510
510
const maxResults = params . limit || 50 ;
511
511
const searchQuery = params . query ?. trim ( ) ;
512
+ const res : ListFileItem [ ] = [ ] ;
513
+ let openTabs = window . tabGroups . all
514
+ . flatMap ( ( group ) => group . tabs )
515
+ . filter ( ( tab ) => tab . input && ( tab . input as TabInputText ) . uri )
516
+ . map ( ( tab ) => ( tab . input as TabInputText ) . uri ) ;
512
517
513
- if ( ! searchQuery ) {
514
- const openTabs = window . tabGroups . all
515
- . flatMap ( ( group ) => group . tabs )
516
- . filter ( ( tab ) => tab . input && ( tab . input as TabInputText ) . uri ) ;
518
+ openTabs = openTabs . filter ( ( uri , idx ) => openTabs . indexOf ( uri ) === idx ) ;
517
519
518
- const openTabItems = openTabs . map ( ( tab ) =>
519
- localUriToListFileItem ( ( tab . input as TabInputText ) . uri , this . gitProvider ) ,
520
- ) ;
521
-
522
- // If we have less than 5 open tabs, fetch additional files to make total = 5
523
- if ( openTabs . length < 5 ) {
524
- const additionalCount = 5 - openTabs . length ;
525
- this . logger . info ( `Found ${ openTabs . length } open tabs, fetching ${ additionalCount } more files` ) ;
526
- const files = await this . findFiles ( "**/*" , { maxResults : additionalCount } ) ;
527
- this . logger . info ( `Found ${ files . length } additional files` ) ;
528
- const fileItems = files . map ( ( uri ) => localUriToListFileItem ( uri , this . gitProvider ) ) ;
529
- return [ ...openTabItems , ...fileItems ] ;
530
- }
531
-
532
- this . logger . info ( `No query provided, listing ${ openTabs . length } opened editors.` ) ;
533
- return openTabItems ;
520
+ res . push ( ...openTabs . map ( ( uri ) => localUriToListFileItem ( uri , this . gitProvider , "openedInEditor" ) ) ) ;
521
+ if ( res . length > maxResults ) {
522
+ return res . slice ( 0 , maxResults ) ;
534
523
}
535
524
525
+ const globPattern = caseInsensitivePattern ( searchQuery ) ;
536
526
try {
537
- const globPattern = caseInsensitivePattern ( searchQuery ) ;
538
- this . logger . info ( `Searching files with pattern: ${ globPattern } , limit: ${ maxResults } ` ) ;
539
- const files = await this . findFiles ( globPattern , { maxResults } ) ;
540
- this . logger . info ( `Found ${ files . length } files.` ) ;
541
- return files . map ( ( uri ) => localUriToListFileItem ( uri , this . gitProvider ) ) ;
527
+ let files = await this . findFiles ( globPattern , {
528
+ maxResults : maxResults - res . length ,
529
+ excludes : openTabs . map ( ( uri ) => uri . fsPath ) ,
530
+ } ) ;
531
+ files = files . filter (
532
+ ( uri , idx ) => files . indexOf ( uri ) === idx && ! openTabs . some ( ( tabUri ) => tabUri . fsPath === uri . fsPath ) ,
533
+ ) ;
534
+ this . logger . debug ( `Found ${ files . length } files matching pattern "${ globPattern } "` ) ;
535
+ res . push ( ...files . map ( ( uri ) => localUriToListFileItem ( uri , this . gitProvider , "searchResult" ) ) ) ;
542
536
} catch ( error ) {
543
537
this . logger . warn ( "Failed to find files:" , error ) ;
544
- return [ ] ;
545
538
}
539
+ return res ;
546
540
} ,
547
541
548
542
readFileContent : async ( info : FileRange ) : Promise < string | null > => {
0 commit comments