Skip to content

Commit dd10436

Browse files
author
Akos Kitta
committed
Fixed the Platform ordering.
We have to pick the installed version first. Otherwise we lose the FQBN of the boards. FBQN is used to check if a board has the corresponding core installed. Signed-off-by: Akos Kitta <[email protected]>
1 parent e79d42d commit dd10436

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

arduino-ide-extension/src/node/boards-service-impl.ts

+34-5
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,43 @@ export class BoardsServiceImpl implements BoardsService {
249249
}
250250
}
251251

252+
// We must group the cores by ID, and sort platforms by, first the installed version, then version alphabetical order.
253+
// Otherwise we lose the FQBN information.
254+
const groupedById: Map<string, Platform[]> = new Map();
252255
for (const platform of resp.getSearchOutputList()) {
253256
const id = platform.getId();
254-
const pkg = packages.get(id);
255-
if (pkg) {
256-
pkg.availableVersions.push(platform.getLatest());
257-
pkg.availableVersions.sort(Installable.Version.COMPARATOR);
257+
if (groupedById.has(id)) {
258+
groupedById.get(id)!.push(platform);
258259
} else {
259-
packages.set(id, toPackage(platform));
260+
groupedById.set(id, [platform]);
261+
}
262+
}
263+
const installedAwareVersionComparator = (left: Platform, right: Platform) => {
264+
// XXX: we cannot rely on `platform.getInstalled()`, it is always an empty string.
265+
const leftInstalled = !!installedPlatforms.find(ip => ip.getId() === left.getId() && ip.getInstalled() === left.getLatest());
266+
const rightInstalled = !!installedPlatforms.find(ip => ip.getId() === right.getId() && ip.getInstalled() === right.getLatest());
267+
if (leftInstalled && !rightInstalled) {
268+
return -1;
269+
}
270+
if (!leftInstalled && rightInstalled) {
271+
return 1;
272+
}
273+
return Installable.Version.COMPARATOR(right.getLatest(), left.getLatest()); // Higher version comes first.
274+
}
275+
for (const id of groupedById.keys()) {
276+
groupedById.get(id)!.sort(installedAwareVersionComparator);
277+
}
278+
279+
for (const id of groupedById.keys()) {
280+
for (const platform of groupedById.get(id)!) {
281+
const id = platform.getId();
282+
const pkg = packages.get(id);
283+
if (pkg) {
284+
pkg.availableVersions.push(platform.getLatest());
285+
pkg.availableVersions.sort(Installable.Version.COMPARATOR);
286+
} else {
287+
packages.set(id, toPackage(platform));
288+
}
260289
}
261290
}
262291

0 commit comments

Comments
 (0)