(
self: Instruction,
state: ZshCompletionState = { multiple: false, optional: false }
)
| 1071 | } |
| 1072 | |
| 1073 | export const getZshCompletions = ( |
| 1074 | self: Instruction, |
| 1075 | state: ZshCompletionState = { multiple: false, optional: false } |
| 1076 | ): Array<string> => { |
| 1077 | switch (self._tag) { |
| 1078 | case "Empty": { |
| 1079 | return Arr.empty() |
| 1080 | } |
| 1081 | case "Single": { |
| 1082 | const multiple = state.multiple ? "*" : "" |
| 1083 | const optional = state.optional ? "::" : ":" |
| 1084 | const shortDescription = getShortDescription(self) |
| 1085 | const description = shortDescription.length > 0 ? ` -- ${shortDescription}` : "" |
| 1086 | const possibleValues = InternalPrimitive.getZshCompletions( |
| 1087 | self.primitiveType as InternalPrimitive.Instruction |
| 1088 | ) |
| 1089 | return possibleValues.length === 0 |
| 1090 | ? Arr.empty() |
| 1091 | : Arr.of(`${multiple}${optional}${self.name}${description}${possibleValues}`) |
| 1092 | } |
| 1093 | case "Map": { |
| 1094 | return getZshCompletions(self.args as Instruction, state) |
| 1095 | } |
| 1096 | case "Both": { |
| 1097 | const left = getZshCompletions(self.left as Instruction, state) |
| 1098 | const right = getZshCompletions(self.right as Instruction, state) |
| 1099 | return Arr.appendAll(left, right) |
| 1100 | } |
| 1101 | case "Variadic": { |
| 1102 | return Option.isSome(self.max) && self.max.value > 1 |
| 1103 | ? getZshCompletions(self.args as Instruction, { ...state, multiple: true }) |
| 1104 | : getZshCompletions(self.args as Instruction, state) |
| 1105 | } |
| 1106 | case "WithDefault": |
| 1107 | case "WithFallbackConfig": { |
| 1108 | return getZshCompletions(self.args as Instruction, { ...state, optional: true }) |
| 1109 | } |
| 1110 | } |
| 1111 | } |
nothing calls this directly
no test coverage detected