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

Honor spaces in autocomplete candidates #1759

Merged
merged 8 commits into from
Oct 31, 2022
Merged

Conversation

jsotuyod
Copy link
Contributor

@jsotuyod jsotuyod commented Jul 29, 2022

Fixes #1754

  • 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.
  • Values still need to be double-escaped for proper handling.

jsotuyod added 4 commits July 28, 2022 19:27
 - 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.
 - Actually parse the values into a COMPREPLY array
@remkop
Copy link
Owner

remkop commented Jul 30, 2022

Thank you for the PR! Checking...

@jsotuyod
Copy link
Contributor Author

@remkop any feedback on this?

@remkop
Copy link
Owner

remkop commented Aug 18, 2022

Oops! Sorry for the long wait. I have not been able to spend much time on picocli recently...
Also, this ticket seems related to #1644 , so I want to look at both together.
I have not forgotten about it though!

Copy link
Contributor

@NewbieOrange NewbieOrange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@remkop remkop merged commit 99d87dc into remkop:main Oct 31, 2022
@remkop remkop added this to the 4.7 milestone Oct 31, 2022
@remkop remkop added type: enhancement ✨ theme: auto-completion An issue or change related to auto-completion theme: codegen An issue or change related to the picocli-codegen module labels Oct 31, 2022
@jsotuyod jsotuyod deleted the fix-1754 branch October 31, 2022 18:50
@remkop
Copy link
Owner

remkop commented Oct 31, 2022

Merged.
Thank you for the contribution!

@jsotuyod
Copy link
Contributor Author

@remkop glad to help! Any rough timelines for 4.7?

@remkop
Copy link
Owner

remkop commented Oct 31, 2022

Started the release process now...

remkop added a commit that referenced this pull request Nov 1, 2022
Copy link
Owner

@remkop remkop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jsotuyod! Thank you again for working on this PR!
I realize it is a while ago that you worked on this, but a question recently came up:
@vorburger ran ErrorProne against the picocli project, which flagged some items on AutoComplete.java:788 and 832:

... the format string has only 2 %s variables, but the code specifies 3 parameters (indent, paramName, currWord)...

This means that the last parameter (currWord) is not used. Is that correct? Can the currWord parameter be removed?

@@ -750,7 +785,7 @@ private static String generatePositionalParamsCases(List<PositionalParamSpec> po
int max = param.index().max();
if (param.completionCandidates() != null) {
buff.append(format("%s %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max));
buff.append(format("%s positionals=$( compgen -W \"$%s_pos_param_args\" -- \"%s\" )\n", indent, paramName, currWord));
buff.append(format("%s positionals=$( compReplyArray \"${%s_pos_param_args[@]}\" )\n", indent, paramName, currWord));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently discovered that the format string has only 2 %s variables, but we specify 3 parameters (indent, paramName, currWord)...

This means that the last parameter (currWord) is not used.
Is that correct? Can the currWord parameter be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it can be removed. Sorry for missing that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #2175

@@ -793,7 +828,8 @@ private static String generateOptionsCases(List<OptionSpec> argOptionFields, Str
}
if (option.completionCandidates() != null) {
buff.append(format("%s %s)\n", indent, concat("|", option.names()))); // " -u|--timeUnit)\n"
buff.append(format("%s COMPREPLY=( $( compgen -W \"${%s_option_args}\" -- \"%s\" ) )\n", indent, bashify(option.paramLabel()), currWord));
buff.append(format("%s local IFS=$'\\n'\n", indent));
buff.append(format("%s COMPREPLY=( $( compReplyArray \"${%s_option_args[@]}\" ) )\n", indent, bashify(option.paramLabel()), currWord));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently discovered that the format string has only 2 %s variables, but we specify 3 parameters (indent, bashify(option.paramLabel()), currWord)...

This means that the last parameter (currWord) is not used.
Is that correct? Can the currWord parameter be removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #2175

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 theme: codegen An issue or change related to the picocli-codegen module type: enhancement ✨
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autocomplete mishandling suggestions with spaces
4 participants