Repository navigation
non-blocking completions - #18334
non-blocking completions#18334
Conversation
5b0a01f to
3d10a11
Compare
|
Converted to draft because I don't want it landed with the |
|
Haha! I forgot about that cargo.toml change. Let me see if I can get better than the unsafe. |
3d10a11 to
18d9bd9
Compare
|
Isolated to A SINGLE unsafe block, feel free to ask further questions, it seems unavoidable. My other PR removes unsafe blocks so maybe it evens out?? |
|
The only 2 acceptable changes for reedline in the Cargo.toml is having a versioned reedline like we do during a release and having this patch in our Cargo.toml. [patch.crates-io]
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }It's fine to have it the way you have it now, pointing to your reedline repo, for testing, but we'd never land it like this because it's not our reedline, of course. I guess you've done this because there are changes required to reedline? If so, please point out those PRs in the description. I'm still not sold on the unsafe but I'll let others comment on that. |
|
It's simply for testing. I invite anyone unsure about unsafe to read the comment and the associated page for a confidence boost! |
18d9bd9 to
93abe1c
Compare
|
Ah, I missed that reedline PR. This looks very cool from the demo video. Thanks! |
ae30616 to
8ac1545
Compare
|
@fdncred Following up here :) |
|
@philocalyst Your reedline PR needs to be landed first and it looks like you haven't responded to comments there. There's also conflicts here. |
|
It's not real clear to me which parts of this work on Windows and which do not. I don't really like adding unix-only things. |
|
@fdncred Managed to make it cross-platform -- windows has a similar flag I'm making use of. I don't have a windows machine to test on, so I got $llm to create a test for it that verifies the case -- but the flag was created as a 1:1 replacement of the unix one, so I'd be surprised if it doesn't work. Also removed the panic-case with a classic fallback ! Just waiting on the second-pass for my reedline PR. Thank you to @blindFS too! The code is simpler now |
e4c3498 to
278af5d
Compare
5b85219 to
075247d
Compare
|
So it does seem to fail because of reedline :( Should I uncomment? |
075247d to
8bc1ee4
Compare
|
it is uncommented in the latest main branch. seems like you need to rebase on main. |
8bc1ee4 to
4ef901e
Compare
|
Should be better than ever! Spent two hours chasing down a bug with completions that was already fixed upstream lmao, sorry for the delay :) |
did some general simplifications with the final diff in hand, mainly around error handling and how we route data through
3686cf3 to
842bb6b
Compare
|
Thanks! Looking forward to having this. |
|
There is a little something weird happening with this PR. @philocalyst Why does it complete to some intermediate list and then when I hit the down arrow look like regular nushell completions? |
|
Hi @philocalyst, I wonder if there's a way to fallback to the blocking completer somehow. Because I want to draw some fzf menus during the external completer call, it causes a lot of reedline troubles, like shown in the screen recording of #18771 |
|
While I greatly appreciate your attempts to improve completions, I'm hitting multiple issues with this commit in place:
cd ~/sr<tab>
# completes to
cd ~/src/c
# then
cd ~/src/ntd-<tab>
# completes to
cd ~/src/c/ntd
# If I hit tab multiple times on the cd ~/src/c
cd ~/src/c<tab>/c<tab>/c...
# => cd ~/src/c/c/c/c/cAll of these are invalid completions/directories. If I restart the shell, the problem goes away for a few commandlines, it seems, then comes back. Again, can't reproduce the trigger condition. Unfortunately it's so bad I'm going to have to build to before this commit for my daily use until fixed or reverted. It's just impossible to navigate the filesystem. And I'm seeing this with others as well, such as |
|
Yup @NotTheDr01ds we know it's bad. @philocalyst is currently working on it. |
|
Don't mean to harp on it if it's already known, but I didn't see any report of the second issue, so wasn't sure. Good to hear it's known. |
It was mentioned in discord, but now there is a separate issue for it |
|
@Juhan280 Can you point me to that issue? I'm not seeing anything that lines up with the problems I'm seeing, at least not from the title. |
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]>
While the worker computes, reedline keeps reading the terminal, so a custom completer that drives an interactive picker (`$candidates | fzf`) paints its UI but never receives a keystroke. Disabling the option makes the REPL completer settle on the reedline thread: reedline blocks on input as it did before nushell#18334, and the completer can hand the terminal to its child. `complete()` is the only path to the worker spawn, so gating it turns off every background piece at once. The cache is bypassed too: an interactive completer is not a pure function, and the pre-nushell#18334 behavior this restores had no completion cache either. The LSP and `commandline complete` already run inline through `CompletionEngine` and are untouched.
While the worker computes, reedline keeps reading the terminal, so a custom completer that drives an interactive picker (`$candidates | fzf`) paints its UI but never receives a keystroke. Disabling the option makes the REPL completer settle on the reedline thread: reedline blocks on input as it did before nushell#18334, and the completer can hand the terminal to its child. `complete()` is the only path to the worker spawn, so gating it turns off every background piece at once. The cache is bypassed too: an interactive completer is not a pure function, and the pre-nushell#18334 behavior this restores had no completion cache either. The LSP and `commandline complete` already run inline through `CompletionEngine` and are untouched.
## Description While the completion worker computes, reedline keeps reading the terminal, so a custom completer that drives an interactive picker (`$candidates | fzf`) paints its UI but never receives a keystroke. This adds a `background-completions` experimental option (`Status::OptOut`, so the async path stays the default). Disabled, the REPL completer settles on the reedline thread: reedline blocks on input as it did before #18334, and the completer can hand the terminal to its child. Scope of the opt-out: - `complete()` is the only path to the worker spawn, so gating it turns off every background piece at once; `poll_completion` stays `Idle`. - The cache is bypassed too: an interactive completer is not a pure function, and the pre-#18334 behavior this restores had no completion cache either, so opting out is faithful to the old behavior rather than a regression against it. - Suggestions still come from the current engine (`fetch_completions_at`): the opt-out restores the old interaction model, not old results. - The LSP and `commandline complete` already run inline through `CompletionEngine` and are untouched. This option exists for configs that need the old blocking semantics back. ## User-facing changes (Release notes) Added the `background-completions` experimental option (enabled by default). Disabling it makes completions block the line editor again, which lets custom completers drive interactive child processes like fzf: ```nushell nu --experimental-options '[background-completions=false]' ``` ## Additional notes fixes #18771


Description
User-facing changes (Release notes)
Additional notes
Screen.Recording.2026-06-03.at.09.32.03.mov
See relevant PR for reedline: nushell/reedline#1093