mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-13 20:29:27 +00:00
fix: library search boosting
Closes #1106 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
import { injectable, inject } from '@theia/core/shared/inversify';
|
||||
import { ILogger, notEmpty } from '@theia/core';
|
||||
import { FileUri } from '@theia/core/lib/node';
|
||||
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||
import { duration } from '../common/decorators';
|
||||
import {
|
||||
NotificationServiceServer,
|
||||
ResponseService,
|
||||
sortComponents,
|
||||
SortGroup,
|
||||
} from '../common/protocol';
|
||||
import { Installable } from '../common/protocol/installable';
|
||||
import {
|
||||
LibraryDependency,
|
||||
LibraryLocation,
|
||||
@@ -6,29 +16,24 @@ import {
|
||||
LibrarySearch,
|
||||
LibraryService,
|
||||
} from '../common/protocol/library-service';
|
||||
import { CoreClientAware } from './core-client-provider';
|
||||
import { BoardDiscovery } from './board-discovery';
|
||||
import {
|
||||
InstalledLibrary,
|
||||
Library,
|
||||
LibraryInstallLocation,
|
||||
LibraryInstallRequest,
|
||||
LibraryListRequest,
|
||||
LibraryListResponse,
|
||||
LibraryLocation as GrpcLibraryLocation,
|
||||
LibraryRelease,
|
||||
LibraryResolveDependenciesRequest,
|
||||
LibraryUninstallRequest,
|
||||
ZipLibraryInstallRequest,
|
||||
LibrarySearchRequest,
|
||||
LibrarySearchResponse,
|
||||
LibraryInstallLocation,
|
||||
LibraryUninstallRequest,
|
||||
ZipLibraryInstallRequest,
|
||||
} from './cli-protocol/cc/arduino/cli/commands/v1/lib_pb';
|
||||
import { Installable } from '../common/protocol/installable';
|
||||
import { ILogger, notEmpty } from '@theia/core';
|
||||
import { FileUri } from '@theia/core/lib/node';
|
||||
import { ResponseService, NotificationServiceServer } from '../common/protocol';
|
||||
import { CoreClientAware } from './core-client-provider';
|
||||
import { ExecuteWithProgress } from './grpc-progressible';
|
||||
import { duration } from '../common/decorators';
|
||||
|
||||
@injectable()
|
||||
export class LibraryServiceImpl
|
||||
@@ -108,7 +113,10 @@ export class LibraryServiceImpl
|
||||
|
||||
const typePredicate = this.typePredicate(options);
|
||||
const topicPredicate = this.topicPredicate(options);
|
||||
return items.filter((item) => typePredicate(item) && topicPredicate(item));
|
||||
const libraries = items.filter(
|
||||
(item) => typePredicate(item) && topicPredicate(item)
|
||||
);
|
||||
return sortComponents(libraries, librarySortGroup);
|
||||
}
|
||||
|
||||
private typePredicate(
|
||||
@@ -448,7 +456,6 @@ function toLibrary(
|
||||
name: '',
|
||||
exampleUris: [],
|
||||
installable: false,
|
||||
deprecated: false,
|
||||
location: 0,
|
||||
...pkg,
|
||||
|
||||
@@ -462,3 +469,14 @@ function toLibrary(
|
||||
types: lib.getTypesList(),
|
||||
};
|
||||
}
|
||||
|
||||
// Libraries do not have a deprecated property. The deprecated information is inferred if 'Retired' is in 'types'
|
||||
function librarySortGroup(library: LibraryPackage): SortGroup {
|
||||
const types: string[] = [];
|
||||
for (const type of ['Arduino', 'Retired']) {
|
||||
if (library.types.includes(type)) {
|
||||
types.push(type);
|
||||
}
|
||||
}
|
||||
return types.join('-') as SortGroup;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user