Skip to content

Stronger contracts around completions - #1136

Merged
fdncred merged 7 commits into
nushell:mainfrom
philocalyst:visual
Jul 30, 2026
Merged

fdncred merged 7 commits into
nushell:mainfrom
philocalyst:visual

Conversation

@philocalyst

Copy link
Copy Markdown
Contributor

Summary

Async completors BEFORE TODAY... gave menus no real way to prove work was in progress. This instead adds a pleasant indicator that replaces the menu marker while a completion runs, plus a keyed message!

On the way:

  • CompletionResult carries no an Optional Partial
  • ColumnarMenu/IdeMenu track a CompletionOrigin (buffer + insertion point) so a Pending result computed against a stale buffer can't splice its span into the current one.
  • unicase moved from a runtime dependency to a dev-dependency!

Within the public API:
WorkingIndicator, WorkingPhase, CompletionProgress, Partial, and new Menu/MenuBuilder/MenuSettings methods (with_working_marker, with_working_indicator, working_indicator, progress, working_phase, working_message). Menu::set_active/Menu::clear_input are new required methods (no default body), so this is source-breaking for any external Menu implementors.

Before

Async completers had no way to signal "still working"

After

A menu with a WorkingIndicator configured animates its marker while a completion is in flight, and shows a message afta enough time.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens reedline’s completion/menu contracts by (1) making completion application span-safe (preventing stale spans from being spliced into a changed buffer), and (2) adding a first-class “work in flight” indicator/message that menus and the engine can render while async completions are pending.

Changes:

  • Introduces WorkingIndicator/CompletionProgress and new Menu API hooks to animate/announce in-flight completions.
  • Extends CompletionResult to carry an optional completer-supplied Partial, and updates menus to apply partials/accepts through a gated buffer-origin check.
  • Refactors menu activation/deactivation handling (set_active/clear_input + handle_menu_event) and adjusts tests/dependencies (moves unicase to dev-deps).

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/painting/painter.rs Updates test menu impls to satisfy new required Menu trait methods.
src/menu/mod.rs Adds working indicator/progress types; expands Menu and MenuSettings APIs for in-flight UI.
src/menu/menu_functions.rs Introduces span-gated CompletionDisplay apply paths and partial-apply helpers; refactors buffer replacement helper.
src/menu/list_menu.rs Adopts shared activation/deactivation handling via handle_menu_event.
src/menu/ide_menu.rs Tracks completion progress; uses gated accept/partial application; updates activation/deactivation behavior.
src/menu/description_menu.rs Adopts shared activation/deactivation handling and clears values on deactivate.
src/menu/columnar_menu.rs Tracks completion progress; uses gated accept/partial application; adds tests for stale-span safety and working indicator behavior.
src/lib.rs Re-exports new public types (Partial, WorkingIndicator, WorkingPhase, CompletionProgress).
src/engine.rs Repaints based on working-indicator phase changes to animate without repainting every poll.
src/core_editor/editor.rs Adds internal line_buffer_mut() to enable buffer edits before committing via undo stack.
src/completion/mod.rs Re-exports new Partial type from completion base.
src/completion/base.rs Extends CompletionResult to carry Option<Partial> and adds related helpers (with_partial, partial).
Cargo.toml Moves unicase from runtime dependency to dev-dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/menu/menu_functions.rs Outdated
Comment on lines 364 to 368
pub struct CompletionDisplay {
/// Cached suggestion values shown by the menu.
pub values: Suggestions,
/// Suggestions shown by the menu. Private: spans escape only via `accept` /
/// `common_prefix`, so no other code can splice one into the wrong buffer.
values: Suggestions,
/// Display width of each suggestion in `values`.
Comment thread src/menu/mod.rs Resolved
Comment thread src/menu/menu_functions.rs Resolved
@kronberger-droid

Copy link
Copy Markdown
Collaborator

Some things I found while exploring the changes with Claude:

Partial completion is dead for everything but nushell.
common_prefix returns false on partial: None, and DefaultCompleter (default.rs:124) and HistoryCompleter (history.rs:37) still call bare CompletionResult::fresh(...).
examples/demo.rs:88 has with_partial_completions(true) on a DefaultCompleter, so ab + Tab gives abaaa on main and stays ab here.
menu_functions.rs still promises "the built-in derivation kicks in".
That logic now survives only as test_helpers::fake_partial, and the test_find_common_string cases went out with it, nushell/nushell#16765 included.

The Stale gate is weaker than its docs claim.
computed_for is stamped at adoption time, not from the buffer the completer computed against, which for Stale is an older one.
Hand stale_pending_span_is_not_spliced a Stale result with span: 5..10 instead of PendingCompleter and you get open CODE_OF_CONDUCT.mdOF_CONDUCT.md | from csv --sep.
Not reachable through nushell/nushell#18761, since narrowed_fallback rebases every span to Span::new(reference_span.start, query.cursor()) first.
But that puts the invariant in the completer, which is the opposite of what the CompletionDisplay doc claims ("unrepresentable rather than merely guarded-against").
Either Stale reaches accept/common_prefix only behind something reedline can check, or CompletionResult::Stale spells out that spans must describe the buffer it was handed.

Smaller:

