@@ -44,8 +44,8 @@ import {
4444 isBoardListHistory ,
4545 SelectBoardsConfigActionParams ,
4646} from '../../common/protocol/board-list' ;
47- import { Defined } from '../../common/types' ;
48- import {
47+ import type { Defined } from '../../common/types' ;
48+ import type {
4949 StartupTask ,
5050 StartupTaskProvider ,
5151} from '../../electron-common/startup-task' ;
@@ -200,48 +200,6 @@ export class BoardsServiceProvider
200200 this . boardListDumper ?. dispose ( ) ;
201201 }
202202
203- private async maybeUpdateSelectedBoard ( platformDidInstallEvent : {
204- item : BoardsPackage ;
205- } ) : Promise < void > {
206- const { selectedBoard } = this . _boardsConfig ;
207- if (
208- selectedBoard &&
209- ! selectedBoard . fqbn &&
210- BoardWithPackage . is ( selectedBoard )
211- ) {
212- const selectedBoardPlatformId = serializePlatformIdentifier (
213- selectedBoard . packageId
214- ) ;
215- if ( selectedBoardPlatformId === platformDidInstallEvent . item . id ) {
216- const installedSelectedBoard = platformDidInstallEvent . item . boards . find (
217- ( board ) => board . name === selectedBoard . name
218- ) ;
219- // if the board can be found by its name after the install event select it. otherwise unselect it
220- // historical hint: https://github.com/arduino/arduino-ide/blob/144df893d0dafec64a26565cf912a98f32572da9/arduino-ide-extension/src/browser/boards/boards-service-provider.ts#L289-L320
221- this . updateBoard ( installedSelectedBoard ) ;
222- if ( ! installedSelectedBoard ) {
223- const yes = nls . localize ( 'vscode/extensionsUtils/yes' , 'Yes' ) ;
224- const answer = await this . messageService . warn (
225- nls . localize (
226- 'arduino/board/couldNotFindPreviouslySelected' ,
227- "Could not find previously selected board '{0}' in installed platform '{1}'. Please manually reselect the board you want to use. Do you want to reselect it now?" ,
228- selectedBoard . name ,
229- platformDidInstallEvent . item . name
230- ) ,
231- nls . localize ( 'arduino/board/reselectLater' , 'Reselect later' ) ,
232- yes
233- ) ;
234- if ( answer === yes ) {
235- this . onBoardsConfigEdit ( {
236- query : selectedBoard . name ,
237- portToSelect : this . _boardsConfig . selectedPort ,
238- } ) ;
239- }
240- }
241- }
242- }
243- }
244-
245203 registerCommands ( registry : CommandRegistry ) : void {
246204 registry . registerCommand ( USE_INHERITED_CONFIG , {
247205 execute : (
@@ -285,6 +243,48 @@ export class BoardsServiceProvider
285243 ] ;
286244 }
287245
246+ private async maybeUpdateSelectedBoard ( platformDidInstallEvent : {
247+ item : BoardsPackage ;
248+ } ) : Promise < void > {
249+ const { selectedBoard } = this . _boardsConfig ;
250+ if (
251+ selectedBoard &&
252+ ! selectedBoard . fqbn &&
253+ BoardWithPackage . is ( selectedBoard )
254+ ) {
255+ const selectedBoardPlatformId = serializePlatformIdentifier (
256+ selectedBoard . packageId
257+ ) ;
258+ if ( selectedBoardPlatformId === platformDidInstallEvent . item . id ) {
259+ const installedSelectedBoard = platformDidInstallEvent . item . boards . find (
260+ ( board ) => board . name === selectedBoard . name
261+ ) ;
262+ // if the board can be found by its name after the install event select it. otherwise unselect it
263+ // historical hint: https://github.com/arduino/arduino-ide/blob/144df893d0dafec64a26565cf912a98f32572da9/arduino-ide-extension/src/browser/boards/boards-service-provider.ts#L289-L320
264+ this . updateBoard ( installedSelectedBoard ) ;
265+ if ( ! installedSelectedBoard ) {
266+ const yes = nls . localize ( 'vscode/extensionsUtils/yes' , 'Yes' ) ;
267+ const answer = await this . messageService . warn (
268+ nls . localize (
269+ 'arduino/board/couldNotFindPreviouslySelected' ,
270+ "Could not find previously selected board '{0}' in installed platform '{1}'. Please manually reselect the board you want to use. Do you want to reselect it now?" ,
271+ selectedBoard . name ,
272+ platformDidInstallEvent . item . name
273+ ) ,
274+ nls . localize ( 'arduino/board/reselectLater' , 'Reselect later' ) ,
275+ yes
276+ ) ;
277+ if ( answer === yes ) {
278+ this . onBoardsConfigEdit ( {
279+ query : selectedBoard . name ,
280+ portToSelect : this . _boardsConfig . selectedPort ,
281+ } ) ;
282+ }
283+ }
284+ }
285+ }
286+ }
287+
288288 private refreshBoardList ( params ?: RefreshBoardListParams ) : void {
289289 if ( params ?. detectedPorts ) {
290290 this . _detectedPorts = params . detectedPorts ;
@@ -344,16 +344,30 @@ export class BoardsServiceProvider
344344 reason
345345 ) ;
346346 } else if ( selectedBoard ) {
347- this . updateBoard ( selectedBoard ) ;
347+ this . updateConfig ( selectedBoard ) ;
348348 } else if ( selectedPort ) {
349- this . updatePort ( selectedPort ) ;
349+ this . updateConfig ( selectedPort ) ;
350350 }
351351 }
352352
353353 updateConfig (
354354 boardsConfig : Defined < BoardsConfig > ,
355355 reason ?: UpdateBoardsConfigReason
356+ ) : boolean ;
357+ updateConfig ( selectedBoard : BoardIdentifier ) : boolean ;
358+ updateConfig ( selectedPort : PortIdentifier ) : boolean ;
359+ updateConfig (
360+ arg : Defined < BoardsConfig > | BoardIdentifier | PortIdentifier ,
361+ reason ?: UpdateBoardsConfigReason
356362 ) : boolean {
363+ if ( isBoardIdentifier ( arg ) ) {
364+ return this . updateBoard ( arg ) ;
365+ }
366+ if ( isPortIdentifier ( arg ) ) {
367+ return this . updatePort ( arg ) ;
368+ }
369+
370+ const boardsConfig = arg ;
357371 const selectedBoard = boardsConfig . selectedBoard ;
358372 const previousSelectedBoard = this . _boardsConfig . selectedBoard ;
359373 const selectedPort = boardsConfig . selectedPort ;
@@ -400,7 +414,9 @@ export class BoardsServiceProvider
400414 return true ;
401415 }
402416
403- updateBoard ( selectedBoard : BoardIdentifier | undefined ) : boolean {
417+ // `undefined` is special case when a non installed board is selected (no FQBN), the platform is installed,
418+ // but there is no way to determine the FQBN from the previous partial data, and IDE2 unsets the board.
419+ private updateBoard ( selectedBoard : BoardIdentifier | undefined ) : boolean {
404420 const previousSelectedBoard = this . _boardsConfig . selectedBoard ;
405421 if ( boardIdentifierEquals ( previousSelectedBoard , selectedBoard ) ) {
406422 // NOOP if they're the same
@@ -416,7 +432,7 @@ export class BoardsServiceProvider
416432 return true ;
417433 }
418434
419- updatePort ( selectedPort : PortIdentifier | undefined ) : boolean {
435+ private updatePort ( selectedPort : PortIdentifier ) : boolean {
420436 const selectedBoard = this . _boardsConfig . selectedBoard ;
421437 const previousSelectedPort = this . _boardsConfig . selectedPort ;
422438 if ( selectedPort && selectedBoard ) {
0 commit comments