Skip to content

Commit

Permalink
Set of changes for 1st Code Review
Browse files Browse the repository at this point in the history
- Removed helper function from logger/utils
- Moved code in already existing event listener
- Wrapped event listener with context.subscriptions.push()
- Localized messages displayed to user
  • Loading branch information
radurentea committed Oct 1, 2024
1 parent 657eb95 commit f96d071
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 59 deletions.
4 changes: 3 additions & 1 deletion l10n/bundle.l10n.es.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,7 @@
"Open ESP-IDF Terminal": "Abrir terminal ESP-IDF",
"Doctor Command": "Comando médico",
"Execute Custom Task": "Ejecutar tarea personalizada",
"Wait for ESP-IDF build or flash to finish": "Espere a que finalice la compilación o la actualización de ESP-IDF"
"Wait for ESP-IDF build or flash to finish": "Espere a que finalice la compilación o la actualización de ESP-IDF",
"compile_commands.json is missing. This may cause errors with code analysis extensions.": "Falta compile_commands.json. Esto puede causar errores con las extensiones de análisis de código.",
"Generate compile_commands.json": "Generar compile_commands.json"
}
4 changes: 3 additions & 1 deletion l10n/bundle.l10n.pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,7 @@
"Open ESP-IDF Terminal": "Abra o terminal ESP-IDF",
"Doctor Command": "Comando Médico",
"Execute Custom Task": "Executar tarefa personalizada",
"Wait for ESP-IDF build or flash to finish": "Aguarde a conclusão da compilação ou flash do ESP-IDF"
"Wait for ESP-IDF build or flash to finish": "Aguarde a conclusão da compilação ou flash do ESP-IDF",
"compile_commands.json is missing. This may cause errors with code analysis extensions.": "O arquivo compile_commands.json está faltando. Isso pode causar erros com extensões de análise de código.",
"Generate compile_commands.json": "Gerar compile_commands.json"
}
4 changes: 3 additions & 1 deletion l10n/bundle.l10n.ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,7 @@
"Open ESP-IDF Terminal": "Открыть терминал ESP-IDF",
"Doctor Command": "Доктор Команда",
"Execute Custom Task": "Выполнить пользовательскую задачу",
"Wait for ESP-IDF build or flash to finish": "Подождите завершения сборки или прошивки ESP-IDF."
"Wait for ESP-IDF build or flash to finish": "Подождите завершения сборки или прошивки ESP-IDF.",
"compile_commands.json is missing. This may cause errors with code analysis extensions.": "Отсутствует файл compile_commands.json. Это может вызвать ошибки в работе расширений для анализа кода.",
"Generate compile_commands.json": "Создать compile_commands.json"
}
4 changes: 3 additions & 1 deletion l10n/bundle.l10n.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,7 @@
"Open ESP-IDF Terminal": "打开 ESP-IDF 终端",
"Doctor Command": "医生指挥",
"Execute Custom Task": "执行自定义任务",
"Wait for ESP-IDF build or flash to finish": "等待 ESP-IDF 构建或刷新完成"
"Wait for ESP-IDF build or flash to finish": "等待 ESP-IDF 构建或刷新完成",
"compile_commands.json is missing. This may cause errors with code analysis extensions.": "缺少 compile_commands.json 文件。这可能会导致代码分析扩展出错。",
"Generate compile_commands.json": "生成 compile_commands.json"
}
96 changes: 49 additions & 47 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { ExamplesPlanel } from "./examples/ExamplesPanel";
import * as idfConf from "./idfConfiguration";
import { Logger } from "./logger/logger";
import { OutputChannel } from "./logger/outputChannel";
import { showInfoNotificationWithAction, executeCommand } from "./logger/utils";
import { showInfoNotificationWithAction } from "./logger/utils";
import * as utils from "./utils";
import { PreCheck } from "./utils";
import {
Expand Down Expand Up @@ -359,11 +359,26 @@ export async function activate(context: vscode.ExtensionContext) {
}
});
context.subscriptions.push(srcWatchOnChangeDisposable);

