@@ -16,7 +16,7 @@ import (
16
16
// It returns a list of fqbn
17
17
// it's taken from cli/board/listall.go
18
18
func GetInstalledBoards () []string {
19
- inst := instance .CreateAndInit () // TODO optimize this: it does not make sense to create an instance everytime
19
+ inst := instance .CreateAndInit ()
20
20
21
21
list , _ := board .ListAll (context .Background (), & rpc.BoardListAllRequest {
22
22
Instance : inst ,
@@ -34,24 +34,25 @@ func GetInstalledBoards() []string {
34
34
// GetInstalledProtocols is an helper function useful to autocomplete.
35
35
// It returns a list of protocols available based on the installed boards
36
36
func GetInstalledProtocols () []string {
37
- inst := instance .CreateAndInit () // TODO optimize this: it does not make sense to create an instance everytime
37
+ inst := instance .CreateAndInit ()
38
38
pm := commands .GetPackageManager (inst .Id )
39
39
boards := pm .InstalledBoards ()
40
40
41
- // use this strange map because it should be more optimized
42
- // we use only the key and not the value because we do not need it
43
- intalledProtocolsMap := make (map [string ]struct {})
41
+ installedProtocols := make (map [string ]struct {})
44
42
for _ , board := range boards {
45
- // we filter and elaborate a bit the informations present in Properties
46
43
for _ , protocol := range board .Properties .SubTree ("upload.tool" ).FirstLevelKeys () {
47
- if protocol != "default" { // remove this value since it's the default one
48
- intalledProtocolsMap [protocol ] = struct {}{}
44
+ if protocol == "default" {
45
+ // default is used as fallback when trying to upload to a board
46
+ // using a protocol not defined for it, it's useless showing it
47
+ // in autocompletion
48
+ continue
49
49
}
50
+ installedProtocols [protocol ] = struct {}{}
50
51
}
51
52
}
52
- res := make ([]string , len (intalledProtocolsMap ))
53
+ res := make ([]string , len (installedProtocols ))
53
54
i := 0
54
- for k := range intalledProtocolsMap {
55
+ for k := range installedProtocols {
55
56
res [i ] = k
56
57
i ++
57
58
}
@@ -61,7 +62,7 @@ func GetInstalledProtocols() []string {
61
62
// GetInstalledProgrammers is an helper function useful to autocomplete.
62
63
// It returns a list of programmers available based on the installed boards
63
64
func GetInstalledProgrammers () []string {
64
- inst := instance .CreateAndInit () // TODO optimize this: it does not make sense to create an instance everytime
65
+ inst := instance .CreateAndInit ()
65
66
pm := commands .GetPackageManager (inst .Id )
66
67
67
68
// we need the list of the available fqbn in order to get the list of the programmers
@@ -72,8 +73,8 @@ func GetInstalledProgrammers() []string {
72
73
})
73
74
74
75
installedProgrammers := make (map [string ]string )
75
- for _ , i := range list .Boards {
76
- fqbn , _ := cores .ParseFQBN (i .Fqbn )
76
+ for _ , board := range list .Boards {
77
+ fqbn , _ := cores .ParseFQBN (board .Fqbn )
77
78
_ , boardPlatform , _ , _ , _ , _ := pm .ResolveFQBN (fqbn )
78
79
for programmerID , programmer := range boardPlatform .Programmers {
79
80
installedProgrammers [programmerID ] = programmer .Name
@@ -92,7 +93,7 @@ func GetInstalledProgrammers() []string {
92
93
// GetUninstallableCores is an helper function useful to autocomplete.
93
94
// It returns a list of cores which can be uninstalled
94
95
func GetUninstallableCores () []string {
95
- inst := instance .CreateAndInit () // TODO optimize this: it does not make sense to create an instance everytime
96
+ inst := instance .CreateAndInit ()
96
97
97
98
platforms , _ := core .GetPlatforms (& rpc.PlatformListRequest {
98
99
Instance : inst ,
@@ -110,7 +111,7 @@ func GetUninstallableCores() []string {
110
111
// GetInstallableCores is an helper function useful to autocomplete.
111
112
// It returns a list of cores which can be installed/downloaded
112
113
func GetInstallableCores () []string {
113
- inst := instance .CreateAndInit () // TODO optimize this: it does not make sense to create an instance everytime
114
+ inst := instance .CreateAndInit ()
114
115
115
116
platforms , _ := core .PlatformSearch (& rpc.PlatformSearchRequest {
116
117
Instance : inst ,
@@ -125,13 +126,23 @@ func GetInstallableCores() []string {
125
126
return res
126
127
}
127
128
128
- // GetUninstallableLibs is an helper function useful to autocomplete.
129
+ // GetInstalledLibraries is an helper function useful to autocomplete.
130
+ // It returns a list of libs which are currently installed, including the builtin ones
131
+ func GetInstalledLibraries () []string {
132
+ return getLibraries (true )
133
+ }
134
+
135
+ // GetUninstallableLibraries is an helper function useful to autocomplete.
129
136
// It returns a list of libs which can be uninstalled
130
- func GetUninstallableLibs () []string {
131
- inst := instance .CreateAndInit () // TODO optimize this: it does not make sense to create an instance everytime
137
+ func GetUninstallableLibraries () []string {
138
+ return getLibraries (false )
139
+ }
140
+
141
+ func getLibraries (all bool ) []string {
142
+ inst := instance .CreateAndInit ()
132
143
libs , _ := lib .LibraryList (context .Background (), & rpc.LibraryListRequest {
133
144
Instance : inst ,
134
- All : false ,
145
+ All : all ,
135
146
Updatable : false ,
136
147
Name : "" ,
137
148
Fqbn : "" ,
@@ -147,7 +158,7 @@ func GetUninstallableLibs() []string {
147
158
// GetInstallableLibs is an helper function useful to autocomplete.
148
159
// It returns a list of libs which can be installed/downloaded
149
160
func GetInstallableLibs () []string {
150
- inst := instance .CreateAndInit () // TODO optimize this: it does not make sense to create an instance everytime
161
+ inst := instance .CreateAndInit ()
151
162
152
163
libs , _ := lib .LibrarySearch (context .Background (), & rpc.LibrarySearchRequest {
153
164
Instance : inst ,
@@ -165,7 +176,7 @@ func GetInstallableLibs() []string {
165
176
// It returns a list of boards which are currently connected
166
177
// Obviously it does not suggests network ports because of the timeout
167
178
func GetConnectedBoards () []string {
168
- inst := instance .CreateAndInit () // TODO optimize this: it does not make sense to create an instance everytime
179
+ inst := instance .CreateAndInit ()
169
180
170
181
list , _ := board .List (& rpc.BoardListRequest {
171
182
Instance : inst ,
0 commit comments