nushell/crates/nu-cli
Yash Thakur a011791631
Fallback to file completer in custom/external completer (#14781)
# Description

Closes #14595. This modifies the behavior of both custom and external
completers so that if the custom/external completer returns an invalid
value, completions are suppressed and an error is logged. However, if
the completer returns `null` (which this PR treats as a special value),
we fall back to file completions.

Previously, custom completers and external completers had different
behavior. Any time an external completer returned an invalid value
(including `null`), we would fall back to file completions. Any time a
custom completer returned an invalid value (including `null`), we would
suppress completions.

I'm not too happy about the implementation, but it's the least intrusive
way I could think of to do it. I added a `fallback` field to
`CustomCompletions` that's checked after calling its `fetch()` method.
If `fallback` is true, then we use file completions afterwards.

An alternative would be to make `CustomCompletions` no longer implement
the `Completer` trait, and instead have its `fetch()` method return an
`Option<Vec<Suggestion>>`. But that resulted in a teeny bit of code
duplication.

# User-Facing Changes

For those using an external completer, if they want to fall back to file
completions on invalid values, their completer will have to explicitly
return `null`. Returning `"foo"` or something will no longer make
Nushell use file completions instead.

For those making custom completers, they now have the option to fall
back to file completions.

# Tests + Formatting

Added some tests and manually tested that if the completer returns an
invalid value or the completer throws an error, that gets logged and
completions are suppressed.

# After Submitting

The documentation for custom completions and external completers will
have to be updated after this.
2025-01-26 13:44:01 +08:00
..
src Fallback to file completer in custom/external completer (#14781) 2025-01-26 13:44:01 +08:00
tests Fallback to file completer in custom/external completer (#14781) 2025-01-26 13:44:01 +08:00
Cargo.toml Use nucleo instead of skim for completions (#14846) 2025-01-17 06:24:00 -06:00
LICENSE Fix rest of license year ranges (#8727) 2023-04-04 09:03:29 +12:00
README.md Add top-level crate documentation/READMEs (#12907) 2024-07-14 10:10:41 +02:00

This crate implements the core functionality of the interactive Nushell REPL and interfaces with reedline. Currently implements the syntax highlighting and completions logic. Furthermore includes a few commands that are specific to reedline

Internal Nushell crate

This crate implements components of Nushell and is not designed to support plugin authors or other users directly.