Skip to content

Commit 4d87fab

Browse files
authored
feat: multi sketch folders support (#12)
Signed-off-by: dankeboy36 <[email protected]>
1 parent cb414b0 commit 4d87fab

16 files changed

+6458
-759
lines changed

.github/workflows/build.yml

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
run: npm ci
3131
- name: Check Format
3232
run: npm run format && git diff --exit-code
33+
- name: Lint
34+
run: npm run lint
3335
- name: Test
3436
uses: coactions/setup-xvfb@v1
3537
with:
@@ -54,6 +56,8 @@ jobs:
5456
run: npm ci
5557
- name: Build
5658
run: npm run build
59+
- name: Generate Typings
60+
run: npm run typings
5761
- name: Release
5862
id: release
5963
run: npm run release

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules
55
*.vsix
66
src/test/test-workspace/*
77
!src/test/test-workspace/.gitkeep
8+
.nyc_output

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
out
22
dist
33
.vscode-test
4+
.nyc_output
5+
CHANGELOG.md
6+
src/test/test-workspace

.prettierrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"tabWidth": 2
1212
}
1313
}
14-
]
14+
],
15+
"plugins": ["prettier-plugin-packagejson"]
1516
}

.vscode/launch.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
2020
],
2121
"env": {
22-
"NO_TEST_TIMEOUT": "true"
22+
"NO_TEST_TIMEOUT": "true",
23+
"NO_TEST_COVERAGE": "true"
2324
},
2425
"outFiles": [
2526
"${workspaceFolder}/out/**/*.js",

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"typescript.tsc.autoDetect": "off",
1111
"typescript.tsdk": "./node_modules/typescript/lib",
1212
"editor.codeActionsOnSave": {
13-
"source.fixAll.eslint": true
13+
"source.fixAll.eslint": "explicit"
1414
}
1515
}

.vscodeignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ vsc-extension-quickstart.md
1313
**/.eslintrc.json
1414
**/*.map
1515
**/*.ts
16+
release.config.js
17+
.nyc_output/**

README.md

+35-19
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,31 @@ This VS Code extension does not provide any functionality but a bridge between t
1010
1111
## API
1212

13-
Exposes the Arduino state for VS Code extensions:
14-
15-
| Name | Description | Type | Note |
16-
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- | :---------: |
17-
| `sketchPath` | Absolute filesystem path of the sketch folder. | `string` |
18-
| `compileSummary` | The summary of the latest sketch compilation. When the `sketchPath` is available, but the sketch has not been verified (compiled), the `buildPath` can be `undefined`. | `CompileSummary` | ⚠️ `@alpha` |
19-
| `fqbn` | The Fully Qualified Board Name (FQBN) of the currently selected board in the Arduino IDE. | `string` |
20-
| `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` |
21-
| `port` | The currently selected port in the Arduino IDE. | [`Port`](https://arduino.github.io/arduino-cli/latest/rpc/commands/#port) |
22-
| `userDirPath` | Filesystem path to the [`directories.user`](https://arduino.github.io/arduino-cli/latest/configuration/#configuration-keys) location. This is the sketchbook path. | `string` | ⚠️ `@alpha` |
23-
| `dataDirPath` | Filesystem path to the [`directories.data`](https://arduino.github.io/arduino-cli/latest/configuration/#configuration-keys) location | `string` | ⚠️ `@alpha` |
13+
### Variables
14+
15+
| Name | Description | Type | Note |
16+
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | :---------: |
17+
| `openedSketches` | All opened sketch folders in the window. | `SketchFolder[]` | ⚠️ `@alpha` |
18+
| `currentSketch` | The currently active sketch (folder) or `undefined`. The current sketch is the one that currently has focus or most recently had focus. The current sketch is in the opened sketches. | `SketchFolder \| undefined` | ⚠️ `@alpha` |
19+
| `config` | The currently configured Arduino CLI configuration. | `CliConfig` | ⚠️ `@alpha` |
20+
21+
### Events
22+
23+
| Name | Description | Type | Note |
24+
| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | :---------: |
25+
| `onDidChangeCurrentSketch` | An event that is emitted when the current sketch has changed. _Note_ that the event also fires when the active editor changes to `undefined`. | `Event<{ currentSketch: SketchFolder \| undefined }>` | ⚠️ `@alpha` |
26+
| `onDidChangeSketchFolders` | An event that is emitted when sketch folders are added or removed. | `Event<SketchFoldersChangeEvent>` | ⚠️ `@alpha` |
27+
| `onDidChangeSketch` | An event that is emitted when the selected board, port, etc., has changed in the sketch folder. | `Event<ChangeEvent<SketchFolder>>` | ⚠️ `@alpha` |
28+
| `onDidChangeConfig` | An event that is emitter when the sketchbook (`directories.data`) or the data directory (`directories.data`) path has changed. | `Event<ChangeEvent<CliConfig>>` | ⚠️ `@alpha` |
29+
30+
### `SketchFolder`
31+
32+
| Name | Description | Type | Note |
33+
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | :---------: |
34+
| `sketchPath` | Absolute filesystem path of the sketch folder. | `string` | ⚠️ `@alpha` |
35+
| `compileSummary` | The summary of the latest sketch compilation. When the `sketchPath` is available but the sketch has not been verified (compiled), the compile summary can be `undefined`. | `CompileSummary` | ⚠️ `@alpha` |
36+
| `board` | The currently selected board associated with the sketch. If the `board` is undefined, no board is selected. If the `board` is a `BoardIdentifier`, it could be a recognized board on a detected port, but the board's platform could be absent. If platform is installed, the `board` is the 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 in the sketch folder. | `string` | ⚠️ `@alpha` |
37+
| `port` | The currently selected port in the sketch folder. | [`Port`](https://arduino.github.io/arduino-cli/latest/rpc/commands/#port) | ⚠️ `@alpha` |
2438

2539
## How to Use
2640

@@ -41,10 +55,10 @@ If you want to use the Arduino APIs, you have to do the followings:
4155
import type { ArduinoContext } from 'vscode-arduino-api';
4256
4357
export function activate(context: vscode.ExtensionContext) {
44-
const arduinoContext: ArduinoContext = vscode.extensions.getExtension(
58+
const context: ArduinoContext = vscode.extensions.getExtension(
4559
'dankeboy36.vscode-arduino-api'
4660
)?.exports;
47-
if (!arduinoContext) {
61+
if (!context) {
4862
// Failed to load the Arduino API.
4963
return;
5064
}
@@ -63,11 +77,13 @@ If you want to use the Arduino APIs, you have to do the followings:
6377
6478
// Listen on state change.
6579
// Register a listener to show the FQBN of the currently selected board as an information message.
66-
context.subscriptions.push(
67-
arduinoContext.onDidChange('fqbn')((fqbn) =>
68-
vscode.window.showInformationMessage(`FQBN: ${fqbn}`)
69-
)
70-
);
80+
context.onDidChangeSketch((event) => {
81+
if (event.changedProperties.includes('board')) {
82+
vscode.window.showInformationMessage(
83+
`FQBN: ${event.object.board?.fqbn}`
84+
);
85+
}
86+
});
7187
}
7288
```
7389
@@ -93,4 +109,4 @@ This extension contributes the following settings:
93109
---
94110
95111
- Q: Are there any dependent examples?
96-
- A: Yes, for example, [dankeboy36/esp-exception-decoder](https://github.com/dankeboy36/esp-exception-decoder).
112+
- A: Yes, for example, [dankeboy36/esp-exception-decoder](https://github.com/dankeboy36/esp-exception-decoder) or [earlephilhower/arduino-littlefs-upload](https://github.com/earlephilhower/arduino-littlefs-upload).

0 commit comments

Comments
 (0)