|
1 | 1 | import { Command } from "./command.mjs"; |
2 | 2 | import Logger from "../logger.mjs"; |
3 | 3 | import { window, workspace } from "vscode"; |
4 | | -import { configureCmakeNinja } from "../utils/cmakeUtil.mjs"; |
| 4 | +import { cmakeGetPicoVar, configureCmakeNinja } from "../utils/cmakeUtil.mjs"; |
5 | 5 | import Settings, { SettingsKey } from "../settings.mjs"; |
6 | 6 | import { join } from "path"; |
7 | 7 | import { rimraf } from "rimraf"; |
8 | 8 | import { unknownErrorToString } from "../utils/errorHelper.mjs"; |
| 9 | +import type UI from "../ui.mjs"; |
9 | 10 |
|
10 | 11 | export default class ConfigureCmakeCommand extends Command { |
11 | 12 | private _logger: Logger = new Logger("ConfigureCmakeCommand"); |
@@ -60,7 +61,7 @@ export class CleanCMakeCommand extends Command { |
60 | 61 |
|
61 | 62 | public static readonly id = "cleanCmake"; |
62 | 63 |
|
63 | | - constructor() { |
| 64 | + constructor(private readonly _ui: UI) { |
64 | 65 | super(CleanCMakeCommand.id); |
65 | 66 | } |
66 | 67 |
|
@@ -115,5 +116,71 @@ export class CleanCMakeCommand extends Command { |
115 | 116 | "to get more information about the error." |
116 | 117 | ); |
117 | 118 | } |
| 119 | + |
| 120 | + const ws = workspaceFolder.uri.fsPath; |
| 121 | + const cMakeCachePath = join(ws, "build","CMakeCache.txt"); |
| 122 | + const newBuildType = cmakeGetPicoVar(cMakeCachePath, "CMAKE_BUILD_TYPE"); |
| 123 | + this._ui.updateBuildType(newBuildType ?? "unknown"); |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +export class SwitchBuildTypeCommand extends Command { |
| 128 | + private _logger: Logger = new Logger("SwitchBuildTypeCommand"); |
| 129 | + |
| 130 | + public static readonly id = "switchBuildType"; |
| 131 | + |
| 132 | + constructor(private readonly _ui: UI) { |
| 133 | + super(SwitchBuildTypeCommand.id); |
| 134 | + } |
| 135 | + |
| 136 | + async execute(): Promise<void> { |
| 137 | + const workspaceFolder = workspace.workspaceFolders?.[0]; |
| 138 | + |
| 139 | + // check if is a pico project |
| 140 | + if (workspaceFolder === undefined) { |
| 141 | + this._logger.warn("No workspace folder found."); |
| 142 | + void window.showWarningMessage("No workspace folder found."); |
| 143 | + |
| 144 | + return; |
| 145 | + } |
| 146 | + |
| 147 | + const settings = Settings.getInstance(); |
| 148 | + |
| 149 | + if ( |
| 150 | + settings !== undefined && |
| 151 | + settings.getBoolean(SettingsKey.useCmakeTools) |
| 152 | + ) { |
| 153 | + void window.showErrorMessage( |
| 154 | + "You must use the CMake Tools extension to configure your build. " + |
| 155 | + "To use this extension instead, change the useCmakeTools setting." |
| 156 | + ); |
| 157 | + |
| 158 | + return; |
| 159 | + } |
| 160 | + |
| 161 | + const ws = workspaceFolder.uri.fsPath; |
| 162 | + const cMakeCachePath = join(ws, "build","CMakeCache.txt"); |
| 163 | + const oldBuildType = cmakeGetPicoVar(cMakeCachePath, "CMAKE_BUILD_TYPE"); |
| 164 | + |
| 165 | + // QuickPick for the build type |
| 166 | + const quickPickItems = ["Debug", "Release", "MinSizeRel", "RelWithDebInfo"]; |
| 167 | + const buildType = await window.showQuickPick(quickPickItems, { |
| 168 | + placeHolder: `Current: ${oldBuildType}`, |
| 169 | + }); |
| 170 | + |
| 171 | + if (await configureCmakeNinja(workspaceFolder.uri, buildType)) { |
| 172 | + void window.showInformationMessage("CMake has configured your build."); |
| 173 | + } else { |
| 174 | + void window.showWarningMessage( |
| 175 | + "CMake failed to configure your build. " + |
| 176 | + "See the developer console for details " + |
| 177 | + "(Help -> Toggle Developer Tools). " + |
| 178 | + "You can also use the CMake Tools Extension Integration " + |
| 179 | + "to get more information about the error." |
| 180 | + ); |
| 181 | + } |
| 182 | + |
| 183 | + const newBuildType = cmakeGetPicoVar(cMakeCachePath, "CMAKE_BUILD_TYPE"); |
| 184 | + this._ui.updateBuildType(newBuildType ?? "unknown"); |
118 | 185 | } |
119 | 186 | } |
0 commit comments