Skip to content

Fix boards listing #1520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
const { label } = commands.get(commandId)!;
this.menuRegistry.registerMenuAction(menuPath, {
commandId,
order: `${i}`,
order: String(i).padStart(4),
label,
});
return Disposable.create(() =>
Expand Down
33 changes: 20 additions & 13 deletions arduino-ide-extension/src/browser/contributions/board-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,15 @@ PID: ${PID}`;
});

// Installed boards
for (const board of installedBoards) {
installedBoards.forEach((board, index) => {
const { packageId, packageName, fqbn, name, manuallyInstalled } = board;

const packageLabel =
packageName +
`${manuallyInstalled
? nls.localize('arduino/board/inSketchbook', ' (in Sketchbook)')
: ''
`${
manuallyInstalled
? nls.localize('arduino/board/inSketchbook', ' (in Sketchbook)')
: ''
}`;
// Platform submenu
const platformMenuPath = [...boardsPackagesGroup, packageId];
Expand Down Expand Up @@ -239,14 +240,18 @@ PID: ${PID}`;
};

// Board menu
const menuAction = { commandId: id, label: name };
const menuAction = {
commandId: id,
label: name,
order: String(index).padStart(4), // pads with leading zeros for alphanumeric sort where order is 1, 2, 11, and NOT 1, 11, 2
};
this.commandRegistry.registerCommand(command, handler);
this.toDisposeBeforeMenuRebuild.push(
Disposable.create(() => this.commandRegistry.unregisterCommand(command))
);
this.menuModelRegistry.registerMenuAction(platformMenuPath, menuAction);
// Note: we do not dispose the menu actions individually. Calling `unregisterSubmenu` on the parent will wipe the children menu nodes recursively.
}
});

// Installed ports
const registerPorts = (
Expand Down Expand Up @@ -282,11 +287,13 @@ PID: ${PID}`;

// First we show addresses with recognized boards connected,
// then all the rest.
const sortedIDs = Object.keys(ports).sort((left: string, right: string): number => {
const [, leftBoards] = ports[left];
const [, rightBoards] = ports[right];
return rightBoards.length - leftBoards.length;
});
const sortedIDs = Object.keys(ports).sort(
(left: string, right: string): number => {
const [, leftBoards] = ports[left];
const [, rightBoards] = ports[right];
return rightBoards.length - leftBoards.length;
}
);

for (let i = 0; i < sortedIDs.length; i++) {
const portID = sortedIDs[i];
Expand Down Expand Up @@ -322,7 +329,7 @@ PID: ${PID}`;
const menuAction = {
commandId: id,
label,
order: `${protocolOrder + i + 1}`,
order: String(protocolOrder + i + 1).padStart(4),
};
this.commandRegistry.registerCommand(command, handler);
this.toDisposeBeforeMenuRebuild.push(
Expand Down Expand Up @@ -354,7 +361,7 @@ PID: ${PID}`;
}

protected async installedBoards(): Promise<InstalledBoardWithPackage[]> {
const allBoards = await this.boardsService.searchBoards({});
const allBoards = await this.boardsService.getInstalledBoards();
return allBoards.filter(InstalledBoardWithPackage.is);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class SketchControl extends SketchContribution {
{
commandId: command.id,
label: this.labelProvider.getName(uri),
order: `${i}`,
order: String(i).padStart(4),
}
);
this.toDisposeBeforeCreateNewContextMenu.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export interface BoardsService
fqbn: string;
}): Promise<BoardsPackage | undefined>;
searchBoards({ query }: { query?: string }): Promise<BoardWithPackage[]>;
getInstalledBoards(): Promise<BoardWithPackage[]>;
getBoardUserFields(options: {
fqbn: string;
protocol: string;
Expand Down
24 changes: 23 additions & 1 deletion arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { CoreClientAware } from './core-client-provider';
import {
BoardDetailsRequest,
BoardDetailsResponse,
BoardListAllRequest,
BoardListAllResponse,
BoardSearchRequest,
} from './cli-protocol/cc/arduino/cli/commands/v1/board_pb';
import {
Expand Down Expand Up @@ -199,8 +201,28 @@ export class BoardsServiceImpl
const req = new BoardSearchRequest();
req.setSearchArgs(query || '');
req.setInstance(instance);
return this.handleListBoards(client.boardSearch.bind(client), req);
}

async getInstalledBoards(): Promise<BoardWithPackage[]> {
const { instance, client } = await this.coreClient;
const req = new BoardListAllRequest();
req.setInstance(instance);
return this.handleListBoards(client.boardListAll.bind(client), req);
}

private async handleListBoards(
getBoards: (
request: BoardListAllRequest | BoardSearchRequest,
callback: (
error: ServiceError | null,
response: BoardListAllResponse
) => void
) => void,
request: BoardListAllRequest | BoardSearchRequest
): Promise<BoardWithPackage[]> {
const boards = await new Promise<BoardWithPackage[]>((resolve, reject) => {
client.boardSearch(req, (error, resp) => {
getBoards(request, (error, resp) => {
if (error) {
reject(error);
return;
Expand Down