-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Remove folder name prefix in autocompletion suggestions #11250
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
Conversation
src/reader.rs
Outdated
| prefix.push_utfstr(&full[full.len() - PREFIX_MAX_LEN..]); | ||
| let truncated = &full[full.len() - PREFIX_MAX_LEN..]; | ||
| let parts: Vec<&wstr> = truncated.split('/').collect(); | ||
| if parts.len() < 2 { |
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.
Seems like a good change. I'll try it for a while.
I haven't re-read the issue yet - maybe we can briefly summarize the reason for this change.
I gues zsh will only show the basename even if there is no truncation going on,
but we don't need to go there - your approach is safer.
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.
after re-reading the issue, I think we should eventually have a generic way
of making sure that the common prefix is not way larger than any of the suffixes.
But that can definitely be done later, and I expect that we'll still want to keep the special handling of "/".
| // any further | ||
| prefix.push_utfstr(&truncated); | ||
| } else { | ||
| // Discard any parent directories and include whats left |
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.
this works for absolute paths but it doesn't seem to work for ~/some/path, can we fix that?
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.
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.
yeah my bad
src/reader.rs
Outdated
| prefix.push_utfstr(&full[full.len() - PREFIX_MAX_LEN..]); | ||
| let truncated = &full[full.len() - PREFIX_MAX_LEN..]; | ||
| let parts: Vec<&wstr> = truncated.split('/').collect(); | ||
| if parts.len() < 2 { |
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.
parts.len() < 2 is a bit confusing because there's always at least one part.
Better make that obvious by checking parts.len() == 1.
Actually we should also get rid of the gratuitous vector, how about
let (i, last_component) = truncated.split('/').enumerate().last().unwrap();
if i == 0 {
// No path separators were found in the common prefix, so we can't collapse
// any further
prefix.push_utfstr(&truncated);
} else {
// Discard any parent directories and include whats left
prefix.push('/');
prefix.push_utfstr(last_component);
};
src/reader.rs
Outdated
| prefix.push_utfstr(&full[full.len() - PREFIX_MAX_LEN..]); | ||
| let truncated = &full[full.len() - PREFIX_MAX_LEN..]; | ||
| let parts: Vec<&wstr> = truncated.split('/').collect(); | ||
| if parts.len() < 2 { |
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.
I'm wondering if we should also allow = and : as separators, since we sort of do that when computing completions.
I guess let's wait until we find a use case; the LHS is not usually very large.
| prefix.push_utfstr(&common_prefix); | ||
| } else { | ||
| // Append just the end of the string. | ||
| // Collapse parent directories and append end of string |
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.
should probably add to the changelog, maybe something like
- When tab completion results are truncated, the common directory name is omitted.
| prefix.push_utfstr(&common_prefix); | ||
| } else { | ||
| // Append just the end of the string. | ||
| // Collapse parent directories and append end of string |
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.
This didn't break any tests locally for me. I'm willing to add new tests for this behavior, but I could use some direction as to where they would need to go and what sort of setup and/or mocking would be required.
We don't have mocking for src/reader.rs yet, so either add that or write
a system test, maybe in tmux-pager.fish. To run, use
cargo b && tests/test_driver.py target/debug tests/checks/tmux-pager.fish
|
I believe I have addressed all of the comments and added a new check file with some basic tests for this behavior. |
|
Thanks! :-) |


Description
Remove folder name prefix in autocompletion suggestions
Fixes issue #8618
Additional info
Example behavior:

This didn't break any tests locally for me. I'm willing to add new tests for this behavior, but I could use some direction as to where they would need to go and what sort of setup and/or mocking would be required.
TODOs: