diff --git a/platform.json b/platform.json index e615c96ac..ab514f19e 100644 --- a/platform.json +++ b/platform.json @@ -135,6 +135,13 @@ "package-version": "2.20.1", "version": "https://github.com/pioarduino/registry/releases/download/0.0.1/cppcheck-v2.20.1.zip" }, + "tool-clangd-esp": { + "type": "tool", + "optional": true, + "owner": "pioarduino", + "package-version": "21.1.3+20260304", + "version": "https://github.com/pioarduino/registry/releases/download/0.0.1/clangd-esp-21.1.3_20260304.zip" + }, "tool-clangtidy": { "type": "tool", "optional": true, diff --git a/platform.py b/platform.py index 6b63614e1..05b78d02d 100644 --- a/platform.py +++ b/platform.py @@ -797,6 +797,19 @@ def _configure_check_tools(self, variables: Dict) -> None: if any(tool in package for tool in check_tools): self.install_tool(package) + def _configure_clangd_tool(self) -> None: + """Install Espressif's clangd when the IDE has clangd IntelliSense enabled. + + The pioarduino IDE extension exports PLATFORMIO_IDE_INTELLISENSE_ENGINE + so the platform can automatically install the matching tool package. + Espressif's clangd has native Xtensa and ESP RISC-V support that the + upstream clangd lacks. + """ + engine = os.environ.get("PLATFORMIO_IDE_INTELLISENSE_ENGINE", "").strip().lower() + if engine == "clangd" and "tool-clangd-esp" in self.packages: + logger.info("clangd IntelliSense engine detected, installing tool-clangd-esp") + self.install_tool("tool-clangd-esp") + def _handle_dfuutil_tool(self, variables: Dict) -> None: """Install dfuutil tool for Arduino Nano ESP32 board.""" board_config = self.board_config(variables.get("board")) @@ -851,6 +864,7 @@ def configure_default_packages(self, variables: Dict, targets: List[str]) -> Any self._configure_rom_elfs_for_exception_decoder(variables) self._configure_check_tools(variables) + self._configure_clangd_tool() self._handle_dfuutil_tool(variables) logger.info("Package configuration completed successfully")