  • An async Tab reserves a blank row for 2s before searching... shows, since working_message is empty until patience and get_rows returns 1 where it returned 0.
  • The default frames · ∙ • ∙ are all East Asian Ambiguous. Do they hold one column in a CJK-width terminal?
  • The description is short a few breaks: Fresh/Stale gained a field, find_common_string and can_partially_complete removed, CompletionDisplay::values private, CompletionDisplay::new changed signature.
  • The Menu trait refactor is unrelated to completions but is the only source-breaking part for external Menu implementors. Could it go out separately, since follow-ups are coming anyways?

@kronberger-droid

kronberger-droid commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

@fdncred

Worth checking how close nushell/nushell#18761 actually is before we rush this one through.
It's still a draft and it builds on nushell/nushell#18660, which is also a draft.

The duplication in nushell/nushell#18737 is fixed by the CompletionSite work in #18761, not by anything here.
So landing this early doesn't get users a fix, it parks a dependency ahead of a WIP.

@philocalyst
Does the span-math half of #18761 lean on these reedline changes at all?
If CompletionSite can go out on its own, we'd fix #18737 now and take the cache work and this PR at whatever pace we need.

@fdncred

fdncred commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

ya, I was thinking we should point nushell's PR 18761 reedline to this PR/branch so we can test it in nushell.

I'm also confused as to whether 18660 is built into 18761 or we need all 3 of these PR landed (eventually) in a very specific order.

Thanks for the review.

@philocalyst

Copy link
Copy Markdown
Contributor Author

If CompletionSite can go out on its own, we'd fix #18737 now and take the cache work and this PR at whatever pace we need.

I'll rework to make this possible.

To clarify: Async prompts are built on top of the completer rework PR. I did this out of convenience, I don't think there's a direct link. If it's not pressing to have a clear split, I'd rather work through those two PRs one by one, as they're both large and fundamental.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

Well I would say most importantly we/you @philocalyst should focus on making completers stable for the user and then build on the stable base.
Right now I am not sure how much of the two nushell PRs and this one is for stability over features.

@fdncred

fdncred commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

ya, I agree. Let's focus on stability of what we have in these PRs. We can refactor later when it's not such an emergency as it is right now. It's critical that we get the completion bugs fixed soon since our release is on August 15th and we have code freeze around August 13th.

@fdncred

fdncred commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for chatting with us today @philocalyst. I think you said you were going to split this up somehow. If you do that please try to include fixes for the issues martin and copilot mentioned above.

@philocalyst
philocalyst force-pushed the visual branch 2 times, most recently from 9f4e749 to a605ddb Compare July 30, 2026 06:57
…_prefix guarding

- Make CompletionDisplay.values private, add partial/computed_for fields
- Add suggestions(), is_current(), accept(), common_prefix() methods
- Add derive_common_prefix() and apply_partial() helpers
- Update from_result and new() to handle Partial/CompletionOrigin
- Remove find_common_string() and can_partially_complete()
- Update tests to use derive_common_prefix and add fallback test
- Add set_active, clear_input, on_activate, on_deactivate methods
- Add handle_menu_event with default implementation routing
  Activate/Deactivate to lifecycle methods
- Implement delegation in Box<dyn Menu>
…API in all menus

- Add set_active, clear_input, on_activate, on_deactivate to
  ColumnarMenu, IdeMenu, DescriptionMenu, ListMenu
- Switch from can_partially_complete to CompletionDisplay::common_prefix
- Switch from replace_in_buffer to CompletionDisplay::accept
- Use self.completions.suggestions() instead of direct field access
- Add stale-span safety tests for columnar menu
@philocalyst

Copy link
Copy Markdown
Contributor Author

Okay, incorporated your review comments @kronberger-droid , ditto for the automated ones. A second PR will come up tomorrow on the visual indicator. This covers everything that is not that.

@philocalyst

Copy link
Copy Markdown
Contributor Author

I do want to add that the nushell PR is relatively intertangled with even the visual indicator changes, as there I define usage around how progress is communicated, just something to keep in mind.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

@philocalyst
Do you think it makes sense to disentangle it a bit since right now I am not fully in the picture of what does what.

Also do you think we will be able to land all of your changes some time before the release on 15th.
Since i think it would be good to have a somewhat stable version before the release with time to spare to get some testing in.

Thanks for your great work!

@fdncred

fdncred commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Also do you think we will be able to land all of your changes some time before the release on 15th.

My preference is to land PRs sooner, like this week if possible. There's always unexpected edge cases that come up and we have to land PRs and get to finding those ASAP, IMO. We need stability more than anything else.

@philocalyst

Copy link
Copy Markdown
Contributor Author

@kronberger-droid It COULD be splt up, but with trouble, as most of this is so tightly coupled. "What is going on here" is essentially nothing -- just moving the implicit behavior into types.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

Okay, if you think you can land them until next week it doesn't matter.

Haha thanks for the clarification. I was worried we do a lot of feature work now. So thats not the case?

@philocalyst

Copy link
Copy Markdown
Contributor Author

No, that I did split up into another PR.

@fdncred

fdncred commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Are we ready to land this or do we need more time?

@philocalyst

Copy link
Copy Markdown
Contributor Author

I'm confident in it. Up to you? @kronberger-droid

@kronberger-droid

Copy link
Copy Markdown
Collaborator

On reedline for sure!

But I can't really tell for the nushell ones, these are much larger.

@fdncred
fdncred merged commit f799710 into nushell:main Jul 30, 2026
7 checks passed
@fdncred

fdncred commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

ok, let's go then! thanks!

fdncred added a commit to nushell/nushell that referenced this pull request Aug 2, 2026
Requires nushell/reedline#1136
Related PR (Builds ontop of):
#18660

## Description

This is a follow-up to #18334 (non-blocking completions, merged) and
#18671 (test-infra sync, merged). Those landed the async worker model
(`CompletionResult` Fresh/Stale/Pending) but left... several issues
unresolved. Sorry to all the folks who put up with that on the nightlies
:(

Overarching changes:
- Across prompts we're using a LRU cache for storing and managing the
caches. This is configurable, and default bounded to 100. For many
completions nothing is loaded onto the LRU cache, only the intensive
operations (git checkout, carapace stuff, etc.). Open to dramatically
reducing this number, but it *sure* feels nice when it works.
- Cache work is a lot more robust, we do narrowing and carry always an
"env" for the completor environment, so we have a *rough* idea of when
to complete for the sources that are mostly pure.
- Added completionengine for the death of hardcoded dispatch with a
routing enum. This allowed me to rewrite the completor trait around the
context and fetched types, wiring a lot more logic directly through it.
- Added completionsite and sitekind models for a catch-all way for
resolving the facts of what is under the cursor, which kills maybe fifty
sites of span math (what caused the super annoying completion
duplication)
- *commandline complete --type` now type-checks its argument (previously
accepted any string and could silently no-op) and clamps the cursor to a
valid boundary instead of indexing out of range.
- complete paths is shared between file and directory completions, which
eliminates a panic risk and more manual span constructions.
- 
- **Flag/span plumbing.** `FlagRef` and `Flag::long_name` are adopted
across `nu-parser`/`nu-engine`/`nu-cmd-lang` so flag identity survives
through parsing and into completion and help-text rendering, which
eliminated a lot of re-derive logic.

## User-facing changes (Release notes)

- Added `$env.config.completions.cache_size` (default: `100`) to control
that cap.
- Completion results now persist across prompts instead of being
discarded on every new prompt,.
- Fixed a potential panic when narrowing file/directory completions on a
path containing multi-byte (non-ASCII) characters.
- `commandline complete --type` now validates its `--type` argument and
no longer panics on an out-of-range cursor.
- `use`, `overlay use`, `export use`, `source-env`, `hide-env`, `attr
complete`, and `which` now go through the same completion dispatch as
other builtins, fixing inconsistent/missing completions in a few of them

## Additional Notes
- Can't promise that this eliminates all bugs, just most of them. The
bigger thing it gives us is a more robust framework to fix bugs, going
forward. Will be responsive to anything related to completions, and am
okay with a longer review period before merge. The big things are
covered now, however, with the added tests in this PR.
-

fixes #11211

---------

Co-authored-by: Darren Schroeder <[email protected]>
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.

4 participants