Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Auto-Complete args don't work until the first character of the next argument is typed #423

Open
alainbryden opened this issue Nov 3, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@alainbryden
Copy link
Owner

Autocomplete has always worked like this:

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.

@alainbryden alainbryden added the bug Something isn't working label Nov 3, 2024
@alainbryden alainbryden self-assigned this Nov 3, 2024
@alainbryden alainbryden added enhancement New feature or request and removed bug Something isn't working labels Nov 27, 2024
@alainbryden alainbryden changed the title autocomplete doesn't seem to work anymore Custom Auto-Complete args don't work until the first character of the next argument is typed Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant