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