@@ -102,19 +102,25 @@ function getFigSuggestionType(spec: Fig.Suggestion): CommandCompletion['type'] {
102102 }
103103}
104104
105- function transformFigSuggestion ( raw : string | Fig . Suggestion , query : string ) {
105+ function transformFigSuggestion ( raw : string | Fig . Suggestion , query : string , strict ?: boolean ) {
106106 const spec = typeof raw === 'string' ? { name : raw } : raw
107- const values = getFigValues ( spec )
107+ if ( spec . hidden ) return [ ]
108+ let values = getFigValues ( spec )
109+ if ( strict ) {
110+ values = values . filter ( value => value . startsWith ( query ) )
111+ }
108112 return values . map < CommandCompletion > ( value => ( {
109113 type : getFigSuggestionType ( spec ) ,
110114 query : spec . _internal ?. commasCompletionQuery as string | undefined ?? query ,
111115 value,
112116 label : spec . displayName ,
113117 description : spec . description ,
118+ deprecated : Boolean ( spec . deprecated ) ,
114119 } ) )
115120}
116121
117122function transformFigSubcommand ( spec : Fig . Subcommand , query : string ) {
123+ if ( spec . hidden ) return [ ]
118124 const values = getFigValues ( spec )
119125 return values . map < CommandCompletion > ( value => ( {
120126 type : 'command' ,
@@ -124,10 +130,12 @@ function transformFigSubcommand(spec: Fig.Subcommand, query: string) {
124130 spec . insertValue ? undefined : getFigArgsLabel ( spec , value )
125131 ) ,
126132 description : spec . description ,
133+ deprecated : Boolean ( spec . deprecated ) ,
127134 } ) )
128135}
129136
130137function transformFigOption ( spec : Fig . Option , query : string ) {
138+ if ( spec . hidden ) return [ ]
131139 const values = getFigValues ( spec )
132140 return values . map < CommandCompletion > ( value => ( {
133141 type : 'command' ,
@@ -137,6 +145,7 @@ function transformFigOption(spec: Fig.Option, query: string) {
137145 spec . insertValue ? undefined : getFigArgsLabel ( spec , value )
138146 ) ,
139147 description : spec . description ,
148+ deprecated : Boolean ( spec . deprecated ) ,
140149 } ) )
141150}
142151
@@ -164,16 +173,16 @@ async function getFigCompletions(
164173 if ( ! ( 'name' in spec ) ) return [ ]
165174 const asyncCompletions : ( CommandCompletion [ ] | Promise < CommandCompletion [ ] > ) [ ] = [ ]
166175 const options = spec . options ?? [ ]
167- // Suggestions or args (suggestions if no argv, args else)
168- if ( ! args . length || args . length === 1 && args [ 0 ] === '' ) {
169- const suggestions = [
170- ...normalizeArray ( spec . args ) . flatMap ( arg => arg . suggestions ?? [ ] ) ,
171- ... ( spec . additionalSuggestions ?? [ ] ) ,
172- ]
173- asyncCompletions . push (
174- suggestions . flatMap ( suggestion => transformFigSuggestion ( suggestion , query ) ) ,
175- )
176- } else {
176+ // Suggestions
177+ const suggestions = [
178+ ... normalizeArray ( spec . args ) . flatMap ( arg => arg . suggestions ?? [ ] ) ,
179+ ...( spec . additionalSuggestions ?? [ ] ) ,
180+ ]
181+ asyncCompletions . push (
182+ suggestions . flatMap ( suggestion => transformFigSuggestion ( suggestion , query , true ) ) ,
183+ )
184+ // Option args
185+ if ( args . length > 1 ) {
177186 // Option args since option spec will not pass to `getFigCompletions`
178187 const previousArg = args [ args . length - 2 ]
179188 const inputtingOption = options . find ( item => {
0 commit comments