@@ -203,6 +203,16 @@ class AgentCompletions extends Disposable {
203
203
const agents = this . chatAgentService . getAgents ( )
204
204
. filter ( a => a . locations . includes ( widget . location ) ) ;
205
205
206
+ // When the input is only `/`, items are sorted by sortText.
207
+ // When typing, filterText is used to score and sort.
208
+ // The same list is refiltered/ranked while typing.
209
+ const getFilterText = ( agent : IChatAgentData , command : string ) => {
210
+ // This is hacking the filter algorithm to make @terminal /explain match worse than @workspace /explain by making its match index later in the string.
211
+ // When I type `/exp`, the workspace one should be sorted over the terminal one.
212
+ const dummyPrefix = agent . id === 'github.copilot.terminal' ? `0000` : `` ;
213
+ return `${ chatSubcommandLeader } ${ dummyPrefix } ${ agent . name } .${ command } ` ;
214
+ } ;
215
+
206
216
const justAgents : CompletionItem [ ] = agents
207
217
. filter ( a => ! a . isDefault )
208
218
. map ( agent => {
@@ -218,7 +228,7 @@ class AgentCompletions extends Disposable {
218
228
insertText : `${ agentLabel } ` ,
219
229
range : new Range ( 1 , 1 , 1 , 1 ) ,
220
230
kind : CompletionItemKind . Text ,
221
- sortText : `${ chatSubcommandLeader } ${ agent . id } ` ,
231
+ sortText : `${ chatSubcommandLeader } ${ agent . name } ` ,
222
232
command : { id : AssignSelectedAgentAction . ID , title : AssignSelectedAgentAction . ID , arguments : [ { agent, widget } satisfies AssignSelectedAgentActionArgs ] } ,
223
233
} ;
224
234
} ) ;
@@ -230,13 +240,13 @@ class AgentCompletions extends Disposable {
230
240
const withSlash = `${ chatSubcommandLeader } ${ c . name } ` ;
231
241
return {
232
242
label : { label : withSlash , description : agentLabel , detail : isDupe ? ` (${ agent . publisherDisplayName } )` : undefined } ,
233
- filterText : ` ${ chatSubcommandLeader } ${ agent . name } ${ c . name } ` ,
243
+ filterText : getFilterText ( agent , c . name ) ,
234
244
commitCharacters : [ ' ' ] ,
235
245
insertText : `${ agentLabel } ${ withSlash } ` ,
236
246
detail : `(${ agentLabel } ) ${ c . description ?? '' } ` ,
237
247
range : new Range ( 1 , 1 , 1 , 1 ) ,
238
248
kind : CompletionItemKind . Text , // The icons are disabled here anyway
239
- sortText : `${ chatSubcommandLeader } ${ agent . id } ${ c . name } ` ,
249
+ sortText : `${ chatSubcommandLeader } ${ agent . name } ${ c . name } ` ,
240
250
command : { id : AssignSelectedAgentAction . ID , title : AssignSelectedAgentAction . ID , arguments : [ { agent, widget } satisfies AssignSelectedAgentActionArgs ] } ,
241
251
} satisfies CompletionItem ;
242
252
} ) ) )
0 commit comments