fix: library search boosting

Closes #1106

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta
2023-02-07 13:19:55 +01:00
committed by Akos Kitta
parent 5d264ef5b6
commit 79b6b7ecc0
14 changed files with 627 additions and 346 deletions

View File

@@ -17,6 +17,8 @@ import {
BoardWithPackage,
BoardUserField,
BoardSearch,
sortComponents,
SortGroup,
} from '../common/protocol';
import {
PlatformInstallRequest,
@@ -405,7 +407,8 @@ export class BoardsServiceImpl
}
const filter = this.typePredicate(options);
return [...packages.values()].filter(filter);
const boardsPackages = [...packages.values()].filter(filter);
return sortComponents(boardsPackages, boardsPackageSortGroup);
}
private typePredicate(
@@ -559,3 +562,14 @@ function isMissingPlatformError(error: unknown): boolean {
}
return false;
}
function boardsPackageSortGroup(boardsPackage: BoardsPackage): SortGroup {
const types: string[] = [];
if (boardsPackage.types.includes('Arduino')) {
types.push('Arduino');
}
if (boardsPackage.deprecated) {
types.push('Retired');
}
return types.join('-') as SortGroup;
}