vscode.workspace.onDidChangeWorkspaceFolders(async (e) => {
if (PreCheck.isWorkspaceFolderOpen()) {
for (const ws of e.removed) {
if (workspaceRoot && ws.uri === workspaceRoot) {
context.subscriptions.push(
vscode.workspace.onDidChangeWorkspaceFolders(async (e) => {
if (PreCheck.isWorkspaceFolderOpen()) {
for (const ws of e.removed) {
if (workspaceRoot && ws.uri === workspaceRoot) {
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
await getIdfTargetFromSdkconfig(
workspaceRoot,
statusBarItems["target"]
);
if (statusBarItems && statusBarItems["port"]) {
statusBarItems["port"].text =
"$(plug) " + idfConf.readParameter("idf.port", workspaceRoot);
}
const coverageOptions = getCoverageOptions(workspaceRoot);
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
break;
}
}
if (typeof workspaceRoot === undefined) {
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
await getIdfTargetFromSdkconfig(
workspaceRoot,
Expand All @@ -376,39 +391,30 @@ export async function activate(context: vscode.ExtensionContext) {
}
const coverageOptions = getCoverageOptions(workspaceRoot);
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
break;
}
const buildDirPath = idfConf.readParameter(
"idf.buildPath",
workspaceRoot
) as string;
const projectName = await getProjectName(buildDirPath);
const projectElfFile = `${path.join(buildDirPath, projectName)}.elf`;
const debugAdapterConfig = {
currentWorkspace: workspaceRoot,
elfFile: projectElfFile,
} as IDebugAdapterConfig;
debugAdapterManager.configureAdapter(debugAdapterConfig);
const openOCDConfig: IOpenOCDConfig = {
workspace: workspaceRoot,
} as IOpenOCDConfig;
openOCDManager.configureServer(openOCDConfig);
qemuManager.configure({
workspaceFolder: workspaceRoot,
} as IQemuOptions);
await checkAndNotifyMissingCompileCommands();
}
if (typeof workspaceRoot === undefined) {
workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]);
await getIdfTargetFromSdkconfig(
workspaceRoot,
statusBarItems["target"]
);
const coverageOptions = getCoverageOptions(workspaceRoot);
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
}
const buildDirPath = idfConf.readParameter(
"idf.buildPath",
workspaceRoot
) as string;
const projectName = await getProjectName(buildDirPath);
const projectElfFile = `${path.join(buildDirPath, projectName)}.elf`;
const debugAdapterConfig = {
currentWorkspace: workspaceRoot,
elfFile: projectElfFile,
} as IDebugAdapterConfig;
debugAdapterManager.configureAdapter(debugAdapterConfig);
const openOCDConfig: IOpenOCDConfig = {
workspace: workspaceRoot,
} as IOpenOCDConfig;
openOCDManager.configureServer(openOCDConfig);
qemuManager.configure({
workspaceFolder: workspaceRoot,
} as IQemuOptions);
}
ConfserverProcess.dispose();
});
ConfserverProcess.dispose();
})
);

vscode.debug.onDidTerminateDebugSession((e) => {
if (isOpenOCDLaunchedByDebug && !isDebugRestarted) {
Expand Down Expand Up @@ -3569,13 +3575,7 @@ export async function activate(context: vscode.ExtensionContext) {
new HintHoverProvider(treeDataProvider)
)
);

checkAndNotifyMissingCompileCommands();
context.subscriptions.push(
vscode.workspace.onDidChangeWorkspaceFolders(() => {
checkAndNotifyMissingCompileCommands();
})
);
}

function checkAndNotifyMissingCompileCommands() {
Expand All @@ -3593,17 +3593,19 @@ function checkAndNotifyMissingCompileCommands() {

if (!compileCommandsExists) {
showInfoNotificationWithAction(
"compile_commands.json is missing. This may cause errors with the Microsoft C/C++ extension.",
"Generate compile_commands.json",
executeCommand("espIdf.idfReconfigureTask")
vscode.l10n.t(
"compile_commands.json is missing. This may cause errors with code analysis extensions."
),
vscode.l10n.t("Generate compile_commands.json"),
() => vscode.commands.executeCommand("espIdf.idfReconfigureTask")
);
}
}
} catch (error) {
const msg = error.message
? error.message
: "Error checking for compile_commands.json file.";
Logger.error(msg, error);
Logger.error(msg, error, "extension compileCommandsExists");
}
});
}
Expand Down
8 changes: 0 additions & 8 deletions src/logger/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,3 @@ export async function showInfoNotificationWithAction(
await Promise.resolve(action());
}
}

// Helper functions for common actions
export function executeCommand(
commandId: string,
...args: any[]
): NotificationAction {
return () => vscode.commands.executeCommand(commandId, ...args);
}

0 comments on commit f96d071

Please sign in to comment.