mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-14 02:57:52 +08:00
parent
1875b1a7ad
commit
6fe68e3744
|
@ -142,12 +142,20 @@ func filterRawCandidates(ev *eval.Evaler, matcher eval.Callable, seed string, ch
|
|||
matcherInput := make(chan interface{})
|
||||
stopCollector := make(chan struct{})
|
||||
var collected []rawCandidate
|
||||
seen := make(map[string]bool)
|
||||
// Get all values from from chanRawCandidate, remove duplicates, collect
|
||||
// them and forward them to the input channel of the matcher.
|
||||
go func() {
|
||||
defer close(matcherInput)
|
||||
for rc := range chanRawCandidate {
|
||||
text := rc.text()
|
||||
if seen[text] {
|
||||
continue
|
||||
}
|
||||
seen[text] = true
|
||||
collected = append(collected, rc)
|
||||
select {
|
||||
case matcherInput <- rc.text():
|
||||
case matcherInput <- text:
|
||||
case <-stopCollector:
|
||||
return
|
||||
}
|
||||
|
@ -155,6 +163,8 @@ func filterRawCandidates(ev *eval.Evaler, matcher eval.Callable, seed string, ch
|
|||
}()
|
||||
defer close(stopCollector)
|
||||
|
||||
// Run the matcher.
|
||||
|
||||
ports := []*eval.Port{
|
||||
{Chan: matcherInput, File: eval.DevNull}, {File: os.Stdout}, {File: os.Stderr}}
|
||||
ec := eval.NewTopFrame(ev, eval.NewInternalSource("[editor matcher]"), ports)
|
||||
|
@ -167,6 +177,7 @@ func filterRawCandidates(ev *eval.Evaler, matcher eval.Callable, seed string, ch
|
|||
return nil, errIncorrectNumOfResults
|
||||
}
|
||||
|
||||
// Use the matcher results to filter the collected raw candidates.
|
||||
var filtered []rawCandidate
|
||||
for i, value := range values {
|
||||
if vals.Bool(value) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user