@@ -5,7 +5,7 @@ import { MessageService } from '@theia/core/lib/common/message-service';
5
5
import { StorageService } from '@theia/core/lib/browser/storage-service' ;
6
6
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application' ;
7
7
import { RecursiveRequired } from '../../common/types' ;
8
- import { BoardsServiceClient , AttachedBoardsChangeEvent , BoardInstalledEvent , Board , Port , BoardUninstalledEvent } from '../../common/protocol' ;
8
+ import { BoardsServiceClient , AttachedBoardsChangeEvent , BoardInstalledEvent , Board , Port , BoardUninstalledEvent , BoardsService } from '../../common/protocol' ;
9
9
import { BoardsConfig } from './boards-config' ;
10
10
import { naturalCompare } from '../../common/utils' ;
11
11
@@ -40,6 +40,7 @@ export class BoardsServiceClientImpl implements BoardsServiceClient, FrontendApp
40
40
protected _attachedBoards : Board [ ] = [ ] ; // This does not contain the `Unknown` boards. They're visible from the available ports only.
41
41
protected _availablePorts : Port [ ] = [ ] ;
42
42
protected _availableBoards : AvailableBoard [ ] = [ ] ;
43
+ protected boardsService : BoardsService ;
43
44
44
45
/**
45
46
* Event when the state of the attached/detached boards has changed. For instance, the user have detached a physical board.
@@ -65,7 +66,12 @@ export class BoardsServiceClientImpl implements BoardsServiceClient, FrontendApp
65
66
* When the FE connects to the BE, the BE stets the known boards and ports.\
66
67
* This is a DI workaround for not being able to inject the service into the client.
67
68
*/
68
- init ( { attachedBoards, availablePorts } : { attachedBoards : Board [ ] , availablePorts : Port [ ] } ) : void {
69
+ async init ( boardsService : BoardsService ) : Promise < void > {
70
+ this . boardsService = boardsService ;
71
+ const [ attachedBoards , availablePorts ] = await Promise . all ( [
72
+ this . boardsService . getAttachedBoards ( ) ,
73
+ this . boardsService . getAvailablePorts ( )
74
+ ] ) ;
69
75
this . _attachedBoards = attachedBoards ;
70
76
this . _availablePorts = availablePorts ;
71
77
this . reconcileAvailableBoards ( ) . then ( ( ) => this . tryReconnect ( ) ) ;
@@ -157,6 +163,20 @@ export class BoardsServiceClientImpl implements BoardsServiceClient, FrontendApp
157
163
}
158
164
}
159
165
166
+ async searchBoards ( { query, cores } : { query ?: string , cores ?: string [ ] } ) : Promise < Array < Board & { packageName : string } > > {
167
+ const boards = await this . boardsService . allBoards ( { } ) ;
168
+ const coresFilter = ! ! cores && cores . length
169
+ ? ( ( toFilter : { packageName : string } ) => cores . some ( core => core === toFilter . packageName ) )
170
+ : ( ) => true ;
171
+ const fuzzyFilter = ! ! query
172
+ ? ( ( toFilter : Board ) => ! ! monaco . filters . matchesFuzzy ( query , toFilter . name , true ) )
173
+ : ( ) => true
174
+ return boards
175
+ . filter ( coresFilter )
176
+ . filter ( fuzzyFilter )
177
+ . sort ( Board . compare )
178
+ }
179
+
160
180
get boardsConfig ( ) : BoardsConfig . Config {
161
181
return this . _boardsConfig ;
162
182
}
0 commit comments