File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -136,9 +136,22 @@ function transformFigSubcommand(spec: Fig.Subcommand, query: string) {
136
136
} ) )
137
137
}
138
138
139
- function transformFigOption ( spec : Fig . Option , query : string ) {
139
+ function transformFigOption ( spec : Fig . Option , query : string , args : string [ ] ) {
140
140
if ( spec . hidden ) return [ ]
141
- const values = getFigValues ( spec )
141
+ let values = getFigValues ( spec )
142
+ const separator = spec . requiresSeparator
143
+ ? ( typeof spec . requiresSeparator === 'string' ? spec . requiresSeparator : '=' )
144
+ : ( spec . requiresEquals ? '=' : undefined )
145
+ if ( separator ) {
146
+ values = values . map ( value => value + separator )
147
+ }
148
+ const max = spec . isRepeatable
149
+ ? ( typeof spec . isRepeatable === 'number' ? spec . isRepeatable : Infinity )
150
+ : 1
151
+ const times = args . filter ( arg => {
152
+ return values . some ( value => ( separator ? arg . startsWith ( value ) : arg === value ) )
153
+ } ) . length
154
+ if ( times > max ) return [ ]
142
155
return values . map < CommandCompletion > ( value => ( {
143
156
type : 'command' ,
144
157
query,
@@ -219,7 +232,7 @@ async function getFigCompletions(
219
232
}
220
233
// Options
221
234
asyncCompletions . push (
222
- options . flatMap ( option => transformFigOption ( option , query ) ) ,
235
+ options . flatMap ( option => transformFigOption ( option , query , args ) ) ,
223
236
)
224
237
// Args
225
238
asyncCompletions . push (
You can’t perform that action at this time.
0 commit comments