Skip to content

Commit d937fb6

Browse files
authored
Merge pull request #85 from raspberrypi/micropico-interop
Micropico interop
2 parents 03b22e9 + 36d972e commit d937fb6

File tree

13 files changed

+996
-58
lines changed

13 files changed

+996
-58
lines changed

.vscode/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"files.exclude": {
33
// set them to true to hide them in vscode
44
"out": false,
5-
"dist": false,
6-
"**/*.vsix": true
5+
"dist": true,
6+
"**/*.vsix": true,
7+
".yarn": true,
8+
".pnp.*": true
79
},
810
"search.exclude": {
911
"out": true,

README.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Raspberry Pi Pico Visual Studio Code extension
22

3-
> NOTE: The extension is currently under development.
3+
> **Note: The extension is currently under development.**
44
55
This is the official Visual Studio Code extension for Raspberry Pi Pico development. This extension equips you with a suite of tools designed to streamline your Pico projects using Visual Studio Code and the official [Pico SDK](https://github.com/raspberrypi/pico-sdk).
66

@@ -10,18 +10,34 @@ For comprehensive setup instructions, refer to the [Getting Started guide](https
1010

1111
## Features
1212

13-
- Project Generator: Easily create new projects targeting the Ninja build system.
14-
- Automatic CMake Configuration: Automatically configures CMake when loading a project.
15-
- Version Switching: Seamlessly switch between different versions of the Pico SDK and tools.
16-
- No Manual Setup Required: The extension handles environment variables, toolchain, SDK, and tool management for you.
17-
- One-Click Compilation: Compile projects directly from the status bar with your selected SDK and tools.
18-
- Offline Documentation: Access Pico SDK documentation offline.
19-
- Quick Project Setup: Quickly create new Pico projects from the Explorer view when no workspace is open.
20-
- Includes an Uninstaller: Easily remove the extension along with all automatically installed tools and SDKs.
13+
### Project Setup and Management
14+
15+
- **Project Generator**: Easily create and configure new projects with support for advanced Pico features like I2C and PIO. The generator targets the Ninja build system and allows customization during project creation.
16+
- **Quick Project Setup**: Initiate new Pico projects directly from the Explorer view, when no workspace is open.
17+
- **MicroPython Support**: Create and develop MicroPython-based Pico projects with support provided through the [MicroPico](https://github.com/paulober/MicroPico) extension.
18+
19+
### Configuration and Tool Management
20+
21+
- **Automatic CMake Configuration**: Automatically configures CMake when loading a project.
22+
- **Version Switching**: Seamlessly switch between different versions of the Pico SDK and tools.
23+
- **No Manual Setup Required**: Automatically handles environment variables, toolchain, SDK, and tool management.
24+
- **Includes an Uninstaller**: Easily remove the extension along with all automatically installed tools and SDKs.
25+
26+
### Build, Debug, and Documentation
27+
28+
- **One-Click Compilation and Debugging**: Automatically configure OpenOCD, Ninja, and CMake, allowing you to compile and debug with a single click.
29+
- **Offline Documentation**: Conveniently access Pico SDK documentation directly within the editor, even when offline.
30+
31+
- **Version Switching**: Seamlessly switch between different versions of the Pico SDK and tools.
32+
- **No Manual Setup Required**: The extension handles environment variables, toolchain, SDK, and tool management for you.
33+
- **One-Click Compilation**: Compile projects directly from the status bar with your selected SDK and tools.
34+
- **Offline Documentation**: Access Pico SDK documentation offline.
35+
- **Quick Project Setup**: Quickly create new Pico projects from the Explorer view when no workspace is open.
36+
- **MicroPython Support**: Create MicroPython-based Pico projects with support provided through the MicroPico extension.
2137

2238
## Requirements by OS
2339

24-
> Supported Platforms: Raspberry Pi OS (64-bit), Windows 10/11 (x86_64), macOS Sonoma (14.0) and newer, Linux x64 and arm64
40+
> **Supported Platforms: Raspberry Pi OS (64-bit), Windows 10/11 (x86_64), macOS Sonoma (14.0) and newer, Linux x64 and arm64**
2541
2642
- Visual Studio Code v1.87.0 or later
2743

@@ -38,19 +54,19 @@ To meet the requirements for macOS, run the following command in Terminal to ins
3854
xcode-select --install
3955
```
4056
This command installs all of the necessary tools, including but not limited to:
41-
- Git 2.28 or later (ensure it's in your PATH)
42-
- Tar (ensure it's in your PATH)
57+
- **Git 2.28 or later** (ensure it's in your PATH)
58+
- **Tar** (ensure it's in your PATH)
4359

4460
### Windows
4561

4662
No additional requirements are needed for Windows.
4763

4864
### Linux
49-
- Python 3.9 or later (ensure it’s in your PATH or set in settings)
50-
- Git 2.28 or later (ensure it’s in your PATH)
51-
- Tar (ensure it’s in your PATH)
52-
- \[Optional\] gdb-multiarch for debugging (x86_64 only)
53-
- For \[Ubuntu 22.04\], install `libftdi1-2` and `libhidapi-hidraw0` packages to use OpenOCD
65+
- **Python 3.9 or later** (ensure it’s in your PATH or set in settings)
66+
- **Git 2.28 or later** (ensure it’s in your PATH)
67+
- **Tar** (ensure it’s in your PATH)
68+
- **\[Optional\]** gdb-multiarch for debugging (x86_64 only)
69+
- For **\[Ubuntu 22.04\]**, install `libftdi1-2` and `libhidapi-hidraw0` packages to use OpenOCD
5470

5571
## Extension Settings
5672

eslint.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import tseslint from "typescript-eslint";
55
import js from "@eslint/js";
66
import eslintConfigPrettier from "eslint-config-prettier";
77

8-
export default [
8+
export default tseslint.config(
99
js.configs.recommended,
1010
...tseslint.configs.recommendedTypeChecked,
1111
eslintConfigPrettier,
@@ -19,7 +19,7 @@ export default [
1919
...globals.commonjs
2020
},
2121
parserOptions: {
22-
project: true,
22+
projectService: true,
2323
tsconfigRootDir: import.meta.dirname
2424
}
2525
},
@@ -55,4 +55,4 @@ export default [
5555
"web/**/*.js",
5656
]
5757
}
58-
];
58+
);

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"url": "https://github.com/raspberrypi/pico-vscode/"
1717
},
1818
"engines": {
19-
"vscode": "^1.87.0",
20-
"node": ">=18.17.1"
19+
"vscode": "^1.92.1",
20+
"node": ">=20.14.0"
2121
},
2222
"os": [
2323
"win32",
@@ -46,11 +46,13 @@
4646
"ms-vscode.cpptools",
4747
"ms-vscode.cpptools-extension-pack",
4848
"ms-vscode.vscode-serial-monitor",
49-
"marus25.cortex-debug"
49+
"marus25.cortex-debug",
50+
"paulober.pico-w-go",
51+
"ms-python.python"
5052
],
5153
"main": "./dist/extension.cjs",
5254
"markdown": "github",
53-
"minimumNodeVersion": 18,
55+
"minimumNodeVersion": 20,
5456
"capabilities": {
5557
"virtualWorkspaces": {
5658
"supported": false,
@@ -63,7 +65,8 @@
6365
},
6466
"activationEvents": [
6567
"workspaceContains:./pico_sdk_import.cmake",
66-
"onWebviewPanel:newPicoProject"
68+
"onWebviewPanel:newPicoProject",
69+
"onWebviewPanel:newPicoMicroPythonProject"
6770
],
6871
"contributes": {
6972
"commands": [
@@ -279,9 +282,9 @@
279282
"@rollup/plugin-typescript": "^11.1.6",
280283
"@types/adm-zip": "^0.5.5",
281284
"@types/ini": "^4.1.1",
282-
"@types/node": "18.17.x",
285+
"@types/node": "20.14.0",
283286
"@types/uuid": "^10.0.0",
284-
"@types/vscode": "^1.87.0",
287+
"@types/vscode": "^1.92.0",
285288
"@types/which": "^3.0.4",
286289
"eslint": "^9.9.0",
287290
"eslint-config-prettier": "^9.1.0",
@@ -292,6 +295,7 @@
292295
"typescript-eslint": "^8.1.0"
293296
},
294297
"dependencies": {
298+
"@vscode/python-extension": "^1.0.5",
295299
"adm-zip": "^0.5.14 <0.5.15",
296300
"got": "^14.4.2",
297301
"ini": "^4.1.3",

src/commands/newProject.mts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
import { Command } from "./command.mjs";
1+
import { CommandWithArgs } from "./command.mjs";
22
import Logger from "../logger.mjs";
3-
import { type Uri } from "vscode";
3+
import { window, type Uri } from "vscode";
44
import { NewProjectPanel } from "../webview/newProjectPanel.mjs";
5+
// eslint-disable-next-line max-len
6+
import { NewMicroPythonProjectPanel } from "../webview/newMicroPythonProjectPanel.mjs";
57

6-
export default class NewProjectCommand extends Command {
8+
/**
9+
* Enum for the language of the project.
10+
* Can be used to specify the language of the project
11+
* in the `NewProjectCommand` class.
12+
*/
13+
export enum ProjectLang {
14+
cCpp = 1,
15+
micropython = 2,
16+
}
17+
18+
export default class NewProjectCommand extends CommandWithArgs {
719
private readonly _logger: Logger = new Logger("NewProjectCommand");
820
private readonly _extensionUri: Uri;
21+
private static readonly micropythonOption = "MicroPython";
22+
private static readonly cCppOption = "C/C++";
923

1024
public static readonly id = "newProject";
1125

@@ -15,8 +29,38 @@ export default class NewProjectCommand extends Command {
1529
this._extensionUri = extensionUri;
1630
}
1731

18-
execute(): void {
19-
// show webview where the process of creating a new project is continued
20-
NewProjectPanel.createOrShow(this._extensionUri);
32+
private preSelectedTypeToStr(preSelectedType?: number): string | undefined {
33+
return preSelectedType === ProjectLang.cCpp
34+
? NewProjectCommand.cCppOption
35+
: preSelectedType === ProjectLang.micropython
36+
? NewProjectCommand.micropythonOption
37+
: undefined;
38+
}
39+
40+
async execute(preSelectedType?: number): Promise<void> {
41+
// ask the user what language to use
42+
const lang =
43+
this.preSelectedTypeToStr(preSelectedType) ??
44+
(await window.showQuickPick(
45+
[NewProjectCommand.cCppOption, NewProjectCommand.micropythonOption],
46+
{
47+
placeHolder: "Select which language to use for your new project",
48+
canPickMany: false,
49+
ignoreFocusOut: false,
50+
title: "New Pico Project",
51+
}
52+
));
53+
54+
if (lang === undefined) {
55+
return;
56+
}
57+
58+
if (lang === NewProjectCommand.micropythonOption) {
59+
// create a new project with MicroPython
60+
NewMicroPythonProjectPanel.createOrShow(this._extensionUri);
61+
} else {
62+
// show webview where the process of creating a new project is continued
63+
NewProjectPanel.createOrShow(this._extensionUri);
64+
}
2165
}
2266
}

src/extension.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ import NewExampleProjectCommand from "./commands/newExampleProject.mjs";
7474
import SwitchBoardCommand from "./commands/switchBoard.mjs";
7575
import UninstallPicoSDKCommand from "./commands/uninstallPicoSDK.mjs";
7676
import FlashProjectSWDCommand from "./commands/flashProjectSwd.mjs";
77+
// eslint-disable-next-line max-len
78+
import { NewMicroPythonProjectPanel } from "./webview/newMicroPythonProjectPanel.mjs";
7779

7880
export async function activate(context: ExtensionContext): Promise<void> {
7981
Logger.info(LoggerSource.extension, "Extension activation triggered");
@@ -144,6 +146,17 @@ export async function activate(context: ExtensionContext): Promise<void> {
144146
})
145147
);
146148

149+
context.subscriptions.push(
150+
window.registerWebviewPanelSerializer(NewMicroPythonProjectPanel.viewType, {
151+
// eslint-disable-next-line @typescript-eslint/require-await
152+
async deserializeWebviewPanel(webviewPanel: WebviewPanel): Promise<void> {
153+
// Reset the webview options so we use latest uri for `localResourceRoots`.
154+
webviewPanel.webview.options = getWebviewOptions(context.extensionUri);
155+
NewMicroPythonProjectPanel.revive(webviewPanel, context.extensionUri);
156+
},
157+
})
158+
);
159+
147160
context.subscriptions.push(
148161
window.registerTreeDataProvider(
149162
PicoProjectActivityBar.viewType,

src/utils/githubREST.mts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ export const PYENV_REPOSITORY_URL = "https://github.com/pyenv/pyenv.git";
6161
export function ownerOfRepository(repository: GithubRepository): string {
6262
switch (repository) {
6363
case GithubRepository.picoSDK:
64+
case GithubRepository.tools:
65+
case GithubRepository.picotool:
6466
return "raspberrypi";
6567
case GithubRepository.cmake:
6668
return "Kitware";
6769
case GithubRepository.ninja:
6870
return "ninja-build";
69-
case GithubRepository.tools:
70-
return "raspberrypi";
71-
case GithubRepository.picotool:
72-
return "raspberrypi";
7371
}
7472
}
7573

src/webview/activityBar.mts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "vscode";
1010
import Logger from "../logger.mjs";
1111
import { extensionName } from "../commands/command.mjs";
12-
import NewProjectCommand from "../commands/newProject.mjs";
12+
import NewProjectCommand, { ProjectLang } from "../commands/newProject.mjs";
1313
import CompileProjectCommand from "../commands/compileProject.mjs";
1414
import RunProjectCommand from "../commands/runProject.mjs";
1515
import SwitchSDKCommand from "../commands/switchSDK.mjs";
@@ -39,7 +39,8 @@ const COMMON_COMMANDS_PARENT_LABEL = "General";
3939
const PROJECT_COMMANDS_PARENT_LABEL = "Project";
4040
const DOCUMENTATION_COMMANDS_PARENT_LABEL = "Documentation";
4141

42-
const NEW_PROJECT_LABEL = "New Project";
42+
const NEW_C_CPP_PROJECT_LABEL = "New C/C++ Project";
43+
const NEW_MICROPYTHON_PROJECT_LABEL = "New MicroPython Project";
4344
const IMPORT_PROJECT_LABEL = "Import Project";
4445
const EXAMPLE_PROJECT_LABEL = "New Project From Example";
4546
const SWITCH_SDK_LABEL = "Switch SDK";
@@ -78,10 +79,13 @@ export class PicoProjectActivityBar
7879
element: QuickAccessCommand
7980
): TreeItem | Thenable<TreeItem> {
8081
switch (element.label) {
81-
case NEW_PROJECT_LABEL:
82+
case NEW_C_CPP_PROJECT_LABEL:
8283
// alt. "new-folder"
8384
element.iconPath = new ThemeIcon("file-directory-create");
8485
break;
86+
case NEW_MICROPYTHON_PROJECT_LABEL:
87+
element.iconPath = new ThemeIcon("file-directory-create");
88+
break;
8589
case IMPORT_PROJECT_LABEL:
8690
// alt. "repo-pull"
8791
element.iconPath = new ThemeIcon("repo-clone");
@@ -158,11 +162,21 @@ export class PicoProjectActivityBar
158162
} else if (element.label === COMMON_COMMANDS_PARENT_LABEL) {
159163
return [
160164
new QuickAccessCommand(
161-
NEW_PROJECT_LABEL,
165+
NEW_C_CPP_PROJECT_LABEL,
166+
TreeItemCollapsibleState.None,
167+
{
168+
command: `${extensionName}.${NewProjectCommand.id}`,
169+
title: NEW_C_CPP_PROJECT_LABEL,
170+
arguments: [ProjectLang.cCpp],
171+
}
172+
),
173+
new QuickAccessCommand(
174+
NEW_MICROPYTHON_PROJECT_LABEL,
162175
TreeItemCollapsibleState.None,
163176
{
164177
command: `${extensionName}.${NewProjectCommand.id}`,
165-
title: NEW_PROJECT_LABEL,
178+
title: NEW_MICROPYTHON_PROJECT_LABEL,
179+
arguments: [ProjectLang.micropython],
166180
}
167181
),
168182
new QuickAccessCommand(

0 commit comments

Comments
 (0)