feat(complete): Support multi-path-element prefix completion#6261
Open
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
Open
feat(complete): Support multi-path-element prefix completion#6261AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
Conversation
Add comprehensive tests covering abbreviated path completion including good inputs, edge cases, existing path behavior, and hidden files. Abbreviated paths currently return empty since the feature is not yet implemented.
When no direct match is found, treat each /-separated component as a prefix and recursively match directories. For example, tar/de/inc now completes to target/debug/incremental/.
efbc2cb to
afeb916
Compare
epage
reviewed
Feb 13, 2026
Comment on lines
1622
to
1627
| // Hidden directory abbreviated paths: ".c/n" doesn't match without abbreviated path support | ||
| assert_data_eq!( | ||
| complete!(cmd, "--input .c/n[TAB]", current_dir = Some(testdir_path)), | ||
| snapbox::str![""] | ||
| ); | ||
|
|
epage
reviewed
Feb 13, 2026
Member
There was a problem hiding this comment.
Missing test cases:
- when a path element matches both as a literal and a prefix, in particular with a path that is a mixture of literals and prefixes
- ambiguous prefix, particularly early in the path
epage
reviewed
Feb 13, 2026
Member
There was a problem hiding this comment.
This seems to add duplicate coverage
epage
reviewed
Feb 13, 2026
Member
There was a problem hiding this comment.
Some of the test organization is suspect
epage
reviewed
Feb 13, 2026
|
|
||
| /// Resolve the base directory for path completion, handling absolute, home-relative, | ||
| /// and relative paths. | ||
| fn resolve_base_dir( |
Member
There was a problem hiding this comment.
This duplicates parts of complete_path and has major bugs in it
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #5279
Summary
Enables abbreviated path completion where each
/-separated component is treated as a prefix. For example,tar/de/inccompletes totarget/debug/incremental/. This is a fallback when standard completion finds no matches.Changes
clap_complete/src/engine/custom.rs: Addedcomplete_path_abbreviated()recursive function andresolve_base_dir()helper.clap_complete/tests/testsuite/engine.rs: 4 test functions with 18 assertions covering good inputs, edge cases, existing functionality, and hidden files.Test plan
cargo test -p clap_complete --features unstable-dynamic— all 111 tests passcargo clippy -p clap_complete --features unstable-dynamic— clean