Skip to content

feat(complete): Support multi-path-element prefix completion#6261

Open
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
AndreasBackx:feat/multi-path-element
Open

feat(complete): Support multi-path-element prefix completion#6261
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
AndreasBackx:feat/multi-path-element

Conversation

@AndreasBackx
Copy link
Contributor

This PR was generated with the assistance of an AI agent and reviewed by me.

Resolves #5279

Summary

Enables abbreviated path completion where each /-separated component is treated as a prefix. For example, tar/de/inc completes to target/debug/incremental/. This is a fallback when standard completion finds no matches.

Changes

clap_complete/src/engine/custom.rs: Added complete_path_abbreviated() recursive function and resolve_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 pass
  • cargo clippy -p clap_complete --features unstable-dynamic — clean

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.
@AndreasBackx AndreasBackx changed the title feat(complete): support multi-path-element prefix completion feat(complete): Support multi-path-element prefix completion Feb 13, 2026
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/.
@AndreasBackx AndreasBackx force-pushed the feat/multi-path-element branch from efbc2cb to afeb916 Compare February 13, 2026 01:39
@AndreasBackx AndreasBackx marked this pull request as ready for review February 13, 2026 01:46
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![""]
);

Copy link
Member

Choose a reason for hiding this comment

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

What about "--input ./n[TAB]"?

Copy link
Member

@epage epage Feb 13, 2026

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

This seems to add duplicate coverage

Copy link
Member

Choose a reason for hiding this comment

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

Some of the test organization is suspect


/// Resolve the base directory for path completion, handling absolute, home-relative,
/// and relative paths.
fn resolve_base_dir(
Copy link
Member

Choose a reason for hiding this comment

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

This duplicates parts of complete_path and has major bugs in it

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.

Complete multiple path elements at once

2 participants