Theory of operation - PeterWone/vscode-arduino-cli GitHub Wiki

An extension maintains state and spawns arduino-cli to perform operations and request system information.

This depends on arduino-cli being installed and the path to it being known to the extension.

What the extension can do maps directly to what arduino-cli can do, and information on this is here https://arduino.github.io/arduino-cli/latest/getting-started/#before-you-start

To avoid the binary coupling problems that plague the other Arduino extension we are spawning arduino-cli and processing stdio and stderr.

Let's take a look at how we handle a command like

arduino-cli core install arduino:avr

This command downloads and installs the toolchain and headers required for the Nano and similar boards. Here's the code that spawns the command and captures its outputs.

export function installCore(coreName: string, install = true) {
  let args = ["core", install ? "install" : "uninstall", coreName];
  let cp = child_process.spawn(cliPath, args, { cwd: getInoPath() });
  cp.stdout.on("data", (data: any) => outputChannel.append(`${data}`));
  cp.stderr.on("data", (data: any) => outputChannel.append(`${data}`));
  cp.on("error", (err: any) => {
    outputChannel.append(err);
  }).on("exit", () => {
    vscode.window.showInformationMessage(`"${coreName}" resources and toolchain are installed and ready.`);
  });

An output channel looks like this in the VS Code UI.

image

A weakness of this implementation is it doesn't give strong feedback. This operation can take a while and new users won't realise they need to wait for the "ready" message before they can expect to find their board in the quickpick list.