From 8c55198ed531e4eaa9988681299016c99a409357 Mon Sep 17 00:00:00 2001 From: "Brian A. Ignacio" Date: Tue, 19 Jan 2021 19:33:51 +0800 Subject: [PATCH] Feature/doctor cmd (#255) * initial doctor function * check settings fs access * add idf tools validation * add report file * refactor ignore result files * Delete result.json * add system info * launch cpp json files * add ru i18n cmd title * add cmd to readme --- .github/ISSUE_TEMPLATE/bug_report.md | 2 + .gitignore | 2 + .vscodeignore | 2 + README.md | 1 + gulpfile.js | 9 +- i18n/en/package.i18n.json | 1 + i18n/es/package.i18n.json | 1 + i18n/ru/package.i18n.json | 1 + i18n/zh-CN/package.i18n.json | 1 + package.json | 5 + package.nls.json | 1 + schema.i18n.json | 1 + src/extension.ts | 37 +++++++ src/support/checkEspIdfRequirements.ts | 60 ++++++++++ src/support/checkEspIdfTools.ts | 55 +++++++++ src/support/checkExtensionRequirements.ts | 53 +++++++++ src/support/checkSystemInfo.ts | 36 ++++++ src/support/checkVscodeFiles.ts | 54 +++++++++ src/support/configurationAccess.ts | 65 +++++++++++ src/support/configurationSettings.ts | 60 ++++++++++ src/support/espIdfVersion.ts | 41 +++++++ src/support/execChildProcess.ts | 42 +++++++ src/support/gitVersion.ts | 42 +++++++ src/support/index.ts | 64 +++++++++++ src/support/initReportObj.ts | 89 +++++++++++++++ src/support/pipVersion.ts | 36 ++++++ src/support/pythonPackages.ts | 38 +++++++ src/support/pythonVersion.ts | 38 +++++++ src/support/types.ts | 84 ++++++++++++++ src/support/writeReport.ts | 129 ++++++++++++++++++++++ 30 files changed, 1049 insertions(+), 1 deletion(-) create mode 100644 src/support/checkEspIdfRequirements.ts create mode 100644 src/support/checkEspIdfTools.ts create mode 100644 src/support/checkExtensionRequirements.ts create mode 100644 src/support/checkSystemInfo.ts create mode 100644 src/support/checkVscodeFiles.ts create mode 100644 src/support/configurationAccess.ts create mode 100644 src/support/configurationSettings.ts create mode 100644 src/support/espIdfVersion.ts create mode 100644 src/support/execChildProcess.ts create mode 100644 src/support/gitVersion.ts create mode 100644 src/support/index.ts create mode 100644 src/support/initReportObj.ts create mode 100644 src/support/pipVersion.ts create mode 100644 src/support/pythonPackages.ts create mode 100644 src/support/pythonVersion.ts create mode 100644 src/support/types.ts create mode 100644 src/support/writeReport.ts diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 3f44ec089..e52ac7c2b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -31,6 +31,8 @@ If applicable, add screenshots to help explain your problem. - ESP-IDF Version: [e.g. v3.2.2] - Python Version: [e.g. 2.7.10] +> **NOTE**: You can use the `ESP-IDF: Doctor command` to generate a report of your configuration. + **Logs** If applicable, please share the log file which can be obtained from diff --git a/.gitignore b/.gitignore index 0c407e1ea..09b345f0b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ testFiles/tools bandit_output.txt flake8_output.txt results/ +report.txt +report.json \ No newline at end of file diff --git a/.vscodeignore b/.vscodeignore index 55f302fcd..e1a7ad4a6 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -25,3 +25,5 @@ package-lock.json node_modules gulpfile.js .yarnrc +report.txt +report.json diff --git a/README.md b/README.md index 62262484e..c3ae23c3e 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Click F1 to show Visual studio code actions, then type **ESP-IDF** to | Install ESP-IDF Python Packages | | | | Open NVS Partition Editor | | | | Select OpenOCD Board Configuration | | | +| Doctor command | | | The **Add Arduino-ESP32 as ESP-IDF Component** command will add [Arduino-ESP32](https://github.com/espressif/arduino-esp32) as a ESP-IDF component in your current directory (`${CURRENT_DIRECTORY}/components/arduino`). You can also use the **Create ESP-IDF project** command with `arduino-as-component` template to create a new project directory that includes Arduino-esp32 as an ESP-IDF component. diff --git a/gulpfile.js b/gulpfile.js index d110df4b8..24274f6a7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -31,7 +31,14 @@ languagesDirs.forEach((langDir) => { }); function clean(done) { - del(["out/**", "package.nls.*.json", "*.vsix"]); + del([ + "dist/**", + "out/**", + "package.nls.*.json", + "*.vsix", + "report.json", + "report.txt", + ]); done(); } diff --git a/i18n/en/package.i18n.json b/i18n/en/package.i18n.json index be8663b7a..8d6f55d9b 100644 --- a/i18n/en/package.i18n.json +++ b/i18n/en/package.i18n.json @@ -30,6 +30,7 @@ "espIdf.getEspMdf.title": "ESP-IDF: Install ESP-MDF", "espIdf.installPyReqs.title": "ESP-IDF: Install ESP-IDF extension Python Packages", "espIdf.openDocUrl.title": "ESP-IDF: Open ESP-IDF Documentation...", + "espIdf.doctorCommand.title": "ESP-IDF: Doctor command", "espIdf.clearDocsSearchResult.title": "ESP-IDF: Clear ESP-IDF Search results", "espIdf.fullClean.title": "ESP-IDF: Full clean project", "espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: Open NVS Partition Editor", diff --git a/i18n/es/package.i18n.json b/i18n/es/package.i18n.json index fe1a85828..adf01d6cc 100644 --- a/i18n/es/package.i18n.json +++ b/i18n/es/package.i18n.json @@ -30,6 +30,7 @@ "espIdf.getEspMdf.title": "ESP-IDF: Instalar ESP-MDF", "espIdf.installPyReqs.title": "ESP-IDF: Instalar paquetes Python para extensión ESP-IDF", "espIdf.openDocUrl.title": "ESP-IDF: Abrir documentación ESP-IDF...", + "espIdf.doctorCommand.title": "ESP-IDF: Comando Doctor", "espIdf.clearDocsSearchResult.title": "ESP-IDF: Limpiar resultados de busqueda", "espIdf.fullClean.title": "ESP-IDF: Limpiar el proyecto", "espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: Abrir editor de particiones NVS", diff --git a/i18n/ru/package.i18n.json b/i18n/ru/package.i18n.json index 8871fb4d1..d0d0c8565 100644 --- a/i18n/ru/package.i18n.json +++ b/i18n/ru/package.i18n.json @@ -30,6 +30,7 @@ "espIdf.getEspMdf.title": "ESP-IDF: Установить ESP-MDF", "espIdf.installPyReqs.title": "ESP-IDF: Установите пакеты Python расширения ESP-IDF", "espIdf.openDocUrl.title": "ESP-IDF: Открыть документацию ...", + "espIdf.doctorCommand.title": "ESP-IDF: Команда врача", "espIdf.clearDocsSearchResult.title": "ESP-IDF: Очистить результаты поиска", "espIdf.fullClean.title": "ESP-IDF: Полный чистый проект", "espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: Откройте редактор разделов NVS", diff --git a/i18n/zh-CN/package.i18n.json b/i18n/zh-CN/package.i18n.json index 1a884a130..f0327c859 100644 --- a/i18n/zh-CN/package.i18n.json +++ b/i18n/zh-CN/package.i18n.json @@ -30,6 +30,7 @@ "espIdf.getEspMdf.title": "ESP-ADF: 安装ESP-MDF", "espIdf.installPyReqs.title": "ESP-IDF: 安装ESP-IDF扩展Python包", "espIdf.openDocUrl.title": "ESP-IDF: 打开ESP-IDF文档...", + "espIdf.doctorCommand.title": "ESP-IDF: 医生指挥部", "espIdf.clearDocsSearchResult.title": "ESP-IDF: 清除ESP-IDF搜索结果", "espIdf.fullClean.title": "ESP-IDF: 全清洁工程", "espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: 打开NVS分区编辑器", diff --git a/package.json b/package.json index d36da632c..2f39c9da5 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "onCommand:esp.webview.open.partition-table", "onCommand:espIdf.webview.nvsPartitionEditor", "onCommand:espIdf.selectOpenOcdConfigFiles", + "onCommand:espIdf.doctorCommand", "onView:idfAppTracer", "onView:idfAppTraceArchive", "onView:espRainmaker", @@ -782,6 +783,10 @@ { "command": "espIdf.selectOpenOcdConfigFiles", "title": "%espIdf.selectOpenOcdConfigFiles.title%" + }, + { + "command": "espIdf.doctorCommand", + "title": "%espIdf.doctorCommand.title%" } ], "breakpoints": [ diff --git a/package.nls.json b/package.nls.json index bdab83223..2056a2c28 100644 --- a/package.nls.json +++ b/package.nls.json @@ -30,6 +30,7 @@ "espIdf.getEspMdf.title": "ESP-IDF: Install ESP-MDF", "espIdf.installPyReqs.title": "ESP-IDF: Install ESP-IDF extension Python Packages", "espIdf.openDocUrl.title": "ESP-IDF: Open ESP-IDF Documentation...", + "espIdf.doctorCommand.title": "ESP-IDF: Doctor command", "espIdf.clearDocsSearchResult.title": "ESP-IDF: Clear ESP-IDF Search results", "espIdf.fullClean.title": "ESP-IDF: Full clean project", "espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: Open NVS Partition Editor", diff --git a/schema.i18n.json b/schema.i18n.json index 48564eb1f..646954448 100644 --- a/schema.i18n.json +++ b/schema.i18n.json @@ -103,6 +103,7 @@ "espIdf.selectOpenOcdConfigFiles.title", "espIdf.fullClean.title", "espIdf.webview.nvsPartitionEditor.title", + "espIdf.doctorCommand.title", "debug.initConfig.name", "debug.initConfig.description", "param.adapterTargetName", diff --git a/src/extension.ts b/src/extension.ts index 8011efdd5..12974d402 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -99,6 +99,9 @@ import { release } from "os"; import del from "del"; import { NVSPartitionTable } from "./espIdf/nvs/partitionTable/panel"; import { getBoards } from "./espIdf/openOcd/boardConfiguration"; +import { generateConfigurationReport } from "./support"; +import { initializeReportObject } from "./support/initReportObj"; +import { writeTextReport } from "./support/writeReport"; // Global variables shared by commands let workspaceRoot: vscode.Uri; @@ -1339,6 +1342,40 @@ export async function activate(context: vscode.ExtensionContext) { }); }); + registerIDFCommand("espIdf.doctorCommand", async () => { + await vscode.window.withProgress( + { + cancellable: false, + location: vscode.ProgressLocation.Notification, + title: "ESP-IDF: Preparing ESP-IDF extension report", + }, + async ( + progress: vscode.Progress<{ message: string; increment: number }> + ) => { + const reportedResult = initializeReportObject(); + try { + await generateConfigurationReport( + context, + workspaceRoot, + reportedResult + ); + } catch (error) { + reportedResult.latestError = error; + const errMsg = error.message + ? error.message + : "Configuration report error"; + Logger.error(errMsg, error); + Logger.warnNotify( + "Extension configuration report has been copied to clipboard with errors" + ); + const reportOutput = await writeTextReport(reportedResult, context); + await vscode.env.clipboard.writeText(reportOutput); + return reportedResult; + } + } + ); + }); + registerIDFCommand( "espIdf.apptrace.archive.showReport", (trace: AppTraceArchiveItems) => { diff --git a/src/support/checkEspIdfRequirements.ts b/src/support/checkEspIdfRequirements.ts new file mode 100644 index 000000000..aea2dea9c --- /dev/null +++ b/src/support/checkEspIdfRequirements.ts @@ -0,0 +1,60 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:45:23 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { join } from "path"; +import * as vscode from "vscode"; +import { execChildProcess } from "./execChildProcess"; +import { reportObj } from "./types"; + +export async function checkEspIdfRequirements( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + const requirementsPath = join( + reportedResult.configurationSettings.espIdfPath, + "requirements.txt" + ); + const result = await checkRequirements( + context, + reportedResult, + requirementsPath + ); + reportedResult.idfCheckRequirements.output = result; + reportedResult.idfCheckRequirements.result = result; +} + +export async function checkRequirements( + context: vscode.ExtensionContext, + reportedResult: reportObj, + requirementsPath: string +) { + const checkPythonDepsScript = join( + reportedResult.configurationSettings.espIdfPath, + "tools", + "check_python_dependencies.py" + ); + const modifiedEnv: { [key: string]: string } = <{ [key: string]: string }>( + Object.assign({}, process.env) + ); + modifiedEnv.IDF_PATH = reportedResult.configurationSettings.espIdfPath; + const requirementsResult = await execChildProcess( + `${reportedResult.configurationSettings.pythonBinPath} ${checkPythonDepsScript} -r "${requirementsPath}"`, + context.extensionPath, + { env: modifiedEnv, cwd: context.extensionPath } + ); + return requirementsResult.trim(); +} diff --git a/src/support/checkEspIdfTools.ts b/src/support/checkEspIdfTools.ts new file mode 100644 index 000000000..64efdf133 --- /dev/null +++ b/src/support/checkEspIdfTools.ts @@ -0,0 +1,55 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:40:28 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { pathExists, readJSON } from "fs-extra"; +import { join } from "path"; +import * as vscode from "vscode"; +import { IdfToolsManager } from "../idfToolsManager"; +import { PlatformInformation } from "../PlatformInformation"; +import { OutputChannel } from "../logger/outputChannel"; +import { reportObj } from "./types"; + +export async function checkEspIdfTools( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + const platformInfo = await PlatformInformation.GetPlatformInformation(); + let toolsJsonPath: string = join( + reportedResult.configurationSettings.espIdfPath, + "tools", + "tools.json" + ); + const jsonExists = await pathExists(toolsJsonPath); + if (!jsonExists) { + const idfToolsJsonToUse = + reportedResult.espIdfVersion.result.localeCompare("4.0") < 0 + ? "fallback-tools.json" + : "tools.json"; + toolsJsonPath = join(context.extensionPath, idfToolsJsonToUse); + } + const toolsJson = await readJSON(toolsJsonPath); + const idfToolsManager = new IdfToolsManager( + toolsJson, + platformInfo, + OutputChannel.init() + ); + const verifiedPkgs = await idfToolsManager.getRequiredToolsInfo( + reportedResult.configurationSettings.toolsPath, + reportedResult.configurationSettings.customExtraPaths + ); + reportedResult.espIdfToolsVersions = verifiedPkgs; +} diff --git a/src/support/checkExtensionRequirements.ts b/src/support/checkExtensionRequirements.ts new file mode 100644 index 000000000..652887206 --- /dev/null +++ b/src/support/checkExtensionRequirements.ts @@ -0,0 +1,53 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:47:28 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { join } from "path"; +import * as vscode from "vscode"; +import { reportObj } from "./types"; +import { checkRequirements } from "./checkEspIdfRequirements"; + +export async function checkExtensionRequirements( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + const requirementsPath = join(context.extensionPath, "requirements.txt"); + const result = await checkRequirements( + context, + reportedResult, + requirementsPath + ); + reportedResult.extensionRequirements.output = result; + reportedResult.extensionRequirements.result = result; +} + +export async function checkDebugAdapterRequirements( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + const requirementsPath = join( + context.extensionPath, + "esp_debug_adapter", + "requirements.txt" + ); + const result = await checkRequirements( + context, + reportedResult, + requirementsPath + ); + reportedResult.debugAdapterRequirements.output = result; + reportedResult.debugAdapterRequirements.result = result; +} diff --git a/src/support/checkSystemInfo.ts b/src/support/checkSystemInfo.ts new file mode 100644 index 000000000..49f9ab82c --- /dev/null +++ b/src/support/checkSystemInfo.ts @@ -0,0 +1,36 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Tuesday, 12th January 2021 7:43:50 pm + * Copyright 2021 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ESP } from "../config"; +import { reportObj } from "./types"; +import * as vscode from "vscode"; +import * as os from "os"; + +export async function checkSystemInfo(reportedResult: reportObj) { + const extensionVersion = vscode.extensions.getExtension(ESP.extensionID); + reportedResult.systemInfo.architecture = os.arch(); + reportedResult.systemInfo.envPath = + process.platform === "win32" ? process.env.Path : process.env.PATH; + reportedResult.systemInfo.extensionVersion = extensionVersion + ? extensionVersion.packageJSON.version + : "ESP-IDF_VERSION_NOT_FOUND"; + reportedResult.systemInfo.language = vscode.env.language; + reportedResult.systemInfo.platform = os.platform(); + reportedResult.systemInfo.systemName = os.release(); + reportedResult.systemInfo.shell = vscode.env.shell; + reportedResult.systemInfo.vscodeVersion = vscode.version; +} diff --git a/src/support/checkVscodeFiles.ts b/src/support/checkVscodeFiles.ts new file mode 100644 index 000000000..9181c9f48 --- /dev/null +++ b/src/support/checkVscodeFiles.ts @@ -0,0 +1,54 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 13th January 2021 3:22:57 pm + * Copyright 2021 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { reportObj } from "./types"; +import { Uri } from "vscode"; +import { join } from "path"; +import { readFile } from "fs-extra"; + +export async function checkLaunchJson( + reportedResult: reportObj, + currentWorkspace: Uri +) { + if (!currentWorkspace) { + return; + } + const launchJsonPath = join( + currentWorkspace.fsPath, + ".vscode", + "launch.json" + ); + const launchJsonObj = await readFile(launchJsonPath, "utf8"); + reportedResult.launchJson = launchJsonObj; +} + +export async function checkCCppPropertiesJson( + reportedResult: reportObj, + currentWorkspace: Uri +) { + if (!currentWorkspace) { + return; + } + const cCppPropertiesJsonPath = join( + currentWorkspace.fsPath, + ".vscode", + "c_cpp_properties.json" + ); + const cCppPropertiesObj = await readFile(cCppPropertiesJsonPath, "utf8"); + reportedResult.cCppPropertiesJson = cCppPropertiesObj; +} diff --git a/src/support/configurationAccess.ts b/src/support/configurationAccess.ts new file mode 100644 index 000000000..7fabd6028 --- /dev/null +++ b/src/support/configurationAccess.ts @@ -0,0 +1,65 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:03:52 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { constants } from "fs-extra"; +import { delimiter } from "path"; +import * as vscode from "vscode"; +import { canAccessFile } from "../utils"; +import { execChildProcess } from "./execChildProcess"; +import { reportObj } from "./types"; + +export async function getConfigurationAccess( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + reportedResult.configurationAccess.toolsPath = canAccessFile( + reportedResult.configurationSettings.toolsPath, + constants.R_OK + ); + reportedResult.configurationAccess.espIdfPath = canAccessFile( + reportedResult.configurationSettings.espIdfPath, + constants.R_OK + ); + reportedResult.configurationAccess.pythonBinPath = canAccessFile( + reportedResult.configurationSettings.pythonBinPath, + constants.X_OK + ); + const toolPathsArray = reportedResult.configurationSettings.customExtraPaths.split( + delimiter + ); + reportedResult.configurationAccess.espIdfToolsPaths = {}; + for (const tool of toolPathsArray) { + reportedResult.configurationAccess.espIdfToolsPaths[tool] = canAccessFile( + tool, + constants.R_OK + ); + } + if (process.platform !== "win32") { + const cmakePathInEnv = await execChildProcess( + `which cmake`, + context.extensionPath + ); + reportedResult.configurationAccess.cmakeInEnv = + cmakePathInEnv && cmakePathInEnv.indexOf("not found") === -1; + const ninjaPathInEnv = await execChildProcess( + `which ninja`, + context.extensionPath + ); + reportedResult.configurationAccess.ninjaInEnv = + ninjaPathInEnv && ninjaPathInEnv.indexOf("not found") === -1; + } +} diff --git a/src/support/configurationSettings.ts b/src/support/configurationSettings.ts new file mode 100644 index 000000000..7d522b83b --- /dev/null +++ b/src/support/configurationSettings.ts @@ -0,0 +1,60 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:02:17 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { reportObj } from "./types"; +import * as vscode from "vscode"; + +export function getConfigurationSettings(reportedResult: reportObj) { + const winFlag = process.platform === "win32" ? "Win" : ""; + const configurationSettings: string[] = [ + "idf.espIdfPath" + winFlag, + "idf.customExtraPaths", + "idf.customExtraVars", + "idf.pythonBinPath" + winFlag, + "idf.port" + winFlag, + "idf.openOcdConfigs", + "idf.toolsPath" + winFlag, + ]; + const settingsValues = {}; + for (const conf of configurationSettings) { + const confValue = vscode.workspace.getConfiguration("").get(conf); + settingsValues[conf] = confValue; + } + reportedResult.configurationSettings = { + espIdfPath: vscode.workspace + .getConfiguration("") + .get("idf.espIdfPath" + winFlag), + customExtraPaths: vscode.workspace + .getConfiguration("") + .get("idf.customExtraPaths"), + customExtraVars: vscode.workspace + .getConfiguration("") + .get("idf.customExtraVars"), + pythonBinPath: vscode.workspace + .getConfiguration("") + .get("idf.pythonBinPath" + winFlag), + pythonPackages: [], + serialPort: vscode.workspace.getConfiguration("").get("idf.port"), + openOcdConfigs: + vscode.workspace.getConfiguration("").get("idf.openOcdConfigs") || [], + toolsPath: vscode.workspace + .getConfiguration("") + .get("idf.toolsPath" + winFlag), + systemEnvPath: + process.platform === "win32" ? process.env.Path : process.env.PATH, + }; +} diff --git a/src/support/espIdfVersion.ts b/src/support/espIdfVersion.ts new file mode 100644 index 000000000..ebadbb008 --- /dev/null +++ b/src/support/espIdfVersion.ts @@ -0,0 +1,41 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:34:31 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { execChildProcess } from "./execChildProcess"; +import { reportObj } from "./types"; + +const ESP_IDF_VERSION_REGEX = /v(\d+)(?:\.)?(\d+)?(?:\.)?(\d+)?.*/; + +export async function getEspIdfVersion(reportedResult: reportObj) { + const rawEspIdfVersion = await execChildProcess( + "git describe --tags", + reportedResult.configurationSettings.espIdfPath + ); + reportedResult.espIdfVersion.output = rawEspIdfVersion; + const espIdfVersionMatch = rawEspIdfVersion.match(ESP_IDF_VERSION_REGEX); + if (espIdfVersionMatch && espIdfVersionMatch.length) { + let espVersion: string = ""; + for (let i = 1; i < espIdfVersionMatch.length; i++) { + if (espIdfVersionMatch[i]) { + espVersion = `${espVersion}.${espIdfVersionMatch[i]}`; + } + } + reportedResult.espIdfVersion.result = espVersion.substr(1); + } else { + reportedResult.espIdfVersion.result = "Not found"; + } +} diff --git a/src/support/execChildProcess.ts b/src/support/execChildProcess.ts new file mode 100644 index 000000000..61e0e04f7 --- /dev/null +++ b/src/support/execChildProcess.ts @@ -0,0 +1,42 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 5:18:11 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { exec, ExecOptions } from "child_process"; + +export function execChildProcess( + cmd: string, + pathWhereToExecute: string, + opts?: ExecOptions +) { + if (!opts) { + opts = { + cwd: pathWhereToExecute, + maxBuffer: 500 * 1024, + }; + } + return new Promise((resolve, reject) => { + exec(cmd, opts, (error: Error, stdout: string, stderr: string) => { + if (error) { + return reject(error); + } + if (stderr && stderr.length) { + return resolve("".concat(stderr, stdout)); + } + return resolve(stdout); + }); + }); +} diff --git a/src/support/gitVersion.ts b/src/support/gitVersion.ts new file mode 100644 index 000000000..b07429ef0 --- /dev/null +++ b/src/support/gitVersion.ts @@ -0,0 +1,42 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:36:51 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as vscode from "vscode"; +import { execChildProcess } from "./execChildProcess"; +import { reportObj } from "./types"; + +const GIT_VERSION_REGEX = /(?:git\sversion\s)(\d+)(.\d+)?(.\d+)?(?:.windows.\d+)?/g; + +export async function getGitVersion( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + const rawGitVersion = await execChildProcess( + "git --version", + context.extensionPath + ); + reportedResult.gitVersion.output = rawGitVersion; + const versionMatches = rawGitVersion.match(GIT_VERSION_REGEX); + if (versionMatches && versionMatches.length) { + reportedResult.gitVersion.result = versionMatches[0].replace( + /git\sversion\s/g, + "" + ); + } else { + reportedResult.gitVersion.result = "Not found"; + } +} diff --git a/src/support/index.ts b/src/support/index.ts new file mode 100644 index 000000000..59abd09a2 --- /dev/null +++ b/src/support/index.ts @@ -0,0 +1,64 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 23rd December 2020 4:35:32 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as vscode from "vscode"; +import { Logger } from "../logger/logger"; +import { reportObj } from "./types"; +import { getConfigurationSettings } from "./configurationSettings"; +import { getConfigurationAccess } from "./configurationAccess"; +import { getGitVersion } from "./gitVersion"; +import { getEspIdfVersion } from "./espIdfVersion"; +import { getPythonVersion } from "./pythonVersion"; +import { getPipVersion } from "./pipVersion"; +import { getPythonPackages } from "./pythonPackages"; +import { checkEspIdfTools } from "./checkEspIdfTools"; +import { checkEspIdfRequirements } from "./checkEspIdfRequirements"; +import { + checkDebugAdapterRequirements, + checkExtensionRequirements, +} from "./checkExtensionRequirements"; +import { writeTextReport } from "./writeReport"; +import { checkSystemInfo } from "./checkSystemInfo"; +import { checkCCppPropertiesJson, checkLaunchJson } from "./checkVscodeFiles"; + +export async function generateConfigurationReport( + context: vscode.ExtensionContext, + currentWorkspace: vscode.Uri, + reportedResult: reportObj +) { + getConfigurationSettings(reportedResult); + await checkSystemInfo(reportedResult); + await getConfigurationAccess(reportedResult, context); + await getGitVersion(reportedResult, context); + await getEspIdfVersion(reportedResult); + await getPythonVersion(reportedResult, context); + await getPipVersion(reportedResult, context); + await getPythonPackages(reportedResult, context); + await checkEspIdfTools(reportedResult, context); + await checkEspIdfRequirements(reportedResult, context); + await checkExtensionRequirements(reportedResult, context); + await checkDebugAdapterRequirements(reportedResult, context); + await checkLaunchJson(reportedResult, currentWorkspace); + await checkCCppPropertiesJson(reportedResult, currentWorkspace); + const reportOutput = await writeTextReport(reportedResult, context); + await vscode.env.clipboard.writeText(reportOutput); + reportedResult.formatedOutput = reportOutput; + Logger.infoNotify( + "Extension configuration report has been copied to clipboard" + ); + return reportedResult; +} diff --git a/src/support/initReportObj.ts b/src/support/initReportObj.ts new file mode 100644 index 000000000..c5c72f44d --- /dev/null +++ b/src/support/initReportObj.ts @@ -0,0 +1,89 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 5:20:44 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { reportObj } from "./types"; + +export function initializeReportObject() { + const report = new reportObj(); + report.configurationSettings = { + systemEnvPath: undefined, + espIdfPath: undefined, + customExtraPaths: undefined, + customExtraVars: undefined, + pythonBinPath: undefined, + pythonPackages: undefined, + serialPort: undefined, + openOcdConfigs: undefined, + toolsPath: undefined, + }; + report.cCppPropertiesJson = undefined; + report.configurationAccess = { + espIdfPath: undefined, + espIdfToolsPaths: undefined, + pythonBinPath: undefined, + cmakeInEnv: undefined, + ninjaInEnv: undefined, + toolsPath: undefined, + }; + report.debugAdapterRequirements = { + output: undefined, + result: undefined, + }; + report.espIdfToolsVersions = undefined; + report.espIdfVersion = { + output: undefined, + result: undefined, + }; + report.extensionRequirements = { + output: undefined, + result: undefined, + }; + report.formatedOutput = undefined; + report.gitVersion = { + output: undefined, + result: undefined, + }; + report.idfCheckRequirements = { + output: undefined, + result: undefined, + }; + report.launchJson = undefined; + report.latestError = undefined; + report.pipVersion = { + output: undefined, + result: undefined, + }; + report.pythonPackages = { + output: undefined, + result: undefined, + }; + report.pythonVersion = { + output: undefined, + result: undefined, + }; + report.systemInfo = { + architecture: undefined, + envPath: undefined, + extensionVersion: undefined, + language: undefined, + shell: undefined, + platform: undefined, + systemName: undefined, + vscodeVersion: undefined, + }; + return report; +} diff --git a/src/support/pipVersion.ts b/src/support/pipVersion.ts new file mode 100644 index 000000000..52f7e6547 --- /dev/null +++ b/src/support/pipVersion.ts @@ -0,0 +1,36 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:08:26 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as vscode from "vscode"; +import { execChildProcess } from "./execChildProcess"; +import { reportObj } from "./types"; +const PIP_VERSION_REGEX = /pip\s\d+(.\d+)?(.\d+)?/g; + +export async function getPipVersion( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + const rawPipVersion = await execChildProcess( + `${reportedResult.configurationSettings.pythonBinPath} -m pip --version`, + context.extensionPath + ); + reportedResult.pipVersion.output = rawPipVersion; + const match = rawPipVersion.match(PIP_VERSION_REGEX); + if (match && match.length) { + reportedResult.pipVersion.result = match[0].replace(/pip\s/, ""); + } +} diff --git a/src/support/pythonPackages.ts b/src/support/pythonPackages.ts new file mode 100644 index 000000000..7efc213da --- /dev/null +++ b/src/support/pythonPackages.ts @@ -0,0 +1,38 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:11:32 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as vscode from "vscode"; +import { execChildProcess } from "./execChildProcess"; +import { reportObj } from "./types"; + +export async function getPythonPackages( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + const rawPythonPackagesList = await execChildProcess( + `${reportedResult.configurationSettings.pythonBinPath} -m pip list --format json`, + context.extensionPath + ); + reportedResult.pythonPackages.output = rawPythonPackagesList; + reportedResult.pythonPackages.result = rawPythonPackagesList; + const parsedPkgsListMatches = rawPythonPackagesList.match(/\[.*\]/g); + if (parsedPkgsListMatches && parsedPkgsListMatches.length) { + reportedResult.configurationSettings.pythonPackages = JSON.parse( + parsedPkgsListMatches[0] + ); + } +} diff --git a/src/support/pythonVersion.ts b/src/support/pythonVersion.ts new file mode 100644 index 000000000..9753ff90c --- /dev/null +++ b/src/support/pythonVersion.ts @@ -0,0 +1,38 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 4:07:07 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as vscode from "vscode"; +import { execChildProcess } from "./execChildProcess"; +import { reportObj } from "./types"; +const PYTHON_VERSION_REGEX = /Python\s\d+(.\d+)?(.\d+)?/g; + +export async function getPythonVersion( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + const rawPythonVersion = await execChildProcess( + `${reportedResult.configurationSettings.pythonBinPath} --version`, + context.extensionPath + ); + reportedResult.pythonVersion.output = rawPythonVersion; + const match = rawPythonVersion.match(PYTHON_VERSION_REGEX); + if (match && match.length) { + reportedResult.pythonVersion.result = match[0].replace(/Python\s/g, ""); + } else { + reportedResult.pythonVersion.result = "Not found"; + } +} diff --git a/src/support/types.ts b/src/support/types.ts new file mode 100644 index 000000000..8c5d209f5 --- /dev/null +++ b/src/support/types.ts @@ -0,0 +1,84 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 5:19:16 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class ConfigurationAccess { + espIdfPath: boolean; + espIdfToolsPaths: { [key: string]: boolean }; + pythonBinPath: boolean; + cmakeInEnv: boolean; + ninjaInEnv: boolean; + toolsPath: boolean; +} +export class Configuration { + systemEnvPath: string; + espIdfPath: string; + customExtraPaths: string; + customExtraVars: string; + pythonBinPath: string; + pythonPackages: pyPkgVersion[]; + serialPort: string; + openOcdConfigs: string[]; + toolsPath: string; +} + +export class SystemInfo { + architecture: string; + envPath: string; + extensionVersion: string; + language: string; + shell: string; + platform: string; + systemName: string; + vscodeVersion: string; +} + +export class pyPkgVersion { + name: string; + version: string; +} + +export class idfToolResult { + actual: string; + doesToolExist: boolean; + expected: string; + id: string; +} + +export class execResult { + output: string; + result: string; +} + +export class reportObj { + configurationSettings: Configuration; + configurationAccess: ConfigurationAccess; + espIdfToolsVersions: idfToolResult[]; + espIdfVersion: execResult; + gitVersion: execResult; + latestError: Error; + launchJson: any; + cCppPropertiesJson: any; + pipVersion: execResult; + pythonVersion: execResult; + pythonPackages: execResult; + idfCheckRequirements: execResult; + extensionRequirements: execResult; + debugAdapterRequirements: execResult; + formatedOutput: string; + systemInfo: SystemInfo; +} diff --git a/src/support/writeReport.ts b/src/support/writeReport.ts new file mode 100644 index 000000000..f46e5dd4c --- /dev/null +++ b/src/support/writeReport.ts @@ -0,0 +1,129 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Wednesday, 30th December 2020 5:07:59 pm + * Copyright 2020 Espressif Systems (Shanghai) CO LTD + *  + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *  + * http://www.apache.org/licenses/LICENSE-2.0 + *  + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { writeFile, writeJson } from "fs-extra"; +import { EOL, release } from "os"; +import { join } from "path"; +import * as vscode from "vscode"; +import { reportObj } from "./types"; + +export async function writeTextReport( + reportedResult: reportObj, + context: vscode.ExtensionContext +) { + let output = `---------------------------------------------- ESP-IDF Extension for Visual Studio Code report ---------------------------------------------${EOL}`; + const lineBreak = `--------------------------------------------------------------------------------------------------------------------------------------------${EOL}`; + output += `OS ${reportedResult.systemInfo.platform} ${reportedResult.systemInfo.architecture} ${reportedResult.systemInfo.systemName} ${EOL}`; + output += `System environment variable PATH ${EOL} ${reportedResult.systemInfo.envPath} ${EOL}`; + output += `Visual Studio Code version ${reportedResult.systemInfo.extensionVersion} ${EOL}`; + output += `Visual Studio Code language ${reportedResult.systemInfo.language} ${EOL}`; + output += `Visual Studio Code shell ${reportedResult.systemInfo.shell} ${EOL}`; + output += `ESP-IDF Extension version ${reportedResult.systemInfo.vscodeVersion} ${EOL}`; + output += `---------------------------------------------------- Extension configuration settings ------------------------------------------------------${EOL}`; + output += `ESP-IDF Path (idf.espIdfPath) ${reportedResult.configurationSettings.espIdfPath}${EOL}`; + output += `Custom extra paths (idf.customExtraPaths) ${reportedResult.configurationSettings.customExtraPaths}${EOL}`; + output += `Custom extra vars (idf.customExtraVars) ${reportedResult.configurationSettings.customExtraVars}${EOL}`; + output += `Virtual env Python Path (idf.pythonBinPath) ${reportedResult.configurationSettings.pythonBinPath}${EOL}`; + output += `Serial port (idf.port) ${reportedResult.configurationSettings.serialPort}${EOL}`; + output += `OpenOCD Configs (idf.openOcdConfigs) ${reportedResult.configurationSettings.openOcdConfigs}${EOL}`; + output += `ESP-IDF Tools Path (idf.toolsPath) ${reportedResult.configurationSettings.toolsPath}${EOL}`; + output += `-------------------------------------------------------- Configurations access -------------------------------------------------------------${EOL}`; + output += `Access to ESP-IDF Path (idf.espIdfPath) ${reportedResult.configurationAccess.espIdfPath}${EOL}`; + output += `Access to ESP-IDF Custom extra paths${EOL}`; + for (let key in reportedResult.configurationAccess.espIdfToolsPaths) { + output += `Access to ${key}: ${reportedResult.configurationAccess.espIdfToolsPaths[key]}${EOL}`; + } + output += `Access to Virtual env Python Path (idf.pythonBinPath) ${reportedResult.configurationAccess.pythonBinPath}${EOL}`; + output += `Access to CMake in environment PATH ${reportedResult.configurationAccess.cmakeInEnv}${EOL}`; + output += `Access to Ninja in environment PATH ${reportedResult.configurationAccess.ninjaInEnv}${EOL}`; + output += `Access to ESP-IDF Tools Path (idf.toolsPath) ${reportedResult.configurationAccess.toolsPath}${EOL}`; + output += `----------------------------------------------------------- Executables Versions -----------------------------------------------------------${EOL}`; + output += `Git version ${ + reportedResult.gitVersion.result + ? reportedResult.gitVersion.result + : reportedResult.gitVersion.output + }${EOL}`; + output += `ESP-IDF version ${ + reportedResult.espIdfVersion.result + ? reportedResult.espIdfVersion.result + : reportedResult.espIdfVersion.output + }${EOL}`; + output += `Python version ${ + reportedResult.pythonVersion.result + ? reportedResult.pythonVersion.result + : reportedResult.pythonVersion.output + }${EOL}`; + output += `Python's pip version ${ + reportedResult.pipVersion.result + ? reportedResult.pipVersion.result + : reportedResult.pipVersion.output + }${EOL}`; + output += `-------------------------------------------------- Python packages in idf.pythonBinPath ----------------------------------------------------${EOL}`; + if (reportedResult.configurationSettings.pythonPackages) { + for (let pkg of reportedResult.configurationSettings.pythonPackages) { + output += `${pkg.name} version: ${pkg.version}${EOL}`; + } + } else { + output += `Python packages ${ + reportedResult.pythonPackages.result + ? reportedResult.pythonPackages.result + : reportedResult.pythonPackages.output + }${EOL}`; + } + output += `---------------------------------------------------- Check ESP-IDF python requirements.txt -------------------------------------------------${EOL}`; + output += `Check ESP-IDF Python packages ${ + reportedResult.idfCheckRequirements.result + ? reportedResult.idfCheckRequirements.result + : reportedResult.idfCheckRequirements.output + }${EOL}`; + output += `---------------------------------------------------- Check extension requirements.txt ------------------------------------------------------${EOL}`; + output += `Check Extension Python packages ${ + reportedResult.extensionRequirements.result + ? reportedResult.extensionRequirements.result + : reportedResult.extensionRequirements.output + }${EOL}`; + output += `---------------------------------------------------- Check ESP-IDF debug adapter requirements.txt ------------------------------------------${EOL}`; + output += `Check Debug AdapterPython packages ${ + reportedResult.debugAdapterRequirements.result + ? reportedResult.debugAdapterRequirements.result + : reportedResult.debugAdapterRequirements.output + }${EOL}`; + if (reportedResult.launchJson) { + output += `---------------------------------------------------- Visual Studio Code launch.json --------------------------------------------------------${EOL}`; + output += `${reportedResult.launchJson} ${EOL}`; + } + if (reportedResult.cCppPropertiesJson) { + output += `---------------------------------------------------- Visual Studio Code c_cpp_properties.json ----------------------------------------------${EOL}`; + output += `${reportedResult.cCppPropertiesJson} ${EOL}`; + } + if (reportedResult.latestError) { + output += `----------------------------------------------------------- Latest error -----------------------------------------------------------------${EOL}`; + output += `Latest error at ${ + reportedResult.latestError.message + ? reportedResult.latestError.message + : "Unknown error in ESP-IDF doctor command" + }${EOL}`; + } + output += lineBreak; + const resultFile = join(context.extensionPath, "report.txt"); + const resultJson = join(context.extensionPath, "report.json"); + await writeFile(resultFile, output); + await writeJson(resultJson, reportedResult, { + spaces: vscode.workspace.getConfiguration().get("editor.tabSize") || 2, + }); + return output; +}