-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback to file completer in custom/external completer #14781
Conversation
Sorry, accidentally deleted the branch while pruning stale branches on my fork |
I'm thinking about another solution, what about making pub struct CustomCompletion<T: Completer> {
stack: Stack,
decl_id: DeclId,
line: String,
fallback: T
} Then if it evals |
@WindSoilder Great idea! That also means |
Sorry if this is off-topic, but there should be a way to configure the external completer so that it overrides internal completion. That way, completion becomes entirely customizable by the user (instead of trying to guess what the user wants in these kind of situations). TLDR
This would be very nice. |
cdd112c
to
de24ae5
Compare
@WindSoilder Implemented your solution, it works well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
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 (includingnull
), 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 toCustomCompletions
that's checked after calling itsfetch()
method. Iffallback
is true, then we use file completions afterwards.An alternative would be to make
CustomCompletions
no longer implement theCompleter
trait, and instead have itsfetch()
method return anOption<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.