@@ -12,6 +12,7 @@ import { Emitter } from '@theia/core/lib/common/event';
12
12
import { ILogger } from '@theia/core/lib/common/logger' ;
13
13
import { MessageService } from '@theia/core/lib/common/message-service' ;
14
14
import { nls } from '@theia/core/lib/common/nls' ;
15
+ import { deepClone } from '@theia/core/lib/common/objects' ;
15
16
import { Deferred } from '@theia/core/lib/common/promise-util' ;
16
17
import type { Mutable } from '@theia/core/lib/common/types' ;
17
18
import { inject , injectable , optional } from '@theia/core/shared/inversify' ;
@@ -21,31 +22,32 @@ import {
21
22
} from '@theia/output/lib/browser/output-channel' ;
22
23
import {
23
24
BoardIdentifier ,
24
- boardIdentifierEquals ,
25
+ BoardUserField ,
26
+ BoardWithPackage ,
25
27
BoardsConfig ,
26
28
BoardsConfigChangeEvent ,
27
29
BoardsPackage ,
28
30
BoardsService ,
29
- BoardUserField ,
30
- BoardWithPackage ,
31
31
DetectedPorts ,
32
+ Port ,
33
+ PortIdentifier ,
34
+ boardIdentifierEquals ,
32
35
emptyBoardsConfig ,
33
36
isBoardIdentifier ,
34
37
isBoardIdentifierChangeEvent ,
35
38
isPortIdentifier ,
36
39
isPortIdentifierChangeEvent ,
37
- Port ,
38
- PortIdentifier ,
39
40
portIdentifierEquals ,
41
+ sanitizeFqbn ,
40
42
serializePlatformIdentifier ,
41
43
} from '../../common/protocol' ;
42
44
import {
43
45
BoardList ,
44
46
BoardListHistory ,
45
- createBoardList ,
46
47
EditBoardsConfigActionParams ,
47
- isBoardListHistory ,
48
48
SelectBoardsConfigActionParams ,
49
+ createBoardList ,
50
+ isBoardListHistory ,
49
51
} from '../../common/protocol/board-list' ;
50
52
import type { Defined } from '../../common/types' ;
51
53
import type {
@@ -104,6 +106,21 @@ type BoardListHistoryUpdateResult =
104
106
type BoardToSelect = BoardIdentifier | undefined | 'ignore-board' ;
105
107
type PortToSelect = PortIdentifier | undefined | 'ignore-port' ;
106
108
109
+ function sanitizeBoardToSelectFQBN ( board : BoardToSelect ) : BoardToSelect {
110
+ if ( isBoardIdentifier ( board ) ) {
111
+ return sanitizeBoardIdentifierFQBN ( board ) ;
112
+ }
113
+ return board ;
114
+ }
115
+ function sanitizeBoardIdentifierFQBN ( board : BoardIdentifier ) : BoardIdentifier {
116
+ if ( board . fqbn ) {
117
+ const copy : Mutable < BoardIdentifier > = deepClone ( board ) ;
118
+ copy . fqbn = sanitizeFqbn ( board . fqbn ) ;
119
+ return copy ;
120
+ }
121
+ return board ;
122
+ }
123
+
107
124
interface UpdateBoardListHistoryParams {
108
125
readonly portToSelect : PortToSelect ;
109
126
readonly boardToSelect : BoardToSelect ;
@@ -356,7 +373,8 @@ export class BoardsServiceProvider
356
373
portToSelect !== 'ignore-port' &&
357
374
! portIdentifierEquals ( portToSelect , previousSelectedPort ) ;
358
375
const boardDidChangeEvent = boardDidChange
359
- ? { selectedBoard : boardToSelect , previousSelectedBoard }
376
+ ? // The change event must always contain any custom board options. Hence the board to select is not sanitized.
377
+ { selectedBoard : boardToSelect , previousSelectedBoard }
360
378
: undefined ;
361
379
const portDidChangeEvent = portDidChange
362
380
? { selectedPort : portToSelect , previousSelectedPort }
@@ -377,11 +395,22 @@ export class BoardsServiceProvider
377
395
return false ;
378
396
}
379
397
380
- this . maybeUpdateBoardListHistory ( { portToSelect, boardToSelect } ) ;
381
- this . maybeUpdateBoardsData ( { boardToSelect, reason } ) ;
398
+ // unlike for the board change event, every persistent state must not contain custom board config options in the FQBN
399
+ const sanitizedBoardToSelect = sanitizeBoardToSelectFQBN ( boardToSelect ) ;
400
+
401
+ this . maybeUpdateBoardListHistory ( {
402
+ portToSelect,
403
+ boardToSelect : sanitizedBoardToSelect ,
404
+ } ) ;
405
+ this . maybeUpdateBoardsData ( {
406
+ boardToSelect : sanitizedBoardToSelect ,
407
+ reason,
408
+ } ) ;
382
409
383
410
if ( isBoardIdentifierChangeEvent ( event ) ) {
384
- this . _boardsConfig . selectedBoard = event . selectedBoard ;
411
+ this . _boardsConfig . selectedBoard = event . selectedBoard
412
+ ? sanitizeBoardIdentifierFQBN ( event . selectedBoard )
413
+ : event . selectedBoard ;
385
414
}
386
415
if ( isPortIdentifierChangeEvent ( event ) ) {
387
416
this . _boardsConfig . selectedPort = event . selectedPort ;
0 commit comments