Skip to content

feat(completion): allow overriding half of the span in custom/external completer - #17049

Merged
ysthakur merged 2 commits into
nushell:mainfrom
blindFS:custom_completion_span
Nov 22, 2025
Merged

ysthakur merged 2 commits into
nushell:mainfrom
blindFS:custom_completion_span

Conversation

@blindFS

@blindFS blindFS commented Nov 20, 2025 •

Copy link
Copy Markdown
Contributor

As commented here

CC @ysthakur

Release notes summary - What our users need to know

None. Should be covered by those of #15888

Tasks after submitting

  • Update the document.

@Juhan280

Copy link
Copy Markdown
Contributor

What does "half of the span" mean?

Does this resolve #17046 or unrelated?

@blindFS

blindFS commented Nov 20, 2025

Copy link
Copy Markdown
Contributor Author

What does "half of the span" mean?

Does this resolve #17046 or unrelated?

Not related.

.get("end")
.and_then(|val| val.as_int().ok())
.and_then(|x| usize::try_from(x).ok());
// TODO: error on invalid spans?

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.

We really should, but right now we can just log an error or something. I really should've done that in my PR. Not a blocker for this PR though

Comment thread crates/nu-cli/tests/completions/mod.rs Resolved
@ysthakur

Copy link
Copy Markdown
Member

You've probably already thought of this, but I wanted to bring up that it's not unambiguous what the user intends when their completer provides only half a span. There's a few possibilities if start is not given (I'm ignoring missing end here to make the discussion simpler):

  1. There's a bug in the completer causing start to not be included
    1. Or start was given, but isn't an int because of a bug in the completer (we don't differentiate at the moment)
  2. It's intentional, and the user means "replace everything from the beginning of the line to end"
  3. It's intentional, and the user means "replace everything from the beginning of the normal suggestion span to end" (what this PR does)

If we chose interpretation 1, we would have to error. I think interpretation 3 is the most sensible and useful. It's what most users would mean when returning half a span intentionally. But the disadvantage with that is that if someone provides an end that's less than the original suggestion.span.start, then there isn't a good way to deal with that.

With this PR, in such a scenario, suggestion.span.end would be set to suggestion.span.start, meaning that nothing would be replaced, only inserted. That's probably not users want.

With interpretation 2, the completer's given end can still be invalid, but it would have to be either negative or greater than the line length.

To be clear, I'm not pushing for interpretation 2 here, just wanted to hear your thoughts. I don't have strong feelings either way but we need to make sure whatever we decide will be intuitive.

@ysthakur

Copy link
Copy Markdown
Member

We should have some sort of combined release notes btw mentioning both PRs. Can come up with it after this PR is merged though

@blindFS

blindFS commented Nov 22, 2025 •

Copy link
Copy Markdown
Contributor Author

To be clear, I'm not pushing for interpretation 2 here, just wanted to hear your thoughts. I don't have strong feelings either way but we need to make sure whatever we decide will be intuitive.

IMO, error on such cases without any completion makes most sense.

I mean if we provide enough messages about the validity of spans, there should be no more ambiguity, right?

But I'm not sure how we want the message to present, on the reedline menu or a ShellError?

@ysthakur

Copy link
Copy Markdown
Member

Yeah, erroring makes sense. As for how we want to present, it wouldn't be too bad to print a big in-your-face ShellError. The problem with that is that it would probably mean moving the prompt down, and I'm not sure if that's desirable behavior.

I do want to make it so that Reedline menus can display more than just suggestions. If we did that, we could have it display the error, then get rid of the error if the menu's deactivated. We'd also log errors so that the error isn't lost forever once the menu's deactivated.

Either way, not a blocker for this PR. We can disallow this behavior later. I'll just merge this for now.

@ysthakur
ysthakur merged commit 2bd42c4 into nushell:main Nov 22, 2025
@github-actions github-actions Bot added this to the v0.109.0 milestone Nov 22, 2025
@ysthakur

Copy link
Copy Markdown
Member

Actually, never mind the release notes, if you think it's too inconsequential to be mentioned. But we do need to update the docs, I forgot to do that after my PR

@blindFS
blindFS deleted the custom_completion_span branch November 22, 2025 02:14
@ysthakur ysthakur added A:completions Issues related to tab completion category:enhancement New feature or request notes:hide Noted only in "Full Changelog" section labels Nov 22, 2025
@blindFS

blindFS commented Nov 22, 2025

Copy link
Copy Markdown
Contributor Author

@ysthakur As for issue #17046, I don't know how pos was used before this span customization. Should we calibrate it and note it a breaking change?

@ysthakur

Copy link
Copy Markdown
Member

Should we calibrate it and note it a breaking change?

Yup, working on that now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:completions Issues related to tab completion category:enhancement New feature or request notes:hide Noted only in "Full Changelog" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants