-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Enable closing of fuzzyfinder from the caller by passing context #165
Conversation
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 for your contribution!
I think that it makes sense to provide an option that accepts context 👍
Almost the implementation looks good, but I suggested some trivial points. Could you work on them when you have time?
fuzzyfinder.go
Outdated
@@ -94,6 +98,12 @@ func (f *finder) initFinder(items []string, matched []matching.Matched, opt opt) | |||
if err := f.term.Init(); err != nil { | |||
return errors.Wrap(err, "failed to initialize screen") | |||
} | |||
|
|||
eventsChan := make(chan tcell.Event) | |||
quitChan := make(chan struct{}) |
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.
This channel is not used anywhere so we can use a nil channel.
fuzzyfinder.go
Outdated
@@ -25,6 +25,7 @@ import ( | |||
var ( | |||
// ErrAbort is returned from Find* functions if there are no selections. | |||
ErrAbort = errors.New("abort") | |||
ErrCancel = errors.New("cancel") |
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.
I think that we don't need a self-defined cancellation error. Context is a standard mechanism, so how about returning ctx.Err()
simply?
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #165 +/- ##
==========================================
- Coverage 87.68% 87.42% -0.26%
==========================================
Files 5 5
Lines 828 851 +23
==========================================
+ Hits 726 744 +18
- Misses 89 94 +5
Partials 13 13 |
Co-authored-by: ktr <[email protected]>
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.
LGTM. Thank you!
This PR adds a new option called
WithContext
. This enables callers offuzzyfinder.Find
to cancel the passed context and forcefully makeFind
return if completing it is no longer desirable.An example use case is when
Find
is called with theWithHotReload
option, but the caller does not have any items to put in the slice (e.g due to a failed network call).Please let me know what you think!