diff --git a/arduino-ide-extension/src/browser/contributions/examples.ts b/arduino-ide-extension/src/browser/contributions/examples.ts index 48009509..86ae30d3 100644 --- a/arduino-ide-extension/src/browser/contributions/examples.ts +++ b/arduino-ide-extension/src/browser/contributions/examples.ts @@ -154,15 +154,14 @@ export class LibraryExamples extends Examples { protected async register(board: Board | undefined = this.boardsServiceClient.boardsConfig.selectedBoard): Promise { return this.queue.add(async () => { this.toDispose.dispose(); - if (!board || !board.fqbn) { - return; - } - const { fqbn, name } = board; + const fqbn = board?.fqbn; + const name = board?.name; + // Shows all examples when no board is selected, or the platform of the currently selected board is not installed. const { user, current, any } = await this.examplesService.installed({ fqbn }); if (user.length) { (user as any).unshift('Examples from Custom Libraries'); } - if (current.length) { + if (name && fqbn && current.length) { (current as any).unshift(`Examples for ${name}`); } if (any.length) { diff --git a/arduino-ide-extension/src/common/protocol/examples-service.ts b/arduino-ide-extension/src/common/protocol/examples-service.ts index 2d511c0f..994291f6 100644 --- a/arduino-ide-extension/src/common/protocol/examples-service.ts +++ b/arduino-ide-extension/src/common/protocol/examples-service.ts @@ -4,7 +4,7 @@ export const ExamplesServicePath = '/services/example-service'; export const ExamplesService = Symbol('ExamplesService'); export interface ExamplesService { builtIns(): Promise; - installed(options: { fqbn: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }>; + installed(options: { fqbn?: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }>; } diff --git a/arduino-ide-extension/src/node/examples-service-impl.ts b/arduino-ide-extension/src/node/examples-service-impl.ts index 5b16adad..4fa25feb 100644 --- a/arduino-ide-extension/src/node/examples-service-impl.ts +++ b/arduino-ide-extension/src/node/examples-service-impl.ts @@ -40,22 +40,20 @@ export class ExamplesServiceImpl implements ExamplesService { } // TODO: decide whether it makes sense to cache them. Keys should be: `fqbn` + version of containing core/library. - async installed({ fqbn }: { fqbn: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }> { + async installed({ fqbn }: { fqbn?: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }> { const user: SketchContainer[] = []; const current: SketchContainer[] = []; const any: SketchContainer[] = []; - if (fqbn) { - const packages: LibraryPackage[] = await this.libraryService.list({ fqbn }); - for (const pkg of packages) { - const container = await this.tryGroupExamples(pkg); - const { location } = pkg; - if (location === LibraryLocation.USER) { - user.push(container); - } else if (location === LibraryLocation.PLATFORM_BUILTIN || LibraryLocation.REFERENCED_PLATFORM_BUILTIN) { - current.push(container); - } else { - any.push(container); - } + const packages: LibraryPackage[] = await this.libraryService.list({ fqbn }); + for (const pkg of packages) { + const container = await this.tryGroupExamples(pkg); + const { location } = pkg; + if (location === LibraryLocation.USER) { + user.push(container); + } else if (location === LibraryLocation.PLATFORM_BUILTIN || LibraryLocation.REFERENCED_PLATFORM_BUILTIN) { + current.push(container); + } else { + any.push(container); } } return { user, current, any }; diff --git a/arduino-ide-extension/src/node/library-service-server-impl.ts b/arduino-ide-extension/src/node/library-service-server-impl.ts index 1946a750..5c3cc84f 100644 --- a/arduino-ide-extension/src/node/library-service-server-impl.ts +++ b/arduino-ide-extension/src/node/library-service-server-impl.ts @@ -83,8 +83,9 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic const { client, instance } = coreClient; const req = new LibraryListReq(); req.setInstance(instance); - req.setAll(true); if (fqbn) { + // Only get libraries from the cores when the FQBN is defined. Otherwise, we retrieve user installed libraries only. + req.setAll(true); // https://github.com/arduino/arduino-ide/pull/303#issuecomment-815556447 req.setFqbn(fqbn); }