Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/components management system #1300

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,15 @@
}
],
"typescript.updateImportsOnFileMove.enabled": "always",
"workbench.editor.enablePreview": true
"workbench.editor.enablePreview": true,
"idf.espIdfPathWin": "C:\\Users\\radur\\esp171\\v5.2.2\\esp-idf",
"idf.pythonBinPathWin": "C:\\Users\\radur\\esptools171\\python_env\\idf5.2_py3.11_env\\Scripts\\python.exe",
"idf.toolsPathWin": "C:\\Users\\radur\\esptools171",
"idf.customExtraPaths": "C:\\Users\\radur\\esptools171\\tools\\xtensa-esp-elf-gdb\\14.2_20240403\\xtensa-esp-elf-gdb\\bin;C:\\Users\\radur\\esptools171\\tools\\riscv32-esp-elf-gdb\\14.2_20240403\\riscv32-esp-elf-gdb\\bin;C:\\Users\\radur\\esptools171\\tools\\xtensa-esp-elf\\esp-13.2.0_20230928\\xtensa-esp-elf\\bin;C:\\Users\\radur\\esptools171\\tools\\riscv32-esp-elf\\esp-13.2.0_20230928\\riscv32-esp-elf\\bin;C:\\Users\\radur\\esptools171\\tools\\esp32ulp-elf\\2.35_20220830\\esp32ulp-elf\\bin;C:\\Users\\radur\\esptools171\\tools\\cmake\\3.24.0\\bin;C:\\Users\\radur\\esptools171\\tools\\openocd-esp32\\v0.12.0-esp32-20240318\\openocd-esp32\\bin;C:\\Users\\radur\\esptools171\\tools\\ninja\\1.11.1;C:\\Users\\radur\\esptools171\\tools\\idf-exe\\1.0.3;C:\\Users\\radur\\esptools171\\tools\\ccache\\4.8\\ccache-4.8-windows-x86_64;C:\\Users\\radur\\esptools171\\tools\\dfu-util\\0.11\\dfu-util-0.11-win64;C:\\Users\\radur\\esptools171\\tools\\esp-rom-elfs\\20230320",
"idf.customExtraVars": {
"OPENOCD_SCRIPTS": "C:\\Users\\radur\\esptools171\\tools\\openocd-esp32\\v0.12.0-esp32-20240318/openocd-esp32/share/openocd/scripts",
"IDF_CCACHE_ENABLE": "1",
"ESP_ROM_ELF_DIR": "C:\\Users\\radur\\esptools171\\tools\\esp-rom-elfs\\20230320/"
},
"idf.gitPathWin": "C:\\Users\\radur\\esptools171\\tools\\idf-git\\2.39.2\\cmd\\git.exe"
}
29 changes: 28 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"onView:idfPartitionExplorer",
"onView:espRainmaker",
"onView:idfComponents",
"onView:espRegistryComponents",
"workspaceContains:**/project_description.json",
"workspaceContains:**/sdkconfig",
"workspaceContains:**/CMakeLists.txt"
Expand Down Expand Up @@ -199,6 +200,10 @@
{
"id": "idfComponents",
"name": "%view.components.name%"
},
{
"id": "espRegistryComponents",
"name": "%view.idf.espRegistryComponents%"
}
]
},
Expand All @@ -224,6 +229,11 @@
}
],
"view/title": [
{
"command": "espIdf.espRegistryComponents.refresh",
"group": "navigation",
"when": "view == espRegistryComponents"
},
{
"command": "espIdf.searchError",
"group": "navigation",
Expand Down Expand Up @@ -270,6 +280,11 @@
}
],
"view/item/context": [
{
"command": "espIdf.deleteComponent",
"when": "view == espRegistryComponents",
"group": "inline"
},
{
"command": "esp.rainmaker.backend.logout",
"when": "view == espRainmaker && viewItem == account",
Expand Down Expand Up @@ -978,7 +993,19 @@
"commands": [
{
"command": "espIdf.searchError",
"title": "%espIdf.searchError.title%"
"title": "%espIdf.searchError.title%",
"category": "ESP-IDF"
},
{
"command": "espIdf.espRegistryComponents.refresh",
"title": "%espIdf.espRegistryComponentsRefresh.title%",
"category": "ESP-IDF",
"icon": "$(refresh)"
},
{
"command": "espIdf.deleteComponent",
"title": "Delete Component",
"icon": "$(trash)"
},
{
"command": "espIdf.createFiles",
Expand Down
4 changes: 3 additions & 1 deletion package.nls.es.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"esp_idf.tmoScaleFactor.description": "Factor de escala para el tiempo de espera de gdb [predeterminado:1]",
"esp_idf.verifyAppBinBeforeDebug.description": "Verificar binarios de la aplicación antes de depurar",
"espIdf.searchError.title": "ESP-IDF: Sugerencia de error de búsqueda",
"espIdf.espRegistryComponents.title": "Actualizar Componentes",
"idf.flashType.description": "Método de flasheo del dispositivo, UART o JTag",
"idf.wssPort.description": "Puerto del servidor de socket web para Core Dump o GDB Stub",
"openocd.tcl.host.description": "Host para conexión tcl de Openocd",
Expand Down Expand Up @@ -167,7 +168,7 @@
"trace.stop_tmo.description": "stop_tmo se establecerá para el rastreo de la aplicación",
"trace.trace_size.description": "trace_size se establecerá para el rastreo de la aplicación",
"trace.wait4halt.description": "wait4halt se establecerá para el rastreo de la aplicación",
"view.components.name": "Componentes del proyecto",
"view.components.name": "Navegación de Componentes",
"view.debug.peripheral": "Visor periférico ESP-IDF",
"view.idf.espEFuseExplorer": "Explorador de eFuse",
"view.idf.espRainmaker": "RainMaker",
Expand All @@ -176,6 +177,7 @@
"view.idf.idfCommands": "Comandos",
"view.idf.idfPartitionExplorer": "Explorador de Particiones del Dispositivo",
"view.idf.idfSearchResults": "Resultados de búsqueda de documentación",
"view.idf.espRegistryComponents": "Componentes del Registro ESP",
"viewContainer.title": "ESP-IDF: Explorador",
"viewWelcome.idfPartitionExplorer": "Muestra la lista de particiones de su dispositivo con la opción de flashear binarios (.bin) en la partición seleccionada.\n\nSeleccione el puerto serial de su dispositivo y haga clic en Actualizar tabla de particiones.",
"viewWelcome.idfSearchResults": "En cualquier editor de archivos abierto, seleccione un texto y haga clic con el botón derecho y seleccione ESP-IDF: Buscar en la documentación para obtener resultados coincidentes aquí.\n\nLos resultados se basan en su idioma actual de VS Code, versión de idf.espIdfPath (si no, la última) y idf.adapterTargetName.",
Expand Down
4 changes: 3 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"esp_idf.tmoScaleFactor.description": "Scale factor for gdb timeout [default:1]",
"esp_idf.verifyAppBinBeforeDebug.description": "Verify app binaries before debug",
"espIdf.searchError.title": "ESP-IDF: Search Error Hint",
"espIdf.espRegistryComponentsRefresh.title": "Refresh Components",
"idf.flashType.description": "Device flash method, UART or JTag",
"idf.wssPort.description": "Web Socket Server Port for Core Dump or GDB Stub",
"openocd.tcl.host.description": "Host for OpenOCD tcl connection",
Expand Down Expand Up @@ -167,7 +168,7 @@
"trace.stop_tmo.description": "stop_tmo will be set for the apptrace",
"trace.trace_size.description": "trace_size will set for the apptrace",
"trace.wait4halt.description": "wait4halt will be set for the apptrace",
"view.components.name": "Project Components",
"view.components.name": "Components Navigation",
"view.debug.peripheral": "ESP-IDF: Peripheral Viewer",
"view.idf.espEFuseExplorer": "eFuseExplorer",
"view.idf.espRainmaker": "RainMaker",
Expand All @@ -176,6 +177,7 @@
"view.idf.idfCommands": "Commands",
"view.idf.idfPartitionExplorer": "Device Partition Explorer",
"view.idf.idfSearchResults": "Documentation search results",
"view.idf.espRegistryComponents": "ESP Registry Components",
"viewContainer.title": "ESP-IDF: Explorer",
"viewWelcome.idfPartitionExplorer": "Show the partition list from your device with the option to flash binaries (.bin) to the selected partition.\n\nSelect your device serial port and click Refresh Partition Table.",
"viewWelcome.idfSearchResults": "On any opened file editor, select some text and right click and select ESP-IDF: Search in Documentation to get matching results here.\n\nResults are based on your current VS Code language, idf.espIdfPath version (latest otherwise) and idf.adapterTargetName.",
Expand Down
4 changes: 3 additions & 1 deletion package.nls.pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"espIdf.unitTest.installPyTest.title": "Teste de unidade: instale os requisitos do ESP-IDF PyTest",
"espIdf.webview.nvsPartitionEditor.title": "Abra o Editor de Partição NVS",
"espIdf.welcome.title": "Bem-vindo",
"espIdf.espRegistryComponents.title": "Atualizar Componentes",
"esp_idf.appOffset.description": "Substituir o deslocamento do endereço inicial do programa de construção (ESP32_APP_FLASH_OFF)",
"esp_idf.debuggers.text.description": "O comando para executar",
"esp_idf.gdbinitFile.description": "caminho do arquivo gdbinit para adaptador de depuração ESP-IDF",
Expand Down Expand Up @@ -165,7 +166,7 @@
"trace.stop_tmo.description": "stop_tmo será definido para o apptrace",
"trace.trace_size.description": "trace_size será definido para o apptrace",
"trace.wait4halt.description": "wait4halt será definido para o apptrace",
"view.components.name": "Componentes do Projeto",
"view.components.name": "Navegação de Componentes",
"view.debug.peripheral": "ESP-IDF: visualizador periférico",
"view.idf.espEFuseExplorer": "eFuseExplorer",
"view.idf.espRainmaker": "Criador de Chuva",
Expand All @@ -174,6 +175,7 @@
"view.idf.idfCommands": "Comandos",
"view.idf.idfPartitionExplorer": "Explorador de partição de dispositivo",
"view.idf.idfSearchResults": "Resultados da pesquisa de documentação",
"view.idf.espRegistryComponents": "Componentes do Registro ESP",
"viewContainer.title": "ESP-IDF: Explorador",
"viewWelcome.idfPartitionExplorer": "Mostre a lista de partições do seu dispositivo com a opção de atualizar binários (.bin) para a partição selecionada.\n\n",
"viewWelcome.idfSearchResults": "Em qualquer editor de arquivo aberto, selecione algum texto e clique com o botão direito e selecione ESP-IDF: Pesquise na documentação para obter resultados correspondentes aqui.\n\n",
Expand Down
4 changes: 3 additions & 1 deletion package.nls.ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"espIdf.unitTest.installPyTest.title": "Модульное тестирование: установите требования ESP-IDF PyTest.",
"espIdf.webview.nvsPartitionEditor.title": "Откройте редактор разделов NVS.",
"espIdf.welcome.title": "Добро пожаловать",
"espIdf.espRegistryComponents.title": "Обновить Компоненты",
"esp_idf.appOffset.description": "Переопределить смещение начального адреса программы сборки (ESP32_APP_FLASH_OFF)",
"esp_idf.debuggers.text.description": "Команда для выполнения",
"esp_idf.gdbinitFile.description": "Путь к файлу gdbinit для адаптера отладки ESP-IDF",
Expand Down Expand Up @@ -167,7 +168,7 @@
"trace.stop_tmo.description": "stop_tmo будет установлен для apptrace",
"trace.trace_size.description": "Trace_size будет установлен для трассировки приложения.",
"trace.wait4halt.description": "wait4halt будет установлен для apptrace",
"view.components.name": "Компоненты проекта",
"view.components.name": "Навигация по компонентам",
"view.debug.peripheral": "ESP-IDF: Периферийное средство просмотра",
"view.idf.espEFuseExplorer": "eFuseExplorer",
"view.idf.espRainmaker": "RainMaker",
Expand All @@ -176,6 +177,7 @@
"view.idf.idfCommands": "Команды",
"view.idf.idfPartitionExplorer": "Обозреватель разделов устройства",
"view.idf.idfSearchResults": "Результаты поиска документации",
"view.idf.espRegistryComponents": "Компоненты реестра ESP",
"viewContainer.title": "ESP-IDF: Проводник",
"viewWelcome.idfPartitionExplorer": "Покажите список разделов вашего устройства с возможностью записать двоичные файлы (.bin) в выбранный раздел.\n\n",
"viewWelcome.idfSearchResults": "В любом открытом редакторе файлов выделите текст, щелкните правой кнопкой мыши и выберите ESP-IDF: поиск в документации, чтобы получить соответствующие результаты здесь.\n\n",
Expand Down
4 changes: 3 additions & 1 deletion package.nls.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"espIdf.unitTest.installPyTest.title": "单元测试:安装 ESP-IDF PyTest 要求",
"espIdf.webview.nvsPartitionEditor.title": "打开 NVS 分区编辑器",
"espIdf.welcome.title": "欢迎",
"espIdf.espRegistryComponents.title": "刷新组件",
"esp_idf.appOffset.description": "覆盖构建程序起始地址偏移 (ESP32_APP_FLASH_OFF)",
"esp_idf.debuggers.text.description": "要执行的命令",
"esp_idf.gdbinitFile.description": "用于 ESP-IDF 调试适配器的 gdbinit 文件路径",
Expand Down Expand Up @@ -167,7 +168,7 @@
"trace.stop_tmo.description": "将为 apptrace 设置 stop_tmo",
"trace.trace_size.description": "将为 apptrace 设置 trace_size",
"trace.wait4halt.description": "将为 apptrace 设置 wait4halt",
"view.components.name": "项目组件",
"view.components.name": "组件导航",
"view.debug.peripheral": "ESP-IDF:外围设备查看器",
"view.idf.espEFuseExplorer": "eFuseExplorer",
"view.idf.espRainmaker": "RainMaker",
Expand All @@ -176,6 +177,7 @@
"view.idf.idfCommands": "命令",
"view.idf.idfPartitionExplorer": "设备分区资源管理器",
"view.idf.idfSearchResults": "文档搜索结果",
"view.idf.espRegistryComponents": "ESP 注册表组件",
"viewContainer.title": "ESP-IDF:资源管理器",
"viewWelcome.idfPartitionExplorer": "显示您的设备的分区列表,选择要将二进制文件 (.bin) 烧录到的分区。\n\n选择您的设备串行端口,然后单击刷新分区表。",
"viewWelcome.idfSearchResults": "在任何已打开的文件编辑器中,选择一些文本,右键单击并选择 ESP-IDF:在文档中搜索以在此处获取匹配的结果。\n\n结果基于您当前的 VS Code 语言、idf.espIdfPath 版本 (否则为最新版本) 和 idf.adapterTargetName。",
Expand Down
183 changes: 183 additions & 0 deletions src/espIdf/espRegistryComponents/tree/componentsTreeDataProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import * as vscode from "vscode";
import * as yaml from "js-yaml";
import * as path from "path";
import * as fs from "fs-extra";

export class Component extends vscode.TreeItem {
constructor(
public readonly label: string,
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
public readonly description?: string
) {
super(label, collapsibleState);
this.tooltip = `${this.label}${
this.description ? ` - ${this.description}` : ""
}`;
this.contextValue = "component"; // This will be used to show the delete command in context menu
}
}

export class ComponentsTreeDataProvider
implements vscode.TreeDataProvider<Component> {
private _onDidChangeTreeData: vscode.EventEmitter<
Component | undefined | null | void
> = new vscode.EventEmitter<Component | undefined | null | void>();
readonly onDidChangeTreeData: vscode.Event<
Component | undefined | null | void
> = this._onDidChangeTreeData.event;
private workspaceFolder?: vscode.Uri;

constructor(workspaceFolder: vscode.Uri | undefined) {
this.workspaceFolder = workspaceFolder;

// Watch the idf_component.yml file for changes
if (workspaceFolder) {
const idfComponentPath = vscode.Uri.joinPath(
this.workspaceFolder,
"main",
"idf_component.yml"
);
const watcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(idfComponentPath, "*")
);

watcher.onDidChange(() => this.refresh());
watcher.onDidCreate(() => this.refresh());
watcher.onDidDelete(() => this.refresh());
}
}

refresh(): void {
this._onDidChangeTreeData.fire(); // Trigger UI update for the tree
}

getTreeItem(element: Component): vscode.TreeItem {
return element;
}

getChildren(element?: Component): Thenable<Component[]> {
if (!this.workspaceFolder) {
vscode.window.showInformationMessage("No workspace folder is open");
return Promise.resolve([]);
}

const idfComponentPath = vscode.Uri.joinPath(
this.workspaceFolder,
"main",
"idf_component.yml"
);

return vscode.workspace.fs.stat(idfComponentPath).then(
() => {
if (!element) {
return this.getDependencies(idfComponentPath);
}
return Promise.resolve([]);
},
() => {
return Promise.resolve([
new Component(
"idf_component.yml not found",
vscode.TreeItemCollapsibleState.None,
"Create this file to define your component dependencies"
),
]);
}
);
}

private async getDependencies(fileUri: vscode.Uri): Promise<Component[]> {
try {
const fileContents = await vscode.workspace.fs.readFile(fileUri);
const data = yaml.load(fileContents.toString()) as any;

if (data && data.dependencies) {
return Object.entries(data.dependencies).map(
([dep, version]) =>
new Component(
`${dep}`,
vscode.TreeItemCollapsibleState.None,
`${version}`
)
);
} else {
return [
new Component(
"No dependencies found",
vscode.TreeItemCollapsibleState.None
),
];
}
} catch (err) {
vscode.window.showErrorMessage(
`Error reading idf_component.yml: ${(err as Error).message}`
);
return [
new Component(
"Error reading file",
vscode.TreeItemCollapsibleState.None
),
];
}
}

async deleteComponentFromYml(
componentName: string,
workspaceFolder: vscode.Uri
): Promise<void> {
const idfComponentPath = vscode.Uri.joinPath(
this.workspaceFolder || workspaceFolder,
"main",
"idf_component.yml"
);

try {
// Delete from idf_component.yml
const fileContents = await vscode.workspace.fs.readFile(idfComponentPath);
const data = yaml.load(fileContents.toString()) as any;

if (data && data.dependencies && data.dependencies[componentName]) {
delete data.dependencies[componentName];
const newContents = yaml.dump(data);
await vscode.workspace.fs.writeFile(
idfComponentPath,
Buffer.from(newContents)
);

// Delete the component folder
const managedComponentsPath = path.join(
workspaceFolder.fsPath,
"managed_components"
);
const componentFolderName = componentName.replace("/", "__");
const componentFolderPath = path.join(
managedComponentsPath,
componentFolderName
);

if (await fs.pathExists(componentFolderPath)) {
await fs.remove(componentFolderPath);
vscode.window.showInformationMessage(
`Deleted component "${componentName}" from path ${componentFolderPath}`
);
} else {
vscode.window.showWarningMessage(
`Component folder not found: ${componentFolderPath}`
);
}

this.refresh();
} else {
vscode.window.showWarningMessage(
`Component ${componentName} not found in idf_component.yml`
);
}
} catch (err) {
vscode.window.showErrorMessage(
`Error updating idf_component.yml or deleting component folder: ${
(err as Error).message
}`
);
}
}
}
Loading
Loading