export function autocomplete(data, args) {
data.flags(argsSchema);
const lastFlag = args.length > 1 ? args[args.length - 2] : null;
if (lastFlag == "--spend-on") // Provide a couple auto-complete options to facilitate these arguments with spaces in them
return purchaseOptions.map(f => f.replaceAll(" ", "_"))
.concat(purchaseOptions.map(f => `'${f}'`));
return [];
}
Today, this seems to work if and only if the user has started typing some characters in the next argument (then lastFlag is correct).
Where this falls apart, is if the user types e.g. --spend-on and then immediately hits "tab". In this case, the last flag is args[^-1], but we don't detect that correctly and merely return a list of flags.
Further, if they type an entire second arg, --spend-on -l then hit autocomplete, they start seeing the spend-on options.
Perhaps in older versions of the game, the args list always contained an empty arg at the end (or perhaps we just never tested this, although I could have sworn it worked before). In either event, we now need to detect whether the last arg is "complete", and use the last arg, rather than the second-to-last arg as the "lastFlag".
We may need to wrap this up in a helper function to make it easier to maintain future fixes.
Autocomplete has always worked like this:
Today, this seems to work if and only if the user has started typing some characters in the next argument (then lastFlag is correct).
Where this falls apart, is if the user types e.g.
--spend-on
and then immediately hits "tab". In this case, the last flag isargs[^-1]
, but we don't detect that correctly and merely return a list of flags.Further, if they type an entire second arg,
--spend-on -l
then hit autocomplete, they start seeing the spend-on options.Perhaps in older versions of the game, the args list always contained an empty arg at the end (or perhaps we just never tested this, although I could have sworn it worked before). In either event, we now need to detect whether the last arg is "complete", and use the last arg, rather than the second-to-last arg as the "lastFlag".
We may need to wrap this up in a helper function to make it easier to maintain future fixes.