diff --git a/src/commands/launchTargetPath.mts b/src/commands/launchTargetPath.mts index 69951ba..7a4419c 100644 --- a/src/commands/launchTargetPath.mts +++ b/src/commands/launchTargetPath.mts @@ -3,6 +3,7 @@ import { CommandWithResult } from "./command.mjs"; import { commands, window, workspace } from "vscode"; import { join } from "path"; import Settings, { SettingsKey } from "../settings.mjs"; +import { cmakeGetPicoVar } from "../utils/cmakeUtil.mjs"; export default class LaunchTargetPathCommand extends CommandWithResult { constructor() { @@ -27,8 +28,8 @@ export default class LaunchTargetPathCommand extends CommandWithResult { // Extract the project name from the matched result if (match && match[1]) { - const projectName = match[1].trim(); - + let projectName = match[1].trim(); + if (matchBg && matchPoll) { // For examples with both background and poll, let user pick which to run const quickPickItems = ["Threadsafe Background", "Poll"]; @@ -45,6 +46,16 @@ export default class LaunchTargetPathCommand extends CommandWithResult { case quickPickItems[1]: return projectName + "_poll"; } + }else{ + if(workspace.workspaceFolders !== undefined) { + let cmakeCacheFile = workspace.workspaceFolders[0].uri.fsPath; + cmakeCacheFile = join(cmakeCacheFile,"build","CMakeCache.txt"); + + const value = cmakeGetPicoVar(cmakeCacheFile,"CMAKE_PROJECT_NAME"); + if(value !== null){ + projectName = value; + } + } } return projectName; diff --git a/src/commands/switchBoard.mts b/src/commands/switchBoard.mts index 18543bc..23ff2d1 100644 --- a/src/commands/switchBoard.mts +++ b/src/commands/switchBoard.mts @@ -11,8 +11,11 @@ import { cmakeGetSelectedToolchainAndSDKVersions, cmakeUpdateBoard, cmakeUpdateSDK, + cmakeGetPicoVar, } from "../utils/cmakeUtil.mjs"; import { join } from "path"; +import { resolve } from "path"; +import { normalize } from "path"; import { compareLt } from "../utils/semverUtil.mjs"; import type UI from "../ui.mjs"; import { updateVSCodeStaticConfigs } from "../utils/vscodeConfigUtil.mjs"; @@ -32,20 +35,74 @@ export default class SwitchBoardCommand extends Command { public static async askBoard(sdkVersion: string): Promise<[string, boolean] | undefined> { const quickPickItems: string[] = ["pico", "pico_w"]; + const workspaceFolder = workspace.workspaceFolders?.[0]; if (!compareLt(sdkVersion, "2.0.0")) { quickPickItems.push("pico2"); } - if (!compareLt(sdkVersion, "2.1.0")) { quickPickItems.push("pico2_w"); } - const sdkPath = buildSDKPath(sdkVersion); + const boardHeaderDirList = []; + + if(workspaceFolder !== undefined) { + const ws = workspaceFolder.uri.fsPath; + const cMakeCachePath = join(ws, "build","CMakeCache.txt"); + + let picoBoardHeaderDirs = cmakeGetPicoVar( + cMakeCachePath, + "PICO_BOARD_HEADER_DIRS"); + + if(picoBoardHeaderDirs){ + if(picoBoardHeaderDirs.startsWith("'")){ + const substrLen = picoBoardHeaderDirs.length-1; + picoBoardHeaderDirs = picoBoardHeaderDirs.substring(1,substrLen); + } + + const picoBoardHeaderDirList = picoBoardHeaderDirs.split(";"); + picoBoardHeaderDirList.forEach( + item => { + let boardPath = resolve(item); + const normalized = normalize(item); + + //If path is not absolute, join workspace path + if(boardPath !== normalized){ + boardPath = join(ws,normalized); + } - readdirSync(join(sdkPath, "src", "boards", "include", "boards")).forEach( - file => { - quickPickItems.push(file.split(".")[0]); + if(existsSync(boardPath)){ + boardHeaderDirList.push(boardPath); + } + } + ); + } + } + + const sdkPath = buildSDKPath(sdkVersion); + const systemBoardHeaderDir = + join(sdkPath,"src", "boards", "include","boards"); + + boardHeaderDirList.push(systemBoardHeaderDir); + + interface IBoardFile{ + [key: string]: string; + }; + + const boardFiles:IBoardFile = {}; + + boardHeaderDirList.forEach( + path =>{ + readdirSync(path).forEach( + file => { + const fullFilename = join(path, file); + if(fullFilename.endsWith(".h")) { + const boardName = file.split(".")[0]; + boardFiles[boardName] = fullFilename; + quickPickItems.push(boardName); + } + } + ) } ); @@ -58,11 +115,8 @@ export default class SwitchBoardCommand extends Command { return board; } - // Check that board doesn't have an RP2040 on it - const data = readFileSync( - join(sdkPath, "src", "boards", "include", "boards", `${board}.h`) - ) + const data = readFileSync(boardFiles[board]) if (data.includes("rp2040")) {