Skip to content

Conversation

@TheRealFalcon
Copy link
Contributor

Description

Remove folder name prefix in autocompletion suggestions

Fixes issue #8618

Additional info

Example behavior:
image

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:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

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 {
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless I'm misunderstanding you, it should already work for relative directories, but it depends on the length of the prefix. For example, here's my fish config dir:
image

But even with an absolute path, a short prefix won't collapse:
image

Copy link
Contributor

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 {
Copy link
Contributor

@krobelus krobelus Mar 15, 2025

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 {
Copy link
Contributor

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.

@krobelus krobelus added this to the fish 4.1 milestone Mar 15, 2025
prefix.push_utfstr(&common_prefix);
} else {
// Append just the end of the string.
// Collapse parent directories and append end of string
Copy link
Contributor

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
Copy link
Contributor

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

@TheRealFalcon
Copy link
Contributor Author

I believe I have addressed all of the comments and added a new check file with some basic tests for this behavior.

@krobelus krobelus closed this in 0dbfb4c Mar 20, 2025
@omentic
Copy link
Contributor

omentic commented Jul 20, 2025

Thanks! :-)

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.

3 participants