@@ -23,27 +23,32 @@ import (
23
23
"github.com/arduino/arduino-cli/arduino/cores"
24
24
"github.com/arduino/arduino-cli/commands"
25
25
rpc "github.com/arduino/arduino-cli/rpc/commands"
26
+ "github.com/lithammer/fuzzysearch/fuzzy"
26
27
)
27
28
29
+ // maximumSearchDistance is the maximum Levenshtein distance accepted when using fuzzy search.
30
+ // This value is completely arbitrary and picked randomly.
31
+ const maximumSearchDistance = 20
32
+
28
33
// ListAll FIXMEDOC
29
34
func ListAll (ctx context.Context , req * rpc.BoardListAllReq ) (* rpc.BoardListAllResp , error ) {
30
35
pm := commands .GetPackageManager (req .GetInstance ().GetId ())
31
36
if pm == nil {
32
37
return nil , errors .New ("invalid instance" )
33
38
}
34
39
35
- args := req .GetSearchArgs ()
36
- match := func (name string ) bool {
37
- if len (args ) == 0 {
40
+ searchArgs := strings .Join (req .SearchArgs , " " )
41
+
42
+ match := func (toTest []string ) bool {
43
+ if len (searchArgs ) == 0 {
38
44
return true
39
45
}
40
- name = strings .ToLower (name )
41
- for _ , term := range args {
42
- if ! strings .Contains (name , strings .ToLower (term )) {
43
- return false
46
+ for _ , rank := range fuzzy .RankFindNormalizedFold (searchArgs , toTest ) {
47
+ if rank .Distance < maximumSearchDistance {
48
+ return true
44
49
}
45
50
}
46
- return true
51
+ return false
47
52
}
48
53
49
54
list := & rpc.BoardListAllResp {Boards : []* rpc.BoardListItem {}}
@@ -85,13 +90,26 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllRe
85
90
platformRelease = latestPlatformRelease
86
91
}
87
92
93
+ toTest := []string {
94
+ platform .String (),
95
+ platform .Name ,
96
+ platform .Architecture ,
97
+ targetPackage .Name ,
98
+ targetPackage .Maintainer ,
99
+ }
100
+
88
101
for _ , board := range platformRelease .Boards {
89
- if ! match ( board .Name () ) {
102
+ if ! req . GetIncludeHiddenBoards () && board .IsHidden ( ) {
90
103
continue
91
104
}
92
- if ! req .GetIncludeHiddenBoards () && board .IsHidden () {
105
+
106
+ toTest := toTest
107
+ toTest = append (toTest , strings .Split (board .Name (), " " )... )
108
+ toTest = append (toTest , board .FQBN ())
109
+ if ! match (toTest ) {
93
110
continue
94
111
}
112
+
95
113
list .Boards = append (list .Boards , & rpc.BoardListItem {
96
114
Name : board .Name (),
97
115
FQBN : board .FQBN (),
0 commit comments