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

Autocomplete mishandling suggestions with spaces #1754

Closed
jsotuyod opened this issue Jul 27, 2022 · 2 comments · Fixed by #1759
Closed

Autocomplete mishandling suggestions with spaces #1754

jsotuyod opened this issue Jul 27, 2022 · 2 comments · Fixed by #1759
Labels
theme: auto-completion An issue or change related to auto-completion type: bug 🐛
Milestone

Comments

@jsotuyod
Copy link
Contributor

When an option provides a completionProvider that list strings with spaces, the autocomplete doesn't honor the completion provider, but instead splits all options on its own.

For instance, given the example:

    @Command(mixinStandardHelpOptions = true)
    public static class DummyCommand {
        @Option(names = "--candidate", completionCandidates = CandidatesCompletion.class)
        public String candidate;

        public static class CandidatesCompletion implements Iterable<String> {

            @Override
            public Iterator<String> iterator() {
                return Arrays.asList("John Doe", "Michael Scott", "John Sena").iterator();
            }
        }
    }

I'd expect 3 candidates to be offered, with proper escaping for the whitespace. However, this is what it's actually being suggested:

$ myapp --candidate <TAB><TAB>
Doe      John     Michael  Scott    Sena

5 options, all single words, duplicates removed.

@remkop
Copy link
Owner

remkop commented Jul 28, 2022

Thank you for raising this!
Is this for the bash/zsh completion, or for the JLine completion?

Will you be able to provide a pull request for this?

@remkop remkop added type: bug 🐛 theme: auto-completion An issue or change related to auto-completion labels Jul 28, 2022
@jsotuyod
Copy link
Contributor Author

It's on Bash / Zsh. By the time compgen -W is invoked, the list is already plain as John Doe Michael Scott John Sena, so compgen does it's thing.

For what I've seen, escaping here doesn't help, but there are some workarounds… I may give it a go with a PR, but will let you know if I run into trouble.

jsotuyod added a commit to jsotuyod/picocli that referenced this issue Jul 28, 2022
 - Both positional params and option candidates are now stored in the autocomplete script as an array.
 - By setting `IFS=$'\n'` for those scenarios, each array entry is treated as a single candidate,
allowing to honor any spaces in the original suggestions coded by the user.
remkop pushed a commit that referenced this issue Oct 31, 2022
 - Both positional params and option candidates are now stored in the autocomplete script as an array.
 - By setting `IFS=$'\n'` for those scenarios, each array entry is treated as a single candidate,
allowing to honor any spaces in the original suggestions coded by the user.
@remkop remkop added this to the 4.7 milestone Oct 31, 2022
remkop added a commit that referenced this issue Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: auto-completion An issue or change related to auto-completion type: bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants