Repository navigation
Stronger contracts around completions - #1136
Conversation
There was a problem hiding this comment.
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/CompletionProgressand newMenuAPI hooks to animate/announce in-flight completions. - Extends
CompletionResultto carry an optional completer-suppliedPartial, 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 (movesunicaseto 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.
| 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`. |
|
Some things I found while exploring the changes with Claude: Partial completion is dead for everything but nushell. The Smaller:
|
|
Worth checking how close nushell/nushell#18761 actually is before we rush this one through. The duplication in nushell/nushell#18737 is fixed by the @philocalyst |
|
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. |
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. |
|
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. |
|
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. |
|
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. |
9f4e749 to
a605ddb
Compare
…_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
|
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. |
|
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. |
|
@philocalyst Also do you think we will be able to land all of your changes some time before the release on 15th. Thanks for your great work! |
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. |
|
@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. |
|
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? |
|
No, that I did split up into another PR. |
|
Are we ready to land this or do we need more time? |
|
I'm confident in it. Up to you? @kronberger-droid |
|
On reedline for sure! But I can't really tell for the nushell ones, these are much larger. |
|
ok, let's go then! thanks! |
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]>
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:
ColumnarMenu/IdeMenutrack aCompletionOrigin(buffer + insertion point) so aPendingresult computed against a stale buffer can't splice its span into the current one.unicasemoved from a runtime dependency to a dev-dependency!Within the public API:
WorkingIndicator,WorkingPhase,CompletionProgress,Partial, and newMenu/MenuBuilder/MenuSettingsmethods (with_working_marker,with_working_indicator,working_indicator,progress,working_phase,working_message).Menu::set_active/Menu::clear_inputare new required methods (no default body), so this is source-breaking for any externalMenuimplementors.Before
Async completers had no way to signal "still working"
After
A menu with a
WorkingIndicatorconfigured animates its marker while a completion is in flight, and shows a message afta enough time.