(
self: Instruction,
state: ZshCompletionState = { conflicts: Arr.empty(), multiple: false }
)
| 2162 | |
| 2163 | /** @internal */ |
| 2164 | export const getZshCompletions = ( |
| 2165 | self: Instruction, |
| 2166 | state: ZshCompletionState = { conflicts: Arr.empty(), multiple: false } |
| 2167 | ): Array<string> => { |
| 2168 | switch (self._tag) { |
| 2169 | case "Empty": { |
| 2170 | return Arr.empty() |
| 2171 | } |
| 2172 | case "Single": { |
| 2173 | const names = getNames(self) |
| 2174 | const description = getShortDescription(self) |
| 2175 | const possibleValues = InternalPrimitive.getZshCompletions( |
| 2176 | self.primitiveType as InternalPrimitive.Instruction |
| 2177 | ) |
| 2178 | const multiple = state.multiple ? "*" : "" |
| 2179 | const conflicts = Arr.isNonEmptyReadonlyArray(state.conflicts) |
| 2180 | ? `(${Arr.join(state.conflicts, " ")})` |
| 2181 | : "" |
| 2182 | return Arr.map( |
| 2183 | names, |
| 2184 | (name) => `${conflicts}${multiple}${name}[${escape(description)}]${possibleValues}` |
| 2185 | ) |
| 2186 | } |
| 2187 | case "KeyValueMap": { |
| 2188 | return getZshCompletions(self.argumentOption as Instruction, { ...state, multiple: true }) |
| 2189 | } |
| 2190 | case "Map": |
| 2191 | case "WithDefault": |
| 2192 | case "WithFallback": { |
| 2193 | return getZshCompletions(self.options as Instruction, state) |
| 2194 | } |
| 2195 | case "Both": { |
| 2196 | const left = getZshCompletions(self.left as Instruction, state) |
| 2197 | const right = getZshCompletions(self.right as Instruction, state) |
| 2198 | return Arr.appendAll(left, right) |
| 2199 | } |
| 2200 | case "OrElse": { |
| 2201 | const leftNames = getNames(self.left as Instruction) |
| 2202 | const rightNames = getNames(self.right as Instruction) |
| 2203 | const left = getZshCompletions( |
| 2204 | self.left as Instruction, |
| 2205 | { ...state, conflicts: Arr.appendAll(state.conflicts, rightNames) } |
| 2206 | ) |
| 2207 | const right = getZshCompletions( |
| 2208 | self.right as Instruction, |
| 2209 | { ...state, conflicts: Arr.appendAll(state.conflicts, leftNames) } |
| 2210 | ) |
| 2211 | return Arr.appendAll(left, right) |
| 2212 | } |
| 2213 | case "Variadic": { |
| 2214 | return Option.isSome(self.max) && self.max.value > 1 |
| 2215 | ? getZshCompletions(self.argumentOption as Instruction, { ...state, multiple: true }) |
| 2216 | : getZshCompletions(self.argumentOption as Instruction, state) |
| 2217 | } |
| 2218 | } |
| 2219 | } |
nothing calls this directly
no test coverage detected