Skip to content

Commit 6b3f029

Browse files
committed
WIP
Signed-off-by: paulober <[email protected]>
1 parent 39de7a4 commit 6b3f029

File tree

14 files changed

+1890
-221
lines changed

14 files changed

+1890
-221
lines changed

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
"category": "Raspberry Pi Pico",
9595
"enablement": "false"
9696
},
97+
{
98+
"command": "raspberry-pi-pico.launchTargetPathRelease",
99+
"title": "Get path of the project release executable (rust only)",
100+
"category": "Raspberry Pi Pico",
101+
"enablement": "false"
102+
},
97103
{
98104
"command": "raspberry-pi-pico.getPythonPath",
99105
"title": "Get python path",
@@ -142,6 +148,12 @@
142148
"category": "Raspberry Pi Pico",
143149
"enablement": "false"
144150
},
151+
{
152+
"command": "raspberry-pi-pico.getOpenOCDRoot",
153+
"title": "Get OpenOCD root",
154+
"category": "Raspberry Pi Pico",
155+
"enablement": "false"
156+
},
145157
{
146158
"command": "raspberry-pi-pico.compileProject",
147159
"title": "Compile Pico Project",
@@ -152,7 +164,7 @@
152164
"command": "raspberry-pi-pico.runProject",
153165
"title": "Run Pico Project (USB)",
154166
"category": "Raspberry Pi Pico",
155-
"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
167+
"enablement": "raspberry-pi-pico.isPicoProject"
156168
},
157169
{
158170
"command": "raspberry-pi-pico.clearGithubApiCache",
@@ -163,7 +175,7 @@
163175
"command": "raspberry-pi-pico.conditionalDebugging",
164176
"title": "Conditional Debugging",
165177
"category": "Raspberry Pi Pico",
166-
"enablement": "raspberry-pi-pico.isPicoProject && !inQuickOpen && !raspberry-pi-pico.isRustProject"
178+
"enablement": "raspberry-pi-pico.isPicoProject && !inQuickOpen"
167179
},
168180
{
169181
"command": "raspberry-pi-pico.debugLayout",

src/commands/conditionalDebugging.mts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Command } from "./command.mjs";
1+
import { Command, extensionName } from "./command.mjs";
22
import Logger from "../logger.mjs";
3-
import { commands } from "vscode";
3+
import { commands, window, workspace, debug } from "vscode";
4+
import State from "../state.mjs";
5+
import DebugLayoutCommand from "./debugLayout.mjs";
46

