Skip to content

fix(ri): fix several problems and use _comp_split #1083

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

Merged
merged 6 commits into from
Feb 1, 2024

Conversation

akinomyoga
Copy link
Collaborator

I'm now trying to apply _comp_split in completions/*, but I decided to submit the changes on completions/ri in a separate PR since this file ri has many fixes. See the commit message of each commit for the details.

In particular, commit 8c4510d needs double-checking from others. The existing code looks like COMPREPLY+=("$(... | sort -u)") where the entire result of the command substitution is quoted, but I suspected that the quoting is unneeded because the result should be separated. However, the quoting seems to have existed from the beginning.

The current implementation of `_comp_cmd_ri__methods` generates
methods separated by newlines as a single element of COMPREPLY, which
is suspicous.  This code existed since the first implementation of the
"ri" completion in commit 309cf93.  In this patch, we try to split
the result with newlines.
The current implementation passes to `compgen` the option `-P ...`
through the quoted word "$prefix" where prefix='-P ...'.  However,
this is interpreted by compgen as `-P' ...'` where an extra space is
suffixed.

It was originally specified in an unquoted form `$prefix` so that `-P`
and `...` were split by the word splitting.  This was broken in commit
9ba5831 [1], which added quotes based on shellcheck SC2086.  In this
patch, we use a different approach.  We make the variable `prefix`
only contains the prefix value `...` and explicitly specify the option
`-P` at the calling site.

[1] \
scop@9ba5831#diff-bbb83b7f6efc5ed7f97e90f27044b376b7a227f954b1ff6ff6ee0afea4bf4a36R32
The current implementation of `_comp_cmd_ri__methods` prefixes $prefix
to the generated method names.  However, this prefixing also affects
the already generated completions in COMPREPLY because it first
generates the method names by appending them to COMPRELY and then
modifies all the elements of COMPREPLY.

In the current usage, it did not produce the problem because prefix is
empty when there are existing elements in COMPREPLY, but it's
accidentally.  Before refactoring the code, we want to resolve this
dependency on the subtle condition.
@scop scop merged commit 18fac2b into scop:master Feb 1, 2024
@akinomyoga akinomyoga deleted the _comp_split-1 branch February 1, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants