Skip to content

Commit 50ab124

Browse files
committed
feat: Initial Arduino API for VS Code extensions
Signed-off-by: dankeboy36 <[email protected]>
1 parent c310d66 commit 50ab124

22 files changed

+9319
-0
lines changed

.eslintrc.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"extends": [
9+
"plugin:@typescript-eslint/recommended",
10+
"plugin:prettier/recommended",
11+
"prettier"
12+
],
13+
"plugins": ["@typescript-eslint", "prettier"],
14+
"rules": {
15+
"@typescript-eslint/naming-convention": "off",
16+
"@typescript-eslint/semi": "warn",
17+
"curly": "warn",
18+
"eqeqeq": "warn",
19+
"no-throw-literal": "warn",
20+
"semi": "off",
21+
"prettier/prettier": "warn"
22+
},
23+
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
24+
}

.github/workflows/ci.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Tests
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
name: test (${{ matrix.os }}, node-${{ matrix.node }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [windows-latest, ubuntu-latest, macos-latest]
18+
node: [16.x, 18.x]
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-node@v3
23+
with:
24+
node-version: ${{ matrix.config.node }}
25+
- uses: coactions/setup-xvfb@v1
26+
with:
27+
run: npm ci && npm test

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
out
2+
dist
3+
node_modules
4+
.vscode-test/
5+
*.vsix

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
out
2+
dist
3+
.vscode-test

.prettierrc.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"printWidth": 80,
6+
"endOfLine": "auto",
7+
"overrides": [
8+
{
9+
"files": "*.json",
10+
"options": {
11+
"tabWidth": 2
12+
}
13+
}
14+
]
15+
}

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"dbaeumer.vscode-eslint",
4+
"amodio.tsl-problem-matcher",
5+
"streetsidesoftware.code-spell-checker"
6+
]
7+
}

.vscode/launch.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run Extension",
6+
"type": "extensionHost",
7+
"request": "launch",
8+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
9+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
10+
"preLaunchTask": "${defaultBuildTask}"
11+
},
12+
{
13+
"name": "Extension Tests",
14+
"type": "extensionHost",
15+
"request": "launch",
16+
"args": [
17+
"--extensionDevelopmentPath=${workspaceFolder}",
18+
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
19+
],
20+
"outFiles": [
21+
"${workspaceFolder}/out/**/*.js",
22+
"${workspaceFolder}/dist/**/*.js"
23+
],
24+
"preLaunchTask": "tasks: watch-tests"
25+
}
26+
]
27+
}

.vscode/settings.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"files.exclude": {
3+
"out": false,
4+
"dist": false
5+
},
6+
"search.exclude": {
7+
"out": true,
8+
"dist": true
9+
},
10+
"typescript.tsc.autoDetect": "off",
11+
"typescript.tsdk": "./node_modules/typescript/lib",
12+
"editor.codeActionsOnSave": {
13+
"source.fixAll.eslint": true
14+
}
15+
}

.vscode/tasks.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "watch",
7+
"problemMatcher": "$ts-webpack-watch",
8+
"isBackground": true,
9+
"presentation": {
10+
"reveal": "never",
11+
"group": "watchers"
12+
},
13+
"group": {
14+
"kind": "build",
15+
"isDefault": true
16+
}
17+
},
18+
{
19+
"type": "npm",
20+
"script": "watch-tests",
21+
"problemMatcher": "$tsc-watch",
22+
"isBackground": true,
23+
"presentation": {
24+
"reveal": "never",
25+
"group": "watchers"
26+
},
27+
"group": "build"
28+
},
29+
{
30+
"label": "tasks: watch-tests",
31+
"dependsOn": ["npm: watch", "npm: watch-tests"],
32+
"problemMatcher": []
33+
}
34+
]
35+
}

.vscodeignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/**
4+
node_modules/**
5+
src/**
6+
.gitignore
7+
.yarnrc
8+
webpack.config.js
9+
vsc-extension-quickstart.md
10+
**/tsconfig.json
11+
**/.eslintrc.json
12+
**/*.map
13+
**/*.ts

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
All notable changes to the "vscode-arduino-api" extension will be documented in this file.
4+
5+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6+
7+
## [Unreleased]
8+
9+
- Initial release

README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)