@@ -15,16 +15,10 @@ import {
1515} from '../../common/protocol' ;
1616import { BoardsConfig } from './boards-config' ;
1717import { naturalCompare } from '../../common/utils' ;
18- import { compareAnything } from '../theia/monaco/comparers' ;
1918import { NotificationCenter } from '../notification-center' ;
2019import { CommandService } from '@theia/core' ;
2120import { ArduinoCommands } from '../arduino-commands' ;
2221
23- interface BoardMatch {
24- readonly board : BoardWithPackage ;
25- readonly matches : monaco . filters . IMatch [ ] | undefined ;
26- }
27-
2822@injectable ( )
2923export class BoardsServiceProvider implements FrontendApplicationContribution {
3024
@@ -205,38 +199,9 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
205199 }
206200 }
207201
208- async searchBoards ( { query, cores } : { query ?: string , cores ?: string [ ] } ) : Promise < Array < BoardWithPackage > > {
209- const boards = await this . boardsService . allBoards ( { } ) ;
210- const coresFilter = ! ! cores && cores . length
211- ? ( ( toFilter : BoardWithPackage ) => cores . some ( core => core === toFilter . packageName || core === toFilter . packageId ) )
212- : ( ) => true ;
213- if ( ! query ) {
214- return boards . filter ( coresFilter ) . sort ( Board . compare ) ;
215- }
216- const toMatch = ( ( toFilter : BoardWithPackage ) => ( ( { board : toFilter , matches : monaco . filters . matchesFuzzy ( query , toFilter . name , true ) } ) ) ) ;
217- const compareEntries = ( left : BoardMatch , right : BoardMatch , lookFor : string ) => {
218- const leftMatches = left . matches || [ ] ;
219- const rightMatches = right . matches || [ ] ;
220- if ( leftMatches . length && ! rightMatches . length ) {
221- return - 1 ;
222- }
223- if ( ! leftMatches . length && rightMatches . length ) {
224- return 1 ;
225- }
226- if ( leftMatches . length === 0 && rightMatches . length === 0 ) {
227- return 0 ;
228- }
229- const leftLabel = left . board . name . replace ( / \r ? \n / g, ' ' ) ;
230- const rightLabel = right . board . name . replace ( / \r ? \n / g, ' ' ) ;
231- return compareAnything ( leftLabel , rightLabel , lookFor ) ;
232- }
233- const normalizedQuery = query . toLowerCase ( ) ;
234- return boards
235- . filter ( coresFilter )
236- . map ( toMatch )
237- . filter ( ( { matches } ) => ! ! matches )
238- . sort ( ( left , right ) => compareEntries ( left , right , normalizedQuery ) )
239- . map ( ( { board } ) => board ) ;
202+ async searchBoards ( { query, cores } : { query ?: string , cores ?: string [ ] } ) : Promise < BoardWithPackage [ ] > {
203+ const boards = await this . boardsService . searchBoards ( { query } ) ;
204+ return boards ;
240205 }
241206
242207 get boardsConfig ( ) : BoardsConfig . Config {
0 commit comments