Skip to content

Commit 3bd2221

Browse files
authored
[VSC-1578] Modify Event Activation for file types (#1568)
* feat: Modify Event Activation for file types Removed previous activation events for file types. We only check for CMakeLists.txt at root project folder if it includes "include($ENV{IDF_PATH}/tools/cmake/project.cmake)" * fix: If idf project is detected, activate - No matter the order of the projects, if an idf extension is present, extension will activate itself. - If no idf project is detected, but CMakeLists.txt is detected at root level user is asked if he wants to activate extension * fix: Ignore *.code-profile for linting fix: lint issue * fix: activation for folder without CMakeLists.txt file If there were folders without CMakeLists.txt file in root, but they had a CMakeLists.txt file in there subfolders, the extension would have activated * Improve ESP-IDF project detection and update messages Refactored the activation check to search for any CMakeLists.txt in the workspace and verify if it is an ESP-IDF project, rather than only checking root folders. Updated localized messages in Spanish, Portuguese, Russian, and Chinese to reflect the new logic and provide clearer prompts to users. * feat: optimize extension activation for multi-workspace ESP-IDF projects - Replace recursive CMakeLists.txt search with root-only validation - Use direct file system checks instead of workspace.findFiles for better performance - Support multiple workspace folders with ESP-IDF projects at root level - Maintain user prompt for non-ESP-IDF CMakeLists.txt files
1 parent 50acf1b commit 3bd2221

File tree

7 files changed

+71
-9
lines changed

7 files changed

+71
-9
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ get_serial_list.py
1515
*.vsix
1616
export.ps1
1717
export.bat
18+
*.code-profile
1819

1920
#dirs
2021
.vscode

l10n/bundle.l10n.es.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@
233233
"Type 'SWITCH' to confirm switching to Release Mode": "Escriba 'SWITCH' para confirmar el cambio al Modo Release",
234234
"Please type 'SWITCH' exactly to confirm": "Por favor escriba 'SWITCH' exactamente para confirmar",
235235
"Switching to Release Mode cancelled by user": "Cambio al Modo Release cancelado por el usuario",
236-
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Usuario confirmó el cambio al Modo Release. Procediendo con el cifrado de flash.",
237236
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually.": "La detección de devkit ESP-IDF conectados se omite durante la depuración. Aún puede seleccionar un objetivo manualmente.",
238-
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "La detección de devkit ESP-IDF conectados no está disponible para su versión de OpenOCD {openOCDVersion}. Se requiere la versión {minRequiredVersion} o superior. Aún puede seleccionar un objetivo manualmente."
237+
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "La detección de devkit ESP-IDF conectados no está disponible para su versión de OpenOCD {openOCDVersion}. Se requiere la versión {minRequiredVersion} o superior. Aún puede seleccionar un objetivo manualmente.",
238+
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "El usuario confirmó el cambio al Modo de Lanzamiento. Procediendo con el cifrado de flash.",
239+
"Activate Anyway": "Activar de todos modos",
240+
"No standard ESP-IDF project was found in this workspace. Do you want to activate the ESP-IDF extension anyway?": "No se encontró ningún proyecto ESP-IDF estándar en este espacio de trabajo. ¿Desea activar la extensión ESP-IDF de todos modos?"
239241
}

l10n/bundle.l10n.pt.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@
233233
"Type 'SWITCH' to confirm switching to Release Mode": "Digite 'SWITCH' para confirmar a mudança para o Modo de Release",
234234
"Please type 'SWITCH' exactly to confirm": "Por favor, digite 'SWITCH' exatamente para confirmar",
235235
"Switching to Release Mode cancelled by user": "Mudança para o Modo de Release cancelada pelo usuário",
236-
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Usuário confirmou a mudança para o Modo de Release. Prosseguindo com a criptografia flash.",
237236
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually.": "A detecção de devkit ESP-IDF conectados é ignorada durante a depuração. Você ainda pode selecionar um alvo manualmente.",
238-
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "A detecção de devkit ESP-IDF conectados não está disponível para sua versão do OpenOCD {openOCDVersion}. É necessária a versão {minRequiredVersion} ou superior. Você ainda pode selecionar um alvo manualmente."
237+
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "A detecção de devkit ESP-IDF conectados não está disponível para sua versão do OpenOCD {openOCDVersion}. É necessária a versão {minRequiredVersion} ou superior. Você ainda pode selecionar um alvo manualmente.",
238+
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Usuário confirmou a mudança para o Modo de Lançamento. Prosseguindo com a criptografia da flash.",
239+
"Activate Anyway": "Ativar mesmo assim",
240+
"No standard ESP-IDF project was found in this workspace. Do you want to activate the ESP-IDF extension anyway?": "Nenhum projeto ESP-IDF padrão foi encontrado neste espaço de trabalho. Deseja ativar a extensão ESP-IDF mesmo assim?"
239241
}

