]> Git Repo - pico-vscode.git/blob - src/commands/launchTargetPath.mts
Install OpenOCD and tools from github
[pico-vscode.git] / src / commands / launchTargetPath.mts
1 import { readFileSync } from "fs";
2 import { CommandWithResult } from "./command.mjs";
3 import { workspace } from "vscode";
4 import { join } from "path";
5
6 export default class LaunchTargetPathCommand extends CommandWithResult<string> {
7   constructor() {
8     super("launchTargetPath");
9   }
10
11   private readProjectNameFromCMakeLists(filename: string): string | null {
12     // Read the file
13     const fileContent = readFileSync(filename, "utf-8");
14
15     // Match the project line using a regular expression
16     const regex = /project\(([^)\s]+)/;
17     const match = regex.exec(fileContent);
18
19     // Extract the project name from the matched result
20     if (match && match[1]) {
21       const projectName = match[1].trim();
22
23       return projectName;
24     }
25
26     return null; // Return null if project line is not found
27   }
28
29   execute(): string {
30     if (
31       workspace.workspaceFolders === undefined ||
32       workspace.workspaceFolders.length === 0
33     ) {
34       return "";
35     }
36
37     const fsPathFolder = workspace.workspaceFolders[0].uri.fsPath;
38
39     const projectName = this.readProjectNameFromCMakeLists(
40       join(fsPathFolder, "CMakeLists.txt")
41     );
42
43     if (projectName === null) {
44       return "";
45     }
46
47     return join(fsPathFolder, "build", projectName + ".elf");
48   }
49 }
This page took 0.028694 seconds and 4 git commands to generate.