-
Notifications
You must be signed in to change notification settings - Fork 379
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
fix(_comp_delimited): prepend prefix to all compreply args #913
Merged
scop
merged 3 commits into
scop:master
from
Rogach:pr/fix-comp-delimited-on-ambiguous-args
Apr 22, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
|
||
from conftest import assert_bash_exec | ||
|
||
|
||
@pytest.mark.bashcomp(cmd=None) | ||
class TestUnitDelimited: | ||
@pytest.fixture(scope="class") | ||
def functions(self, request, bash): | ||
assert_bash_exec( | ||
bash, | ||
"_comp_cmd_test_delim() {" | ||
" local cur prev words cword comp_args;" | ||
" _comp_get_words cur;" | ||
" _comp_delimited , -W 'alpha beta bravo';" | ||
"};" | ||
"complete -F _comp_cmd_test_delim test_delim", | ||
) | ||
|
||
@pytest.mark.complete("test_delim --opt=a") | ||
def test_1(self, functions, completion): | ||
assert completion == ["lpha"] | ||
|
||
@pytest.mark.complete("test_delim --opt=b") | ||
def test_2(self, functions, completion): | ||
assert completion == ["beta", "bravo"] | ||
|
||
@pytest.mark.complete("test_delim --opt=alpha,b") | ||
def test_3(self, functions, completion): | ||
assert completion == ["alpha,beta", "alpha,bravo"] | ||
|
||
@pytest.mark.complete("test_delim --opt=alpha,be") | ||
def test_4(self, functions, completion): | ||
assert completion == ["ta"] | ||
|
||
@pytest.mark.complete("test_delim --opt=beta,a") | ||
def test_5(self, functions, completion): | ||
assert completion == ["lpha"] | ||
|
||
@pytest.mark.complete("test_delim --opt=c") | ||
def test_6(self, functions, completion): | ||
assert not completion |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this certainly seems to work, it's also somewhat unfortunate, because displaying the completions with the prefix in place makes them harder to read, and with
show-all-if-ambiguous
on it appears we wouldn't have to do it (I'm biased, I have it on). So I'm contemplating something like:I suppose this would require some addressing/complexity in tests, too.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we have discussed in the past in #546, the current test framework totally relies on
set show-all-if-ambiguous on
, so I'm afraid there is no way to test the behavior for the caseset show-all-if-ambiguous off
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akinomyoga showed that
((${#COMPREPLY[@]} == 1)) && COMPREPLY=("$prefix$COMPREPLY")
isn't guaranteed to work even ifshow-all-if-unmodified
ison
(#913 (comment)). Copying the snippet here:I'm not an expert here, but it feels very brittle to be relying on some obscure undocumented interaction between options, that might break easily down the road (as showcased above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. I was also about to write it. I tried the change suggested by @scop with
set show-all-if-ambiguous
and confirmed that it still fails. Also, I was experimenting to see if it is possible to detect the insertion by looking atCOMP_TYPE
, but there doesn't seem to be a reliable way.(Experimental code)
with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Then let's just go with the implementation here that is known to work in all cases, you guys have spent more than enough time here already. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note in e3840d0 as a reminder to take stuff into account if someone is tempted to revisit this later.