@@ -20,9 +20,9 @@ import (
20
20
"errors"
21
21
"strings"
22
22
23
+ "github.com/arduino/arduino-cli/arduino/utils"
23
24
"github.com/arduino/arduino-cli/commands"
24
25
rpc "github.com/arduino/arduino-cli/rpc/commands"
25
- "github.com/lithammer/fuzzysearch/fuzzy"
26
26
)
27
27
28
28
// maximumSearchDistance is the maximum Levenshtein distance accepted when using fuzzy search.
@@ -36,18 +36,26 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllRe
36
36
return nil , errors .New ("invalid instance" )
37
37
}
38
38
39
- searchArgs := strings .Join (req .SearchArgs , " " )
39
+ searchArgs := []string {}
40
+ for _ , s := range req .SearchArgs {
41
+ searchArgs = append (searchArgs , strings .Trim (s , " " ))
42
+ }
40
43
41
- match := func (toTest []string ) bool {
44
+ match := func (toTest []string ) ( bool , error ) {
42
45
if len (searchArgs ) == 0 {
43
- return true
46
+ return true , nil
44
47
}
45
- for _ , rank := range fuzzy .RankFindNormalizedFold (searchArgs , toTest ) {
46
- if rank .Distance < maximumSearchDistance {
47
- return true
48
+
49
+ for _ , t := range toTest {
50
+ matches , err := utils .Match (t , searchArgs )
51
+ if err != nil {
52
+ return false , err
53
+ }
54
+ if matches {
55
+ return matches , nil
48
56
}
49
57
}
50
- return false
58
+ return false , nil
51
59
}
52
60
53
61
list := & rpc.BoardListAllResp {Boards : []* rpc.BoardListItem {}}
@@ -90,10 +98,11 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllRe
90
98
continue
91
99
}
92
100
93
- toTest := toTest
94
- toTest = append (toTest , strings .Split (board .Name (), " " )... )
101
+ toTest := append (toTest , board .Name ())
95
102
toTest = append (toTest , board .FQBN ())
96
- if ! match (toTest ) {
103
+ if ok , err := match (toTest ); err != nil {
104
+ return nil , err
105
+ } else if ! ok {
97
106
continue
98
107
}
99
108
0 commit comments