57
/**
68
* Relay command for the default buildin debug select and start command.
@@ -16,6 +18,23 @@ export default class ConditionalDebuggingCommand extends Command {
1618
}
1719

1820
async execute(): Promise<void> {
21+
const isRustProject = State.getInstance().isRustProject;
22+
23+
if (isRustProject) {
24+
const wsFolder = workspace.workspaceFolders?.[0];
25+
if (!wsFolder) {
26+
this._logger.error("No workspace folder found.");
27+
void window.showErrorMessage("No workspace folder found.");
28+
29+
return;
30+
}
31+
32+
void commands.executeCommand(`${extensionName}.${DebugLayoutCommand.id}`);
33+
void debug.startDebugging(wsFolder, "rp2040-project");
34+
35+
return;
36+
}
37+
1938
await commands.executeCommand("workbench.action.debug.selectandstart");
2039
}
2140
}

src/commands/getPaths.mts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import {
88
} from "../utils/cmakeUtil.mjs";
99
import { join } from "path";
1010
import {
11+
buildOpenOCDPath,
1112
buildPicotoolPath,
1213
buildToolchainPath,
14+
downloadAndInstallOpenOCD,
1315
downloadAndInstallPicotool,
1416
} from "../utils/download.mjs";
1517
import Settings, { SettingsKey } from "../settings.mjs";
1618
import which from "which";
1719
import { execSync } from "child_process";
1820
import { getPicotoolReleases } from "../utils/githubREST.mjs";
21+
import { openOCDVersion } from "../webview/newProjectPanel.mjs";
1922

2023
export class GetPythonPathCommand extends CommandWithResult<string> {
2124
constructor() {
@@ -143,7 +146,8 @@ export class GetCompilerPathCommand extends CommandWithResult<string> {
143146
}
144147

145148
return join(
146-
buildToolchainPath(toolchainVersion), "bin",
149+
buildToolchainPath(toolchainVersion),
150+
"bin",
147151
triple + `-gcc${process.platform === "win32" ? ".exe" : ""}`
148152
);
149153
}
@@ -263,8 +267,10 @@ export class GetPicotoolPathCommand extends CommandWithResult<
263267
> {
264268
private running: boolean = false;
265269

270+
public static readonly id = "getPicotoolPath";
271+
266272
constructor() {
267-
super("getPicotoolPath");
273+
super(GetPicotoolPathCommand.id);
268274
}
269275

270276
async execute(): Promise<string | undefined> {
@@ -305,3 +311,35 @@ export class GetPicotoolPathCommand extends CommandWithResult<
305311
);
306312
}
307313
}
314+
315+
export class GetOpenOCDRootCommand extends CommandWithResult<
316+
string | undefined
317+
> {
318+
private running: boolean = false;
319+
320+
public static readonly id = "getOpenOCDRoot";
321+
322+
constructor() {
323+
super(GetOpenOCDRootCommand.id);
324+
}
325+
326+
async execute(): Promise<string | undefined> {
327+
if (this.running) {
328+
return undefined;
329+
}
330+
this.running = true;
331+
332+
// check if it is installed if not install it
333+
const result = await downloadAndInstallOpenOCD(openOCDVersion);
334+
335+
if (result === null || !result) {
336+
this.running = false;
337+
338+
return undefined;
339+
}
340+
341+
this.running = false;
342+
343+
return buildOpenOCDPath(openOCDVersion);
344+
}
345+
}

src/commands/launchTargetPath.mts

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import { CommandWithResult } from "./command.mjs";
33
import { commands, window, workspace } from "vscode";
44
import { join } from "path";
55
import Settings, { SettingsKey } from "../settings.mjs";
6+
import State from "../state.mjs";
7+
import { parse as parseToml } from "toml";
8+
import { join as joinPosix } from "path/posix";
69

710
export default class LaunchTargetPathCommand extends CommandWithResult<string> {
11+
public static readonly id = "launchTargetPath";
12+
813
constructor() {
9-
super("launchTargetPath");
14+
super(LaunchTargetPathCommand.id);
1015
}
1116

1217
private async readProjectNameFromCMakeLists(
@@ -61,6 +66,33 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
6166
return "";
6267
}
6368

69+
const isRustProject = State.getInstance().isRustProject;
70+
71+
if (isRustProject) {
72+
const cargoTomlPath = join(
73+
workspace.workspaceFolders[0].uri.fsPath,
74+
"Cargo.toml"
75+
);
76+
const contents = readFileSync(cargoTomlPath, "utf-8");
77+
const cargoToml = (await parseToml(contents)) as
78+
| {
79+
package?: { name?: string };
80+
}
81+
| undefined;
82+
83+
if (cargoToml?.package?.name) {
84+
return joinPosix(
85+
workspace.workspaceFolders[0].uri.fsPath.replaceAll("\\", "/"),
86+
"target",
87+
"thumbv6m-none-eabi",
88+
"debug",
89+
cargoToml.package.name
90+
);
91+
}
92+
93+
return "";
94+
}
95+
6496
const settings = Settings.getInstance();
6597
if (
6698
settings !== undefined &&
@@ -102,3 +134,49 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
102134
);
103135
}
104136
}
137+
138+
export class LaunchTargetPathReleaseCommand extends CommandWithResult<string> {
139+
public static readonly id = "launchTargetPathRelease";
140+
141+
constructor() {
142+
super(LaunchTargetPathReleaseCommand.id);
143+
}
144+
145+
async execute(): Promise<string> {
146+
if (
147+
workspace.workspaceFolders === undefined ||
148+
workspace.workspaceFolders.length === 0
149+
) {
150+
return "";
151+
}
152+
153+
const isRustProject = State.getInstance().isRustProject;
154+
155+
if (!isRustProject) {
156+
return "";
157+
}
158+
159+
const cargoTomlPath = join(
160+
workspace.workspaceFolders[0].uri.fsPath,
161+
"Cargo.toml"
162+
);
163+
const contents = readFileSync(cargoTomlPath, "utf-8");
164+
const cargoToml = (await parseToml(contents)) as
165+
| {
166+
package?: { name?: string };
167+
}
168+
| undefined;
169+
170+
if (cargoToml?.package?.name) {
171+
return joinPosix(
172+
workspace.workspaceFolders[0].uri.fsPath.replaceAll("\\", "/"),
173+
"target",
174+
"thumbv6m-none-eabi",
175+
"release",
176+
cargoToml.package.name
177+
);
178+
}
179+
180+
return "";
181+
}
182+
}

0 commit comments

Comments
 (0)