Skip to content

Commit 279474f

Browse files
committed
feat: fig option isRepeatable
1 parent bf0087c commit 279474f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/utils/completion.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,22 @@ function transformFigSubcommand(spec: Fig.Subcommand, query: string) {
136136
}))
137137
}
138138

139-
function transformFigOption(spec: Fig.Option, query: string) {
139+
function transformFigOption(spec: Fig.Option, query: string, args: string[]) {
140140
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 []
142155
return values.map<CommandCompletion>(value => ({
143156
type: 'command',
144157
query,
@@ -219,7 +232,7 @@ async function getFigCompletions(
219232
}
220233
// Options
221234
asyncCompletions.push(
222-
options.flatMap(option => transformFigOption(option, query)),
235+
options.flatMap(option => transformFigOption(option, query, args)),
223236
)
224237
// Args
225238
asyncCompletions.push(

0 commit comments

Comments
 (0)