Skip to content

Commit 68af4c3

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
ATL-1195: Show examples if no board is selected.
Show all examples: - when no board is selected, - when the core is not installed for the selected board. Otherwise, show examples for the currently selected board only. Only get libraries from the cores when the FQBN is defined. Otherwise, we retrieve user installed libraries only. Signed-off-by: Akos Kitta <[email protected]>
1 parent a8df244 commit 68af4c3

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/examples.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,14 @@ export class LibraryExamples extends Examples {
154154
protected async register(board: Board | undefined = this.boardsServiceClient.boardsConfig.selectedBoard): Promise<void> {
155155
return this.queue.add(async () => {
156156
this.toDispose.dispose();
157-
if (!board || !board.fqbn) {
158-
return;
159-
}
160-
const { fqbn, name } = board;
157+
const fqbn = board?.fqbn;
158+
const name = board?.name;
159+
// Shows all examples when no board is selected, or the platform of the currently selected board is not installed.
161160
const { user, current, any } = await this.examplesService.installed({ fqbn });
162161
if (user.length) {
163162
(user as any).unshift('Examples from Custom Libraries');
164163
}
165-
if (current.length) {
164+
if (name && fqbn && current.length) {
166165
(current as any).unshift(`Examples for ${name}`);
167166
}
168167
if (any.length) {

Diff for: arduino-ide-extension/src/common/protocol/examples-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const ExamplesServicePath = '/services/example-service';
44
export const ExamplesService = Symbol('ExamplesService');
55
export interface ExamplesService {
66
builtIns(): Promise<SketchContainer[]>;
7-
installed(options: { fqbn: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }>;
7+
installed(options: { fqbn?: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }>;
88
}
99

1010

Diff for: arduino-ide-extension/src/node/examples-service-impl.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,20 @@ export class ExamplesServiceImpl implements ExamplesService {
4040
}
4141

4242
// TODO: decide whether it makes sense to cache them. Keys should be: `fqbn` + version of containing core/library.
43-
async installed({ fqbn }: { fqbn: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }> {
43+
async installed({ fqbn }: { fqbn?: string }): Promise<{ user: SketchContainer[], current: SketchContainer[], any: SketchContainer[] }> {
4444
const user: SketchContainer[] = [];
4545
const current: SketchContainer[] = [];
4646
const any: SketchContainer[] = [];
47-
if (fqbn) {
48-
const packages: LibraryPackage[] = await this.libraryService.list({ fqbn });
49-
for (const pkg of packages) {
50-
const container = await this.tryGroupExamples(pkg);
51-
const { location } = pkg;
52-
if (location === LibraryLocation.USER) {
53-
user.push(container);
54-
} else if (location === LibraryLocation.PLATFORM_BUILTIN || LibraryLocation.REFERENCED_PLATFORM_BUILTIN) {
55-
current.push(container);
56-
} else {
57-
any.push(container);
58-
}
47+
const packages: LibraryPackage[] = await this.libraryService.list({ fqbn });
48+
for (const pkg of packages) {
49+
const container = await this.tryGroupExamples(pkg);
50+
const { location } = pkg;
51+
if (location === LibraryLocation.USER) {
52+
user.push(container);
53+
} else if (location === LibraryLocation.PLATFORM_BUILTIN || LibraryLocation.REFERENCED_PLATFORM_BUILTIN) {
54+
current.push(container);
55+
} else {
56+
any.push(container);
5957
}
6058
}
6159
return { user, current, any };

Diff for: arduino-ide-extension/src/node/library-service-server-impl.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
8383
const { client, instance } = coreClient;
8484
const req = new LibraryListReq();
8585
req.setInstance(instance);
86-
req.setAll(true);
8786
if (fqbn) {
87+
// Only get libraries from the cores when the FQBN is defined. Otherwise, we retrieve user installed libraries only.
88+
req.setAll(true); // https://github.com/arduino/arduino-ide/pull/303#issuecomment-815556447
8889
req.setFqbn(fqbn);
8990
}
9091

0 commit comments

Comments
 (0)