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