|
| 1 | +# vscode-arduino-api |
| 2 | + |
| 3 | +Arduino API for [Arduino IDE](https://github.com/arduino/arduino-ide) external tools developers using VS Code extensions. |
| 4 | + |
| 5 | +This VS Code extensions does not provide any functionality, but a bridge between the Arduino IDE and external tools implemented as a VS Code extension. Please reference [arduino/arduino-ide#58](https://github.com/arduino/arduino-ide/issues/58) why this VSIX has been created. This extension has nothing to do with the [Visual Studio Code extension for Arduino](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino). This extension does not work in VS Code. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +Exposes the Arduino context for VS Code extensions: |
| 10 | + |
| 11 | +| Name | Description | Type | Note | |
| 12 | +| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ----------- | |
| 13 | +| `sketchPath` | Absolute filesystem path of the sketch folder. | `string` | |
| 14 | +| `buildPath` | The absolute filesystem path to the build folder of the sketch. When the `sketchPath` is available but the sketch has not been verified (compiled), the `buildPath` can be `undefined`. | `string` | ⚠️ `@alpha` | |
| 15 | +| `fqbn` | The Fully Qualified Board Name (FQBN) of the currently selected board in the Arduino IDE. | `string` | |
| 16 | +| `boardDetails` | Lightweight representation of the board's detail. This information is [provided by the Arduino CLI](https://arduino.github.io/arduino-cli/latest/rpc/commands/#cc.arduino.cli.commands.v1.BoardDetailsResponse) for the currently selected board. It can be `undefined` if the `fqbn` is defined but the platform is not installed. | `BoardDetails` | ⚠️ `@alpha` | |
| 17 | +| `port` | The currently selected port in the Arduino IDE. | [`Port`](https://arduino.github.io/arduino-cli/latest/rpc/commands/#port) | |
| 18 | +| `userDirPath` | Filesystem path to the [`directories.user`](https://arduino.github.io/arduino-cli/latest/configuration/#configuration-keys) location. This is the sketchbook path. | `string` | |
| 19 | +| `dataDirPath` | Filesystem path to the [`directories.data`](https://arduino.github.io/arduino-cli/latest/configuration/#configuration-keys) location | `string` | |
| 20 | + |
| 21 | +## How to Use |
| 22 | + |
| 23 | +If you're developing an external tool for the Arduino IDE, this extension will be available at runtime from the IDE. |
| 24 | + |
| 25 | +If you want to use the Arduino APIs, you have to do the followings: |
| 26 | + |
| 27 | +1. Install the [Arduino API types](https://www.npmjs.com/package/vscode-arduino-api) from `npm`: |
| 28 | + ```shell |
| 29 | + npm i -S vscode-arduino-api |
| 30 | + ``` |
| 31 | +1. Add this VSIX as an `extensionDependencies` in your `package.json`: |
| 32 | + |
| 33 | + ```jsonc |
| 34 | + { |
| 35 | + "extensionDependencies": [ |
| 36 | + "dankeboy36.vscode-arduino-api", |
| 37 | + // other dependencies |
| 38 | + ], |
| 39 | + } |
| 40 | + ``` |
| 41 | +1. Consume the `ArduinoContext` extension API in your VS Code extension: |
| 42 | + |
| 43 | + ```ts |
| 44 | + import * as vscode from 'vscode'; |
| 45 | + import type { ArduinoContext } from 'vscode-arduino-api'; |
| 46 | +
|
| 47 | + function activate(context: vscode.ExtensionContext) { |
| 48 | + const arduinoContext: ArduinoContext = vscode.extensions.getExtension( |
| 49 | + 'dankeboy36.vscode-arduino-api' |
| 50 | + )?.exports; |
| 51 | + if (!arduinoContext) { |
| 52 | + // failed to load the Arduino API |
| 53 | + return; |
| 54 | + } |
| 55 | + // use the Arduino API in your VS Code extension... |
| 56 | + } |
| 57 | + ``` |
| 58 | +
|
| 59 | +## FAQs |
| 60 | +
|
| 61 | +--- |
| 62 | +
|
| 63 | +- Q: Why do I have to install `vscode-arduino-api` from `npm`. |
| 64 | +- A: `vscode-arduino-api` only contains types for the API. The actual code wil be part of the VS Code extension. |
| 65 | +
|
| 66 | +--- |
| 67 | +
|
| 68 | +- Q: I cannot find the `dankeboy36.vscode-arduino-api` extension in the [VS Code Marketplace](https://marketplace.visualstudio.com/vscode). |
| 69 | +- A: Correct. This solution targets the [Arduino IDE](https://github.com/arduino/arduino-ide). I will publish the VSIX later, when it works in VS Code. By the way, the VSIX is signed with a verified published. |
0 commit comments