Skip to content

Substring Match Algorithm#15511

Merged
ysthakur merged 11 commits intonushell:mainfrom
vansh284:feature/substring-algo
Apr 11, 2025
Merged

Substring Match Algorithm#15511
ysthakur merged 11 commits intonushell:mainfrom
vansh284:feature/substring-algo

Conversation

@vansh284
Copy link
Copy Markdown
Contributor

@vansh284 vansh284 commented Apr 6, 2025

Description

This PR should close #15474 .

User-Facing Changes

When users set the match algorithm to 'substring' by modifying $env.config to $env.config.completions.algorithm = "substring"``), completions are done based on substring matches. This was previously possible by setting positional` to be false in custom completers, but doing so now logs a warning as this feature is set to be deprecated and replaced by the new way of setting the matching algorithm to substring based.

@vansh284 vansh284 marked this pull request as ready for review April 6, 2025 17:00
@ysthakur
Copy link
Copy Markdown
Member

ysthakur commented Apr 6, 2025

Thanks for putting this up. I should've clarified on the issue, but I wanted to not only add a substring match algorithm but also remove positional from CompletionOptions internally. So if a custom completer sets positional: false (and the prefix algorithm is used), then you can use the substring match algorithm instead. There shouldn't be any need to have a positional option internally anymore.

Copy link
Copy Markdown
Member

@ysthakur ysthakur left a comment

Choose a reason for hiding this comment

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

I haven't tried running this yet or checked if we need more thorough tests, but this looks like pretty good so far.

Make sure to update doc_config.nu so that users can see what algorithms are available and how sorting works with substring.

Very small nitpick: you currently have <code for prefix stuff>, <code for fuzzy stuff>, <code for substring stuff> everywhere. I think it would look a little nicer if the order was instead prefix, substring, fuzzy, since prefix and substring matching are pretty similar.

Would also be nice to reduce the code duplication in completion_options a teeny bit, but it's not a huge deal, especially if removing duplication ends up complicating the code more.

@vansh284 vansh284 requested a review from ysthakur April 9, 2025 08:13
Copy link
Copy Markdown
Member

@ysthakur ysthakur left a comment

Choose a reason for hiding this comment

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

I just tried this out, and it works great. Just need to change the logging a bit.

Also, this comment isn't necessary anymore:

// positional: false should make it do substring matching

completion_options.positional = positional;
let positional =
options.get("positional").and_then(|val| val.as_bool().ok());
if let Some(_positional) = positional {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Try this instead:

Suggested change
if let Some(_positional) = positional {
if positional.is_some() {

@ysthakur ysthakur merged commit 61dbcf3 into nushell:main Apr 11, 2025
15 checks passed
@github-actions github-actions bot added this to the v0.104.0 milestone Apr 11, 2025
@ysthakur
Copy link
Copy Markdown
Member

Thanks, let's try this out

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.

Substring match algorithm

2 participants