Skip to content

Allow filtering custom completions by description#18156

Merged
fdncred merged 1 commit intonushell:mainfrom
kiil:custom-completion-filter-by-description
May 6, 2026
Merged

Allow filtering custom completions by description#18156
fdncred merged 1 commit intonushell:mainfrom
kiil:custom-completion-filter-by-description

Conversation

@kiil
Copy link
Copy Markdown
Contributor

@kiil kiil commented May 3, 2026

Description

Allow filtering custom completions by description

When a custom completer returns suggestions with descriptions, only the value field was matched against the user's prefix. This made it impossible to narrow down a list by typing a fragment of the human-readable description — e.g. completing an email like lk446763made-up@gmx.net by typing the user's name "Lennart".

Add a new match_description option (default false) to the custom completion options record. When enabled, CustomCompletion::fetch also checks each suggestion's description against the active prefix using the configured match_algorithm, keeping a suggestion if either its value or description matches. The completed value remains the suggestion's value — only filtering is affected. Default behavior is unchanged.

Per review feedback, the option lives on the CompletionOptions struct rather than being threaded around as a separate bool, keeping completion configuration in one place.

User-facing changes (Release notes)

Custom completers can now opt into matching the user's prefix against suggestion descriptions in addition to values, by setting match_description: true in the returned options record. The inserted completion is still the suggestion's value.

def "nu-complete users" [] {
  {
    options: { match_description: true, completion_algorithm: "substring" }
    completions: [
      { value: "lk446763@example.com", description: "Lennart Kiil" }
      { value: "ab123456@example.com", description: "Alice Bob" }
    ]
  }
}

Additional notes

Addresses #18139

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 3, 2026

I'm not sure how I feel about this. Completions are for completing commands not for completing descriptions.

@kiil
Copy link
Copy Markdown
Contributor Author

kiil commented May 4, 2026

@fdncred only the command (value) is completed. This simply allows for filtering both by value and description in the UI (where you use characters to filter and tab to complete).

Let's say the value is lk446763made-up@gmx.net and the description is "Some Full Name". Then you can filter by either, but only lk446763made-up@gmx.net ( the value that is sent to the command ) is completed.

I explain a use case in more detail here: #18139

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 4, 2026

I feel like this should be a completion option vs working all the time.

{{ completions: [{}], options: {{ {} }} }}

options: { completion_algorithm: "substring" }

@kiil
Copy link
Copy Markdown
Contributor Author

kiil commented May 4, 2026

@fdncred I agree it would be best to make it optional, eventhough I feel it should be the default, because as long as the description is shown alongside the value, people will intuitively expect to be able to filter on the description also.

I do not really know how to make it configurable, though.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 4, 2026

I can see how it would be helpful. Lemme see what others think.

@kiil kiil force-pushed the custom-completion-filter-by-description branch from a29cdb0 to 46e33b5 Compare May 4, 2026 19:40
@kiil
Copy link
Copy Markdown
Contributor Author

kiil commented May 4, 2026

I amended the commit to include a bool completion config option for description.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 4, 2026

I think adding match_description is fine but that only works for custom completions written in nushell script, not for the built-in.

One way to get it to work for built-in menus is to change reedline to add another menu item bool.

This is how the default completion menu is defined:

const DEFAULT_COMPLETION_MENU: &str = r#"
{
  name: completion_menu
  only_buffer_difference: false
  marker: "| "
  type: {
      layout: columnar
      columns: 4
      col_width: 20
      col_padding: 2
      tab_traversal: "horizontal"
  }
  style: {
      text: green,
      selected_text: green_reverse
      description_text: yellow
  }
}"#;

Something could be added under tab_traversal, this way people could enable it or disable it pretty easily.

@kiil
Copy link
Copy Markdown
Contributor Author

kiil commented May 5, 2026

@fdncred

Do you think we can land this for custom completions first?

I am not too familiar with reedline functionality, but this PR for custom completions works regardless.

.get("match_description")
.and_then(|val| val.as_bool().ok())
{
match_description = md;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should be updating the completion_options struct here instead of passing around a new bool. Although not your changes, I think the same is true for should_sort and should_filter. Having options spread all over the place and not in the struct makes it very difficult to track what's going on.

Copy link
Copy Markdown
Contributor

@fdncred fdncred left a comment

Choose a reason for hiding this comment

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

Let's maybe try and clean this up with the struct changes I suggested.

@kiil
Copy link
Copy Markdown
Contributor Author

kiil commented May 5, 2026

@fdncred - I'll have a look later today or tomorrow in the morning. Your comments and help are much appreciated.

Adds a new `match_description` option (default `false`) to the custom
completion options record. When enabled, CustomCompletion::fetch also
checks each suggestion's description against the active prefix using
the configured match_algorithm, keeping a suggestion if either its
value or description matches. Default behavior is unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@kiil kiil force-pushed the custom-completion-filter-by-description branch from 46e33b5 to 74c8d49 Compare May 5, 2026 18:27
@kiil
Copy link
Copy Markdown
Contributor Author

kiil commented May 5, 2026

@fdncred I think I managed to do what you asked for.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 6, 2026

I can land this when the CI is green and the Description is updated and in compliance with our default PR request template. Maybe look at others if you're not sure what that means. We use the template to create release notes and either you or your LLM created this PR request template out of spec.

@kiil
Copy link
Copy Markdown
Contributor Author

kiil commented May 6, 2026

I updated the PR according to the template.

@fdncred fdncred merged commit 4c6bbb2 into nushell:main May 6, 2026
32 of 33 checks passed
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 6, 2026

Thanks @kiil

@github-actions github-actions Bot added this to the v0.113.0 milestone May 6, 2026
@kiil kiil deleted the custom-completion-filter-by-description branch May 7, 2026 04:57
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.

2 participants