@@ -868,15 +868,16 @@ class BuiltinDynamicCompletions extends Disposable {
868
868
869
869
private async addFileAndFolderEntries ( widget : IChatWidget , result : CompletionList , info : { insert : Range ; replace : Range ; varWord : IWordAtPosition | null } , token : CancellationToken ) {
870
870
871
- const makeCompletionItem = ( resource : URI , kind : FileKind , description ?: string ) : CompletionItem => {
872
-
871
+ const makeCompletionItem = ( resource : URI , kind : FileKind , description ?: string , boostPriority ?: boolean ) : CompletionItem => {
872
+ console . log ( 'makeCompletionItem' , resource ) ;
873
873
const basename = this . labelService . getUriBasenameLabel ( resource ) ;
874
874
const text = `${ chatVariableLeader } file:${ basename } ` ;
875
875
const uriLabel = this . labelService . getUriLabel ( resource , { relative : true } ) ;
876
876
const labelDescription = description
877
877
? localize ( 'fileEntryDescription' , '{0} ({1})' , uriLabel , description )
878
878
: uriLabel ;
879
- const sortText = ' ' ; // keep files always at the top
879
+ // keep files above other completions
880
+ const sortText = boostPriority ? ' ' : '!' ;
880
881
881
882
return {
882
883
label : { label : basename , description : labelDescription } ,
@@ -905,22 +906,9 @@ class BuiltinDynamicCompletions extends Disposable {
905
906
const seen = new ResourceSet ( ) ;
906
907
const len = result . suggestions . length ;
907
908
908
- // RELATED FILES
909
- if ( widget . input . currentModeKind !== ChatModeKind . Ask && widget . viewModel && widget . viewModel . model . editingSession ) {
910
- const relatedFiles = ( await raceTimeout ( this . _chatEditingService . getRelatedFiles ( widget . viewModel . sessionId , widget . getInput ( ) , widget . attachmentModel . fileAttachments , token ) , 200 ) ) ?? [ ] ;
911
- for ( const relatedFileGroup of relatedFiles ) {
912
- for ( const relatedFile of relatedFileGroup . files ) {
913
- if ( ! seen . has ( relatedFile . uri ) ) {
914
- seen . add ( relatedFile . uri ) ;
915
- result . suggestions . push ( makeCompletionItem ( relatedFile . uri , FileKind . FILE , relatedFile . description ) ) ;
916
- }
917
- }
918
- }
919
- }
920
-
921
909
// HISTORY
922
910
// always take the last N items
923
- for ( const item of this . historyService . getHistory ( ) ) {
911
+ for ( const [ i , item ] of this . historyService . getHistory ( ) . entries ( ) ) {
924
912
if ( ! item . resource || seen . has ( item . resource ) ) {
925
913
// ignore editors without a resource
926
914
continue ;
@@ -935,12 +923,25 @@ class BuiltinDynamicCompletions extends Disposable {
935
923
}
936
924
937
925
seen . add ( item . resource ) ;
938
- const newLen = result . suggestions . push ( makeCompletionItem ( item . resource , FileKind . FILE ) ) ;
926
+ const newLen = result . suggestions . push ( makeCompletionItem ( item . resource , FileKind . FILE , i === 0 ? localize ( 'activeFile' , 'Active file' ) : undefined , i === 0 ) ) ;
939
927
if ( newLen - len >= 5 ) {
940
928
break ;
941
929
}
942
930
}
943
931
932
+ // RELATED FILES
933
+ if ( widget . input . currentModeKind !== ChatModeKind . Ask && widget . viewModel && widget . viewModel . model . editingSession ) {
934
+ const relatedFiles = ( await raceTimeout ( this . _chatEditingService . getRelatedFiles ( widget . viewModel . sessionId , widget . getInput ( ) , widget . attachmentModel . fileAttachments , token ) , 200 ) ) ?? [ ] ;
935
+ for ( const relatedFileGroup of relatedFiles ) {
936
+ for ( const relatedFile of relatedFileGroup . files ) {
937
+ if ( ! seen . has ( relatedFile . uri ) ) {
938
+ seen . add ( relatedFile . uri ) ;
939
+ result . suggestions . push ( makeCompletionItem ( relatedFile . uri , FileKind . FILE , relatedFile . description ) ) ;
940
+ }
941
+ }
942
+ }
943
+ }
944
+
944
945
// SEARCH
945
946
// use file search when having a pattern
946
947
if ( pattern ) {
0 commit comments