l10n/bundle.l10n.ru.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,7 @@
235235
"Switching to Release Mode cancelled by user": "Переключение в Режим Релиза отменено пользователем",
236236
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Пользователь подтвердил переключение в Режим Релиза. Продолжаем шифрование флеш-памяти.",
237237
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually.": "Обнаружение подключенных ESP-IDF devkit пропускается во время отладки. Вы все еще можете выбрать цель вручную.",
238-
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "Обнаружение подключенных ESP-IDF devkit недоступно для вашей версии OpenOCD {openOCDVersion}. Требуется версия {minRequiredVersion} или выше. Вы все еще можете выбрать цель вручную."
238+
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "Обнаружение подключенных ESP-IDF devkit недоступно для вашей версии OpenOCD {openOCDVersion}. Требуется версия {minRequiredVersion} или выше. Вы все еще можете выбрать цель вручную.",
239+
"Activate Anyway": "Активировать в любом случае",
240+
"No standard ESP-IDF project was found in this workspace. Do you want to activate the ESP-IDF extension anyway?": "В этой рабочей области не найден стандартный проект ESP-IDF. Хотите активировать расширение ESP-IDF в любом случае?"
239241
}

l10n/bundle.l10n.zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,7 @@
235235
"Switching to Release Mode cancelled by user": "用户取消了切换到发布模式",
236236
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "用户确认切换到发布模式。继续进行闪存加密。",
237237
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually.": "调试时跳过已连接的 ESP-IDF 开发板检测。您仍可以手动选择目标。",
238-
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "您的 OpenOCD 版本 {openOCDVersion} 不支持已连接的 ESP-IDF 开发板检测功能。需要 {minRequiredVersion} 或更高版本。您仍可以手动选择目标。"
238+
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "您的 OpenOCD 版本 {openOCDVersion} 不支持已连接的 ESP-IDF 开发板检测功能。需要 {minRequiredVersion} 或更高版本。您仍可以手动选择目标。",
239+
"Activate Anyway": "仍然激活",
240+
"No standard ESP-IDF project was found in this workspace. Do you want to activate the ESP-IDF extension anyway?": "在当前工作区中未找到标准 ESP-IDF 项目。您是否仍要激活 ESP-IDF 扩展?"
239241
}

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@
111111
"onView:idfPartitionExplorer",
112112
"onView:espRainmaker",
113113
"onView:idfComponents",
114-
"workspaceContains:**/project_description.json",
115-
"workspaceContains:**/sdkconfig",
116114
"workspaceContains:**/CMakeLists.txt"
117115
],
118116
"main": "./dist/extension",

src/extension.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { ArduinoComponentInstaller } from "./espIdf/arduino/addArduinoComponent"
7272
import { PartitionTableEditorPanel } from "./espIdf/partition-table";
7373
import { ESPEFuseTreeDataProvider } from "./efuse/view";
7474
import { ESPEFuseManager } from "./efuse";
75-
import { constants, createFileSync, pathExists } from "fs-extra";
75+
import { constants, createFileSync, pathExists, readFile } from "fs-extra";
7676
import { getEspAdf } from "./espAdf/espAdfDownload";
7777
import { getEspMdf } from "./espMdf/espMdfDownload";
7878
import { SetupPanel } from "./setup/SetupPanel";
@@ -276,6 +276,61 @@ export async function activate(context: vscode.ExtensionContext) {
276276
Telemetry.init(idfConf.readParameter("idf.telemetry") || false);
277277
utils.setExtensionContext(context);
278278
ChangelogViewer.showChangeLogAndUpdateVersion(context);
279+
280+
// Check for root CMakeLists.txt and its content before full activation
281+
if (PreCheck.isWorkspaceFolderOpen() && vscode.workspace.workspaceFolders) {
282+
let hasValidIdfProject = false;
283+
284+
for (const workspaceFolder of vscode.workspace.workspaceFolders) {
285+
const rootCMakeListsPath = path.join(
286+
workspaceFolder.uri.fsPath,
287+
"CMakeLists.txt"
288+
);
289+
const rootCMakeListsExists = await pathExists(rootCMakeListsPath);
290+
291+
if (rootCMakeListsExists) {
292+
try {
293+
const cmakeContent = await readFile(rootCMakeListsPath, "utf-8");
294+
if (
295+
cmakeContent.includes(
296+
"include($ENV{IDF_PATH}/tools/cmake/project.cmake)"
297+
)
298+
) {
299+
hasValidIdfProject = true;
300+
break; // Found a valid project, activate immediately
301+
}
302+
} catch (error) {
303+
Logger.error(
304+
`Error reading root CMakeLists.txt for activation check in ${workspaceFolder.name}.`,
305+
error,
306+
"extension activate checkCMakeContent"
307+
);
308+
}
309+
}
310+
}
311+
312+
if (!hasValidIdfProject) {
313+
// At least one CMakeLists.txt was found, but none are ESP-IDF projects.
314+
const activateAnyway = await vscode.window.showInformationMessage(
315+
vscode.l10n.t(
316+
"No standard ESP-IDF project was found in this workspace. Do you want to activate the ESP-IDF extension anyway?"
317+
),
318+
{ modal: false },
319+
{ title: vscode.l10n.t("Activate Anyway") }
320+
);
321+
if (
322+
!activateAnyway ||
323+
activateAnyway.title !== vscode.l10n.t("Activate Anyway")
324+
) {
325+
Logger.info("User chose not to activate the ESP-IDF extension.");
326+
return; // Exit activation early
327+
}
328+
Logger.info(
329+
"User chose to activate the ESP-IDF extension despite no standard ESP-IDF project was found."
330+
);
331+
}
332+
}
333+
279334
debugAdapterManager = DebugAdapterManager.init(context);
280335
OutputChannel.init();
281336
const registerIDFCommand = (

0 commit comments

Comments
 (0)