File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -337,21 +337,39 @@ export class Completion {
337337 previousArgs : string [ ] ,
338338 toComplete : string
339339 ) {
340- const commandParts = [ ...previousArgs ] ;
340+ const commandParts = [ ...previousArgs ] . filter ( arg => arg !== '' ) ;
341+
342+ // When we have no real command parts (just empty or showing root commands)
343+ const isRootCompletion = commandParts . length === 0 ;
341344
342345 for ( const [ k , command ] of this . commands ) {
343346 if ( k === '' ) continue ;
347+
344348 const parts = k . split ( ' ' ) ;
345- let match = true ;
346349
350+ // For root completion, just match the first part of each command
351+ if ( isRootCompletion ) {
352+ if ( parts [ 0 ] . startsWith ( toComplete ) ) {
353+ this . completions . push ( {
354+ value : parts [ 0 ] ,
355+ description : command . description ,
356+ } ) ;
357+ }
358+ continue ;
359+ }
360+
361+ // For subcommand completion, match the parts against commandParts
362+ let match = true ;
347363 let i = 0 ;
364+
348365 while ( i < commandParts . length ) {
349366 if ( parts [ i ] !== commandParts [ i ] ) {
350367 match = false ;
351368 break ;
352369 }
353370 i ++ ;
354371 }
372+
355373 if ( match && parts [ i ] ?. startsWith ( toComplete ) ) {
356374 this . completions . push ( {
357375 value : parts [ i ] ,
You can’t perform that action at this time.
0 commit comments