Skip to content

Allow overriding suggestion display value - #1002

Merged
ysthakur merged 3 commits into
nushell:mainfrom
ysthakur:display-override
Jan 24, 2026
Merged

ysthakur merged 3 commits into
nushell:mainfrom
ysthakur:display-override

Conversation

@ysthakur

@ysthakur ysthakur commented Jan 11, 2026 •

Copy link
Copy Markdown
Member

This PR adds an optional display_override field to Suggestion. If set, the string set in this field will be displayed to users rather than the actual value of the suggestion. However, when a suggestion is chosen, its value will be put into the buffer, not its display_override.

Idea came from this comment by @qfel on an older PR.

Why?

Reason 1: On the Nushell side, we often have to provide completions wrapped in quotes. This can cause problems on the Reedline side. We strip quotes in the columnar and IDE menus to account for this when figuring out which substring to highlight. I'm not sure if the quote stripping is necessary anymore since we're doing substring matching anyway, but it doesn't handle escapes in strings. With display_override, we can show suggestions that don't contain any quotes or backslashes while still keeping the suggestions' values the same.

Relatedly, find_common_string, which is used for partial completions, is unable to compare file names wrapped in quotes to file names not wrapped in quotes. But here, the best solution here would be to allow completers to provide their own partial completions, which I plan to implement soon. Right now, partial completions are still based on value, not display value

Reason 2: Allowing Nushell users to customize their completions. The new field allows including ANSI highlights, so we can now let users create custom/external completers that provide suggestions with display_overrides styled however they want. They can get styled strings from some other source and provide those to Nushell.

Testing

As an example, here's a custom completer that uses lolcat. I just used lolcat for a laugh, but the lolcat colors look surprisingly good:

https://asciinema.org/a/CTmdQR9nboLjm5zn?t=4

Completer:

def comp [] {
  let completions = ^ls crates/*/*/*.rs | lolcat -f | lines | each {|file|
    {
      value: ($file | ansi strip),
      display_override: $file
    }
  }
  {
    completions: $completions,
    options: {
      completion_algorithm: "fuzzy"
    }
  }
}
def foo [ arg: string@comp ] {}

@ysthakur ysthakur added enhancement New feature or request A-Completions Area: Tab completion and inline hint completions P-low Low Priority: Implementation would be nice to have but does not severely impact quality of life labels Jan 11, 2026
@ysthakur
ysthakur marked this pull request as draft January 11, 2026 09:47
@ysthakur
ysthakur marked this pull request as ready for review January 11, 2026 09:55
@fdncred

fdncred commented Jan 11, 2026 •

Copy link
Copy Markdown
Contributor

That lolcat demo is great! 🤣 I'm up for giving this a try!

@ysthakur

Copy link
Copy Markdown
Member Author

Great! Do you want to merge it or ask someone else to look over it?

@fdncred

fdncred commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

If there's someone else you can get to review it that would be great. Otherwise we could just land it and see what happens. We have a release this weekend so we could also wait until after that depending on your comfort level.

@ysthakur

Copy link
Copy Markdown
Member Author

Yeah, let's wait. There's a good chance this'll break stuff. I'll dogfood it for a bit before merging.

@maxomatic458 and @blindFS If you have time, could you guys review this PR and/or try it out? Would appreciate any feedback you have since I know you've both spent a bunch of time on completions and menu stuff

@blindFS

blindFS commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

But here, the best solution here would be to allow completers to provide their own partial completions, which I plan to implement soon. Right now, partial completions are still based on value, not display value

I'm confused at this part. Do you mean display value (ansi striped) based partial completion is not good enough?

Haven't looked at those ansi related changes, I can't find any issue except for the per-completer partial completion mentioned.

BTW, with matching indices enabled, I think we are already safe to remove quotes stripping in reedline menus. But the idea of display-value certainly works better in those cases.

@ysthakur

Copy link
Copy Markdown
Member Author

@blindFS Whoops, just saw your comment.

I'm confused at this part. Do you mean display value (ansi striped) based partial completion is not good enough?

It should be good enough if the display override is exactly the same as the value, except with ANSI escapes. But if the display override is a very different string from the value, it won't work. I just felt it'd be safer to use value than display_override.

Do you recommend using the display value for partial completions?

BTW, with matching indices enabled, I think we are already safe to remove quotes stripping in reedline menus. But the idea of display-value certainly works better in those cases.

Indeed. We also use substring matching now instead of prefix matching, so completers don't even need to provide match indices. Display value is mainly for when you have backslashes or something within the quotes.

@ysthakur

Copy link
Copy Markdown
Member Author

@blindFS Actually, I just realized the reason for using value rather than display_override for partial completions. With file completions, if you have paths with a common prefix C:\Program Files\foo, then:

  • if you base partial completion on value, you'll fill in the path with a backtick at the start
  • but if you base partial completion on display_override, there won't be a backtick, and the filled partial path will have a space in it. Users will have to go to the start of the path to add a backtick/quote.

So I think for now, it's safest to use value. It does mean that sometimes you won't get partial completions at all, but it's better when it comes to partial completions for file paths with spaces.

@ysthakur
ysthakur merged commit f2fa4ce into nushell:main Jan 24, 2026
6 checks passed
@ysthakur
ysthakur deleted the display-override branch January 24, 2026 18:37
ysthakur added a commit to nushell/nushell that referenced this pull request Jan 24, 2026
Make Nushell compile after nushell/reedline#1002
and allow custom/external completers to override display value.

This adds a new `display_override` field to the suggestion record that
completers can return.

## Release notes summary - What our users need to know

Custom and external completers will now be able to set a display value
for their suggestions that's separate from the value that will be filled
into the buffer. They can do this by creating suggestions with the
`display_override` field set. The `display_override` field is allowed to
contain ANSI escapes for styling suggestions more extensively than the
`style` field allows.
```nu
def completer [] {
  [{
    value: "foobarbaz",
    display_override: $"(ansi red)foo(ansi green)bar(ansi blue)baz"
  }]
}
```

## Tasks after submitting
<!-- Remove any tasks which aren't relevant for your PR, or add your own
-->
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)
- [ ] Make file completions take advantage of the `display_override`
field to avoid having Reedline deal with quotes
- [ ] Allow completers to choose their own partial completions
kronberger-droid pushed a commit to skull-squadron/reedline that referenced this pull request Jun 1, 2026
This PR adds an optional display_override field to Suggestion. If set, the string set in this field will be displayed to users rather than the actual value of the suggestion. However, when a suggestion is chosen, its value will be put into the buffer, not its display_override.
@kronberger-droid kronberger-droid mentioned this pull request Aug 28, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Completions Area: Tab completion and inline hint completions enhancement New feature or request P-low Low Priority: Implementation would be nice to have but does not severely impact quality of life

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants