( getPrefix: ReturnType<typeof createCommandPrefixExtractor>, splitCommand: (command: string) => string[] | Promise<string[]>, )
| 136 | * @returns A memoized async function that extracts prefixes for the main command and all subcommands |
| 137 | */ |
| 138 | export function createSubcommandPrefixExtractor( |
| 139 | getPrefix: ReturnType<typeof createCommandPrefixExtractor>, |
| 140 | splitCommand: (command: string) => string[] | Promise<string[]>, |
| 141 | ) { |
| 142 | const memoized = memoizeWithLRU( |
| 143 | ( |
| 144 | command: string, |
| 145 | abortSignal: AbortSignal, |
| 146 | isNonInteractiveSession: boolean, |
| 147 | ): Promise<CommandSubcommandPrefixResult | null> => { |
| 148 | const promise = getCommandSubcommandPrefixImpl( |
| 149 | command, |
| 150 | abortSignal, |
| 151 | isNonInteractiveSession, |
| 152 | getPrefix, |
| 153 | splitCommand, |
| 154 | ) |
| 155 | // Evict on rejection so aborted calls don't poison future turns. |
| 156 | // Identity guard: after LRU eviction, a newer promise may occupy |
| 157 | // this key; a stale rejection must not delete it. |
| 158 | promise.catch(() => { |
| 159 | if (memoized.cache.get(command) === promise) { |
| 160 | memoized.cache.delete(command) |
| 161 | } |
| 162 | }) |
| 163 | return promise |
| 164 | }, |
| 165 | command => command, // memoize by command only |
| 166 | 200, |
| 167 | ) |
| 168 | |
| 169 | return memoized |
| 170 | } |
| 171 | |
| 172 | async function getCommandPrefixImpl( |
| 173 | command: string, |
no test coverage detected