From ed521c9d7a5083676c6328dc167677f4780faa56 Mon Sep 17 00:00:00 2001 From: "Brian A. Ignacio" Date: Fri, 11 Oct 2024 17:07:01 +0800 Subject: [PATCH] fix support for multiple sdkconfig files (#1252) * fix support for multiple sdkconfig files * dispose confserver when project config has changed * update compile commands json proj conf change * rm selected project config upon workspace change * rm idfTarget from project conf editor * fix set target status bar update * add open file button in project config editor * update pr comment action version * update default idf target --- .github/workflows/pr-comment.yml | 2 +- .../project-configuration.rst | 2 - docs_espressif/en/settings.rst | 2 +- src/build/buildTask.ts | 10 ++- src/config.ts | 1 - src/espIdf/menuconfig/confServerProcess.ts | 45 +++++++++++- src/espIdf/reconfigure/task.ts | 17 ++++- src/espIdf/setTarget/setTargetInIdf.ts | 10 +++ src/extension.ts | 52 ++++++++++++- src/project-conf/index.ts | 8 -- src/project-conf/projectConfPanel.ts | 32 +++++--- src/project-conf/projectConfiguration.ts | 1 - src/pythonManager.ts | 6 ++ src/statusBar/index.ts | 6 +- src/support/writeReport.ts | 1 - src/utils.ts | 73 ++++++++++++++----- .../components/projectConfElem.vue | 22 ++---- src/views/project-conf/main.ts | 17 ++++- src/views/project-conf/store.ts | 9 +++ src/workspaceConfig.ts | 34 +++++---- 20 files changed, 256 insertions(+), 94 deletions(-) diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml index 150f48898..e775fbdd9 100644 --- a/.github/workflows/pr-comment.yml +++ b/.github/workflows/pr-comment.yml @@ -8,7 +8,7 @@ jobs: if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest steps: - - uses: actions/github-script@v6 + - uses: actions/github-script@v7 with: # This snippet is public-domain, taken from # https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml diff --git a/docs_espressif/en/additionalfeatures/project-configuration.rst b/docs_espressif/en/additionalfeatures/project-configuration.rst index 7d9349e6b..713a1568d 100644 --- a/docs_espressif/en/additionalfeatures/project-configuration.rst +++ b/docs_espressif/en/additionalfeatures/project-configuration.rst @@ -22,8 +22,6 @@ To allow you to have multiple configurations for the same project, you can defin +-----------------------------------+-------------------------------------------------------------------------------------------+ | **idf.customExtraVars** | Variables to be added to system environment variables | +-----------------------------------+-------------------------------------------------------------------------------------------+ -| **idf.adapterTargetName** | ESP-IDF Target Chip (Example: esp32) | -+-----------------------------------+-------------------------------------------------------------------------------------------+ | **idf.flashBaudRate** | Flash Baud rate | +-----------------------------------+-------------------------------------------------------------------------------------------+ | **idf.monitorBaudRate** | Monitor Baud Rate (Empty by default to use SDKConfig CONFIG_ESP_CONSOLE_UART_BAUDRATE) | diff --git a/docs_espressif/en/settings.rst b/docs_espressif/en/settings.rst index 50b3c72a1..5a1dc9903 100644 --- a/docs_espressif/en/settings.rst +++ b/docs_espressif/en/settings.rst @@ -110,7 +110,7 @@ This is how the extension uses them: 6. **idf.openOcdLaunchArgs**: Launch arguments string array for OpenOCD. The resulting OpenOCD launch command looks like this: ``openocd -d${idf.openOcdDebugLevel} -f ${idf.openOcdConfigs} ${idf.openOcdLaunchArgs}``. .. note:: - * When you use the command **ESP-IDF: Set Espressif Device Target** it will override **idf.adapterTargetName** with selected chip and **idf.openOcdConfigs** with its default OpenOCD Configuration Files. + * When you use the command **ESP-IDF: Set Espressif Device Target** it will override the current sdkconfig IDF_TARGET with selected Espressif chip and **idf.openOcdConfigs** with its default OpenOCD Configuration Files. * If you want to customize the **idf.openOcdConfigs** alone, you can use the **ESP-IDF: Select OpenOCD Board Configuration** or modify your settings.json directly. Code Coverage Specific Settings diff --git a/src/build/buildTask.ts b/src/build/buildTask.ts index 4cc8ab1eb..693aee054 100644 --- a/src/build/buildTask.ts +++ b/src/build/buildTask.ts @@ -23,9 +23,10 @@ import * as vscode from "vscode"; import * as idfConf from "../idfConfiguration"; import { appendIdfAndToolsToPath, - isBinInPath, - getEspIdfFromCMake, compareVersion, + getEspIdfFromCMake, + getSDKConfigFilePath, + isBinInPath, } from "../utils"; import { TaskManager } from "../taskManager"; import { selectedDFUAdapterId } from "../flash/dfu"; @@ -167,6 +168,11 @@ export class BuildTask { } } + const sdkconfigFile = await getSDKConfigFilePath(this.currentWorkspace); + if (compilerArgs.indexOf("SDKCONFIG") === -1) { + compilerArgs.push(`-DSDKCONFIG=${sdkconfigFile}`); + } + const sdkconfigDefaults = (idfConf.readParameter("idf.sdkconfigDefaults") as string[]) || []; diff --git a/src/config.ts b/src/config.ts index 21d6933c2..591a28282 100644 --- a/src/config.ts +++ b/src/config.ts @@ -29,7 +29,6 @@ export namespace ESP { export namespace ProjectConfiguration { export let store: ProjectConfigStore; - export const CONFIGURATION_LIST_KEY = "PROJECT_CONFIGURATION_KEYS"; export const SELECTED_CONFIG = "SELECTED_PROJECT_CONFIG"; export const PROJECT_CONFIGURATION_FILENAME = "esp_idf_project_configuration.json"; diff --git a/src/espIdf/menuconfig/confServerProcess.ts b/src/espIdf/menuconfig/confServerProcess.ts index 4702a877d..b1bca4e7a 100644 --- a/src/espIdf/menuconfig/confServerProcess.ts +++ b/src/espIdf/menuconfig/confServerProcess.ts @@ -74,13 +74,14 @@ export class ConfserverProcess { const pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder); const modifiedEnv = await appendIdfAndToolsToPath(workspaceFolder); if (!ConfserverProcess.instance) { + const configFile = await getSDKConfigFilePath(workspaceFolder); ConfserverProcess.instance = new ConfserverProcess( workspaceFolder, extensionPath, pythonBinPath, + configFile, modifiedEnv ); - ConfserverProcess.instance.configFile = await getSDKConfigFilePath(workspaceFolder); } ConfserverProcess.instance.emitter.once("valuesLoaded", resolve); }); @@ -220,7 +221,24 @@ export class ConfserverProcess { if (enableCCache) { reconfigureArgs.push("--ccache"); } - reconfigureArgs.push("-C", currWorkspace.fsPath, "reconfigure"); + reconfigureArgs.push("-C", currWorkspace.fsPath); + const sdkconfigDefaults = + (idfConf.readParameter("idf.sdkconfigDefaults") as string[]) || []; + + if (reconfigureArgs.indexOf("SDKCONFIG") === -1) { + reconfigureArgs.push(`-DSDKCONFIG=${ConfserverProcess.instance.configFile}`) + } + + if ( + reconfigureArgs.indexOf("SDKCONFIG_DEFAULTS") === -1 && + sdkconfigDefaults && + sdkconfigDefaults.length + ) { + reconfigureArgs.push( + `-DSDKCONFIG_DEFAULTS='${sdkconfigDefaults.join(";")}'` + ); + } + reconfigureArgs.push("reconfigure"); const getSdkconfigProcess = spawn(pythonBinPath, reconfigureArgs, { env: modifiedEnv, }); @@ -299,6 +317,7 @@ export class ConfserverProcess { workspaceFolder: vscode.Uri, extensionPath: string, pythonBinPath: string, + configFile: string, modifiedEnv: { [key: string]: string } ) { this.workspaceFolder = workspaceFolder; @@ -308,6 +327,7 @@ export class ConfserverProcess { idfConf.readParameter("idf.espIdfPath", workspaceFolder).toString() || process.env.IDF_PATH; modifiedEnv.PYTHONUNBUFFERED = "0"; + this.configFile = configFile; const idfPath = path.join(this.espIdfPath, "tools", "idf.py"); const enableCCache = idfConf.readParameter( "idf.enableCCache", @@ -317,6 +337,27 @@ export class ConfserverProcess { if (enableCCache) { confServerArgs.push("--ccache"); } + const buildDirPath = idfConf.readParameter( + "idf.buildPath", + workspaceFolder + ) as string; + confServerArgs.push("-B", buildDirPath); + const sdkconfigDefaults = + (idfConf.readParameter("idf.sdkconfigDefaults") as string[]) || []; + + if (confServerArgs.indexOf("SDKCONFIG") === -1) { + confServerArgs.push(`-DSDKCONFIG=${this.configFile}`) + } + + if ( + confServerArgs.indexOf("SDKCONFIG_DEFAULTS") === -1 && + sdkconfigDefaults && + sdkconfigDefaults.length + ) { + confServerArgs.push( + `-DSDKCONFIG_DEFAULTS='${sdkconfigDefaults.join(";")}'` + ); + } confServerArgs.push("-C", workspaceFolder.fsPath, "confserver"); this.confServerProcess = spawn(pythonBinPath, confServerArgs, { env: modifiedEnv, diff --git a/src/espIdf/reconfigure/task.ts b/src/espIdf/reconfigure/task.ts index 188415d2e..f10c2a428 100644 --- a/src/espIdf/reconfigure/task.ts +++ b/src/espIdf/reconfigure/task.ts @@ -27,7 +27,7 @@ import { workspace, } from "vscode"; import { NotificationMode, readParameter } from "../../idfConfiguration"; -import { appendIdfAndToolsToPath } from "../../utils"; +import { appendIdfAndToolsToPath, compareVersion, getEspIdfFromCMake, getSDKConfigFilePath } from "../../utils"; import { join } from "path"; import { TaskManager } from "../../taskManager"; import { getVirtualEnvPythonPath } from "../../pythonManager"; @@ -65,12 +65,23 @@ export class IdfReconfigureTask { const idfPy = join(this.idfPathDir, "tools", "idf.py"); const reconfigureArgs = [idfPy]; + const espIdfVersion = await getEspIdfFromCMake(this.idfPathDir); + const useEqualSign = compareVersion(espIdfVersion, "4.4") >= 0; let buildPathArgsIndex = reconfigureArgs.indexOf("-B"); if (buildPathArgsIndex !== -1) { - reconfigureArgs.splice(buildPathArgsIndex, 2); + reconfigureArgs.splice(buildPathArgsIndex, useEqualSign ? 1 : 2); + } + if (useEqualSign) { + reconfigureArgs.push(`-B=${this.buildDirPath}`); + } else { + reconfigureArgs.push("-B", this.buildDirPath); + } + + const sdkconfigFile = await getSDKConfigFilePath(this.curWorkspace); + if (reconfigureArgs.indexOf("SDKCONFIG") === -1) { + reconfigureArgs.push(`-DSDKCONFIG=${sdkconfigFile}`); } - reconfigureArgs.push("-B", this.buildDirPath); const sdkconfigDefaults = (readParameter("idf.sdkconfigDefaults") as string[]) || []; diff --git a/src/espIdf/setTarget/setTargetInIdf.ts b/src/espIdf/setTarget/setTargetInIdf.ts index c8b0d8c59..a86e09897 100644 --- a/src/espIdf/setTarget/setTargetInIdf.ts +++ b/src/espIdf/setTarget/setTargetInIdf.ts @@ -59,6 +59,16 @@ export async function setTargetInIDF( } else { modifiedEnv.IDF_CCACHE_ENABLE = undefined; } + if (modifiedEnv.SDKCONFIG) { + setTargetArgs.push(`-DSDKCONFIG='${modifiedEnv.SDKCONFIG}'`); + } + const sdkconfigDefaults = + (readParameter("idf.sdkconfigDefaults") as string[]) || []; + + if (sdkconfigDefaults && sdkconfigDefaults.length) { + setTargetArgs.push(`-DSDKCONFIG_DEFAULTS='${sdkconfigDefaults.join(";")}'`); + } + setTargetArgs.push("set-target", selectedTarget.target); const pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder.uri); const setTargetResult = await spawn(pythonBinPath, setTargetArgs, { diff --git a/src/extension.ts b/src/extension.ts index cb9123ec1..e90ec4669 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -71,7 +71,7 @@ import { ArduinoComponentInstaller } from "./espIdf/arduino/addArduinoComponent" import { PartitionTableEditorPanel } from "./espIdf/partition-table"; import { ESPEFuseTreeDataProvider } from "./efuse/view"; import { ESPEFuseManager } from "./efuse"; -import { constants, createFileSync, pathExists, readJson } from "fs-extra"; +import { constants, createFileSync, pathExists } from "fs-extra"; import { getEspAdf } from "./espAdf/espAdfDownload"; import { getEspMdf } from "./espMdf/espMdfDownload"; import { SetupPanel } from "./setup/SetupPanel"; @@ -143,7 +143,7 @@ import { getFileList, getTestComponents } from "./espIdf/unitTest/utils"; import { saveDefSdkconfig } from "./espIdf/menuconfig/saveDefConfig"; import { createSBOM, installEspSBOM } from "./espBom"; import { getEspHomeKitSdk } from "./espHomekit/espHomekitDownload"; -import { selectIdfSetup } from "./versionSwitcher"; +import { getCurrentIdfSetup, selectIdfSetup } from "./versionSwitcher"; import { checkDebugAdapterRequirements } from "./espIdf/debugAdapter/checkPyReqs"; import { CDTDebugConfigurationProvider } from "./cdtDebugAdapter/debugConfProvider"; import { CDTDebugAdapterDescriptorFactory } from "./cdtDebugAdapter/server"; @@ -373,6 +373,30 @@ export async function activate(context: vscode.ExtensionContext) { `$(${commandDictionary[CommandKeys.SelectSerialPort].iconId}) ` + idfConf.readParameter("idf.port", workspaceRoot); } + if (statusBarItems["projectConf"]) { + statusBarItems["projectConf"].dispose(); + statusBarItems["projectConf"] = undefined; + const selectedConfig = ESP.ProjectConfiguration.store.get( + ESP.ProjectConfiguration.SELECTED_CONFIG + ); + ESP.ProjectConfiguration.store.clear(selectedConfig); + ESP.ProjectConfiguration.store.clear( + ESP.ProjectConfiguration.SELECTED_CONFIG + ); + } + const currentIdfSetup = await getCurrentIdfSetup( + workspaceRoot, + false + ); + if (statusBarItems["currentIdfVersion"]) { + statusBarItems["currentIdfVersion"].text = currentIdfSetup.isValid + ? `$(${ + commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId + }) ESP-IDF v${currentIdfSetup.version}` + : `$(${ + commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId + }) ESP-IDF InvalidSetup`; + } const coverageOptions = getCoverageOptions(workspaceRoot); covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions); break; @@ -911,6 +935,27 @@ export async function activate(context: vscode.ExtensionContext) { tooltip: option.uri.fsPath, }; utils.updateStatus(statusBarItems["workspace"], workspaceFolderInfo); + if (statusBarItems["projectConf"]) { + statusBarItems["projectConf"].dispose(); + statusBarItems["projectConf"] = undefined; + const selectedConfig = ESP.ProjectConfiguration.store.get( + ESP.ProjectConfiguration.SELECTED_CONFIG + ); + ESP.ProjectConfiguration.store.clear(selectedConfig); + ESP.ProjectConfiguration.store.clear( + ESP.ProjectConfiguration.SELECTED_CONFIG + ); + } + const currentIdfSetup = await getCurrentIdfSetup(workspaceRoot, false); + if (statusBarItems["currentIdfVersion"]) { + statusBarItems["currentIdfVersion"].text = currentIdfSetup.isValid + ? `$(${ + commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId + }) ESP-IDF v${currentIdfSetup.version}` + : `$(${ + commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId + }) ESP-IDF InvalidSetup`; + } const debugAdapterConfig = { currentWorkspace: workspaceRoot, } as IDebugAdapterConfig; @@ -1106,6 +1151,8 @@ export async function activate(context: vscode.ExtensionContext) { commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState ); await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]); + await utils.setCCppPropertiesJsonCompileCommands(workspaceRoot); + ConfserverProcess.dispose(); }); }); @@ -1830,6 +1877,7 @@ export async function activate(context: vscode.ExtensionContext) { workspaceRoot ); await setIdfTarget(enterDeviceTargetMsg, workspaceFolder); + await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]); }); }); diff --git a/src/project-conf/index.ts b/src/project-conf/index.ts index cd7c294ed..d5531f51d 100644 --- a/src/project-conf/index.ts +++ b/src/project-conf/index.ts @@ -43,13 +43,6 @@ export class ProjectConfigStore { public clear(key: string) { return this.set(key, undefined); } - - public getKeys() { - return this.ctx.workspaceState.get( - ESP.ProjectConfiguration.CONFIGURATION_LIST_KEY, - undefined - ); - } } export async function getProjectConfigurationElements(workspaceFolder: Uri) { @@ -76,7 +69,6 @@ export async function getProjectConfigurationElements(workspaceFolder: Uri) { }, env: projectConfJson[elem].env, flashBaudRate: projectConfJson[elem].flashBaudRate, - idfTarget: projectConfJson[elem].idfTarget, monitorBaudRate: projectConfJson[elem].monitorBaudRate, openOCD: { debugLevel: projectConfJson[elem].openOCD?.debugLevel, diff --git a/src/project-conf/projectConfPanel.ts b/src/project-conf/projectConfPanel.ts index 7961ddb21..47dda48bd 100644 --- a/src/project-conf/projectConfPanel.ts +++ b/src/project-conf/projectConfPanel.ts @@ -119,6 +119,17 @@ export class projectConfigurationPanel { }); } break; + case "openFilePath": + let selectedFile = await this.openFile(); + if (selectedFile) { + this.panel.webview.postMessage({ + command: "setFilePath", + confKey: message.confKey, + newPath: selectedFile, + sectionsKeys: message.sectionsKeys, + }); + } + break; default: break; } @@ -126,15 +137,6 @@ export class projectConfigurationPanel { this.panel.onDidDispose(() => this.dispose(), null, this.disposables); } - private async clearProjectConfFile() { - let projectConfKeys = ESP.ProjectConfiguration.store.getKeys(); - if (projectConfKeys && projectConfKeys.length) { - for (const confKey of projectConfKeys) { - ESP.ProjectConfiguration.store.clear(confKey); - } - } - } - private async openFolder() { const selectedFolder = await window.showOpenDialog({ canSelectFolders: true, @@ -146,6 +148,17 @@ export class projectConfigurationPanel { } } + private async openFile() { + const selectedFile = await window.showOpenDialog({ + canSelectFolders: false, + canSelectFiles: true, + canSelectMany: false, + }); + if (selectedFile && selectedFile.length > 0) { + return selectedFile[0].fsPath; + } + } + private clearSelectedProject(projectKeys: string[]) { const selectedConfig = ESP.ProjectConfiguration.store.get( ESP.ProjectConfiguration.SELECTED_CONFIG @@ -163,7 +176,6 @@ export class projectConfigurationPanel { private async saveProjectConfFile(projectConfDict: { [key: string]: ProjectConfElement; }) { - this.clearProjectConfFile(); const projectConfKeys = Object.keys(projectConfDict); this.clearSelectedProject(projectConfKeys); await saveProjectConfFile(this.workspaceFolder, projectConfDict); diff --git a/src/project-conf/projectConfiguration.ts b/src/project-conf/projectConfiguration.ts index 5e75cef35..5ca264479 100644 --- a/src/project-conf/projectConfiguration.ts +++ b/src/project-conf/projectConfiguration.ts @@ -26,7 +26,6 @@ export interface ProjectConfElement { }; env: { [key: string]: string }; flashBaudRate: string; - idfTarget: string; monitorBaudRate: string; openOCD: { debugLevel: number; diff --git a/src/pythonManager.ts b/src/pythonManager.ts index 87a1b6a2e..ace92bbc1 100644 --- a/src/pythonManager.ts +++ b/src/pythonManager.ts @@ -269,6 +269,12 @@ export async function getVirtualEnvPythonPath(workspaceFolder: Uri) { let pythonPath = readParameter("idf.pythonInstallPath") as string; let espIdfDir = readParameter("idf.espIdfPath", workspaceFolder) as string; let idfToolsDir = readParameter("idf.toolsPath", workspaceFolder) as string; + const idfPathExists = await pathExists(espIdfDir); + const idfToolsPathExists = await pathExists(idfToolsDir); + const pythonPathExists = await pathExists(pythonPath); + if (!idfPathExists || !idfToolsPathExists || !pythonPathExists) { + return; + } const virtualEnvPython = await getPythonEnvPath( espIdfDir, idfToolsDir, diff --git a/src/statusBar/index.ts b/src/statusBar/index.ts index 7d99a9581..89c05e2ab 100644 --- a/src/statusBar/index.ts +++ b/src/statusBar/index.ts @@ -29,6 +29,7 @@ import { readParameter } from "../idfConfiguration"; import { ESP } from "../config"; import { CommandItem } from "../cmdTreeView/cmdTreeDataProvider"; import { CommandKeys, createCommandDictionary } from "../cmdTreeView/cmdStore"; +import { getIdfTargetFromSdkconfig } from "../workspaceConfig"; export const statusBarItems: { [key: string]: StatusBarItem } = {}; @@ -54,14 +55,11 @@ export async function createCmdsStatusBarItems(workspaceFolder: Uri) { return {}; } const port = readParameter("idf.port", workspaceFolder) as string; - let idfTarget = readParameter("idf.adapterTargetName", workspaceFolder); + let idfTarget = await getIdfTargetFromSdkconfig(workspaceFolder); let flashType = readParameter("idf.flashType", workspaceFolder) as string; let projectConf = ESP.ProjectConfiguration.store.get( ESP.ProjectConfiguration.SELECTED_CONFIG ); - if (idfTarget === "custom") { - idfTarget = readParameter("idf.customAdapterTargetName", workspaceFolder); - } let currentIdfVersion = await getCurrentIdfSetup(workspaceFolder, false); diff --git a/src/support/writeReport.ts b/src/support/writeReport.ts index b566afcda..385350fc7 100644 --- a/src/support/writeReport.ts +++ b/src/support/writeReport.ts @@ -154,7 +154,6 @@ export async function writeTextReport( } } output += `Flash baud rate: ${reportedResult.projectConfigurations[key].flashBaudRate}${EOL}`; - output += `IDF Target: ${reportedResult.projectConfigurations[key].idfTarget}${EOL}`; output += `Monitor baud rate: ${reportedResult.projectConfigurations[key].monitorBaudRate}${EOL}`; if (reportedResult.projectConfigurations[key].openOCD) { diff --git a/src/utils.ts b/src/utils.ts index b75541b9a..96671c40d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -253,15 +253,6 @@ export async function createVscodeFolder(curWorkspaceFsPath: vscode.Uri) { export async function setCCppPropertiesJsonCompilerPath( curWorkspaceFsPath: vscode.Uri ) { - const cCppPropertiesJsonPath = path.join( - curWorkspaceFsPath.fsPath, - ".vscode", - "c_cpp_properties.json" - ); - const doesPathExists = await pathExists(cCppPropertiesJsonPath); - if (!doesPathExists) { - return; - } const modifiedEnv = await appendIdfAndToolsToPath(curWorkspaceFsPath); const idfTarget = modifiedEnv.IDF_TARGET || "esp32"; const gccTool = getToolchainToolName(idfTarget, "gcc"); @@ -270,22 +261,65 @@ export async function setCCppPropertiesJsonCompilerPath( curWorkspaceFsPath.fsPath, modifiedEnv ); + if (!compilerAbsolutePath) { + return; + } + let compilerRelativePath = compilerAbsolutePath.split( + modifiedEnv.IDF_TOOLS_PATH + )[1]; + const settingToUse = + process.platform === "win32" + ? "${config:idf.toolsPathWin}" + : "${config:idf.toolsPath}"; + + await updateCCppPropertiesJson( + curWorkspaceFsPath, + "compilerPath", + settingToUse + compilerRelativePath + ); +} + +export async function setCCppPropertiesJsonCompileCommands( + curWorkspaceFsPath: vscode.Uri +) { + const buildDirPath = idfConf.readParameter( + "idf.buildPath", + curWorkspaceFsPath + ) as string; + const compileCommandsPath = path.join(buildDirPath, "compile_commands.json"); + + await updateCCppPropertiesJson( + curWorkspaceFsPath, + "compileCommands", + compileCommandsPath + ); +} +export async function updateCCppPropertiesJson( + workspaceUri: vscode.Uri, + fieldToUpdate: string, + newFieldValue: string +) { + const cCppPropertiesJsonPath = path.join( + workspaceUri.fsPath, + ".vscode", + "c_cpp_properties.json" + ); + const doesPathExists = await pathExists(cCppPropertiesJsonPath); + if (!doesPathExists) { + return; + } const cCppPropertiesJson = await readJSON(cCppPropertiesJsonPath); if ( cCppPropertiesJson && cCppPropertiesJson.configurations && cCppPropertiesJson.configurations.length ) { - let compilerRelativePath = compilerAbsolutePath.split( - modifiedEnv.IDF_TOOLS_PATH - )[1]; - const settingToUse = - process.platform === "win32" - ? "${config:idf.toolsPathWin}" - : "${config:idf.toolsPath}"; - cCppPropertiesJson.configurations[0].compilerPath = - settingToUse + compilerRelativePath; + const buildDirPath = idfConf.readParameter( + "idf.buildPath", + workspaceUri + ) as string; + cCppPropertiesJson.configurations[0][fieldToUpdate] = newFieldValue; await writeJSON(cCppPropertiesJsonPath, cCppPropertiesJson, { spaces: vscode.workspace.getConfiguration().get("editor.tabSize") || 2, }); @@ -1144,7 +1178,8 @@ export async function appendIdfAndToolsToPath(curWorkspace: vscode.Uri) { } let sdkconfigFilePath = idfConf.readParameter( - "idf.sdkconfigFilePath" + "idf.sdkconfigFilePath", + curWorkspace ) as string; if (sdkconfigFilePath) { modifiedEnv.SDKCONFIG = sdkconfigFilePath; diff --git a/src/views/project-conf/components/projectConfElem.vue b/src/views/project-conf/components/projectConfElem.vue index 736e92f04..fd275447b 100644 --- a/src/views/project-conf/components/projectConfElem.vue +++ b/src/views/project-conf/components/projectConfElem.vue @@ -21,16 +21,6 @@ const openOcdDebugLevelOptions: { name: string; value: number }[] = [ { name: "Verbose", value: 4 }, ]; -const idfTargets: { name: string; value: string }[] = [ - { name: "esp32", value: "esp32" }, - { name: "ESP32 S2", value: "esp32s2" }, - { name: "ESP32 S3", value: "esp32s3" }, - { name: "ESP32 C2", value: "esp32c2" }, - { name: "ESP32 C3", value: "esp32c3" }, - { name: "ESP32 C6", value: "esp32c6" }, - { name: "ESP32 H2", value: "esp32h2" }, -]; - function updateElement(sections: string[], newValue: any) { store.updateConfigElement({ confKey: props.title, sections, newValue }); } @@ -39,6 +29,10 @@ function openBuildDir(sections: string[]) { store.openBuildPath({ confKey: props.title, sections }); } +function openFilePath(sections: string[]) { + store.openFilePath({ confKey: props.title, sections }); +} + function addValueToArray(sections: string[], newValue: any) { store.addValueToConfigElement({ confKey: props.title, @@ -93,6 +87,7 @@ function removeValueFromArray(sections: string[], index: number) { " :sections="['build', 'sdkconfigFilePath']" :updateMethod="updateElement" + :openMethod="openFilePath" /> - { }); } break; + case "setFilePath": + if (msg.confKey) { + store.updateConfigElement({ + confKey: msg.confKey, + sections: msg.sectionsKeys, + newValue: msg.newPath, + }); + } + break; case "initialLoad": if (msg.confList) { store.elements = msg.confList; @@ -48,4 +57,4 @@ window.addEventListener("message", (event: MessageEvent) => { default: break; } -}); \ No newline at end of file +}); diff --git a/src/views/project-conf/store.ts b/src/views/project-conf/store.ts index ac3d847a6..bae91d173 100644 --- a/src/views/project-conf/store.ts +++ b/src/views/project-conf/store.ts @@ -86,6 +86,14 @@ export const useProjectConfStore = defineStore("project-config", () => { }); } + function openFilePath(payload: { confKey: string; sections: string[] }) { + vscode.postMessage({ + command: "openFilePath", + sectionsKeys: payload.sections, + confKey: payload.confKey, + }); + } + function addNewConfigToList(confKey: string) { let newConf = { build: { @@ -174,6 +182,7 @@ export const useProjectConfStore = defineStore("project-config", () => { addNewConfigToList, addValueToConfigElement, openBuildPath, + openFilePath, updateConfigElement, removeValueFromConfigElement, requestInitValues, diff --git a/src/workspaceConfig.ts b/src/workspaceConfig.ts index f6866577f..b3e1ca422 100644 --- a/src/workspaceConfig.ts +++ b/src/workspaceConfig.ts @@ -86,21 +86,23 @@ export async function getIdfTargetFromSdkconfig( workspacePath: vscode.Uri, statusItem?: vscode.StatusBarItem ) { - let sdkConfigPath = await getSDKConfigFilePath(workspacePath); - const doesSdkconfigExists = await pathExists(sdkConfigPath); - if (!doesSdkconfigExists) { - return; - } - const configIdfTarget = await utils.getConfigValueFromSDKConfig( - "CONFIG_IDF_TARGET", - workspacePath - ); - const idfTarget = configIdfTarget.replace(/\"/g, ""); - if (!idfTarget) { - return; - } - if (statusItem) { - statusItem.text = "$(chip) " + idfTarget; + try { + const configIdfTarget = await utils.getConfigValueFromSDKConfig( + "CONFIG_IDF_TARGET", + workspacePath + ); + let idfTarget = configIdfTarget.replace(/\"/g, ""); + if (!idfTarget) { + idfTarget = "esp32"; + } + if (statusItem) { + statusItem.text = "$(chip) " + idfTarget; + } + return idfTarget; + } catch (error) { + if (statusItem) { + statusItem.text = "$(chip) esp32"; + } + return "esp32"; } - return idfTarget; }