mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-16 13:49:28 +00:00
fix: library search boosting
Closes #1106 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
@@ -2,7 +2,7 @@ import { Installable } from './installable';
|
||||
|
||||
export interface ArduinoComponent {
|
||||
readonly name: string;
|
||||
readonly deprecated: boolean;
|
||||
readonly deprecated?: boolean;
|
||||
readonly author: string;
|
||||
readonly summary: string;
|
||||
readonly description: string;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import URI from '@theia/core/lib/common/uri';
|
||||
import type { ArduinoComponent } from './arduino-component';
|
||||
|
||||
export interface Searchable<T, O extends Searchable.Options> {
|
||||
search(options: O): Promise<T[]>;
|
||||
@@ -31,3 +32,31 @@ export namespace Searchable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IDE2 must keep the library search order from the CLI but do additional boosting
|
||||
// https://github.com/arduino/arduino-ide/issues/1106
|
||||
// This additional search result boosting considers the following groups: 'Arduino', '', 'Arduino-Retired', and 'Retired'.
|
||||
// If two libraries fall into the same group, the original index is the tiebreaker.
|
||||
export type SortGroup = 'Arduino' | '' | 'Arduino-Retired' | 'Retired';
|
||||
const sortGroupOrder: Record<SortGroup, number> = {
|
||||
Arduino: 0,
|
||||
'': 1,
|
||||
'Arduino-Retired': 2,
|
||||
Retired: 3,
|
||||
};
|
||||
|
||||
export function sortComponents<T extends ArduinoComponent>(
|
||||
components: T[],
|
||||
group: (component: T) => SortGroup
|
||||
): T[] {
|
||||
return components
|
||||
.map((component, index) => ({ ...component, index }))
|
||||
.sort((left, right) => {
|
||||
const leftGroup = group(left);
|
||||
const rightGroup = group(right);
|
||||
if (leftGroup === rightGroup) {
|
||||
return left.index - right.index;
|
||||
}
|
||||
return sortGroupOrder[leftGroup] - sortGroupOrder[rightGroup];
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user