From: Adrian Freihofer <[email protected]> Add "[cpp]"/"[c]" defaultFormatter and editor.formatOnSave settings pointing at the clangd VSCode extension, so devtool ide-sdk-generated workspaces auto-format on save using the recipe's own .clang-format style.
Only enabled when clangd is the active IntelliSense engine (IDE_SDK_INTELLISENSE == "clangd", which also gates whether the clangd extension is recommended/installed) and a .clang-format file exists in the recipe source tree, so gcc/cpptools recipes and recipes without a .clang-format are unaffected. Signed-off-by: Adrian Freihofer <[email protected]> --- scripts/lib/devtool/ide_plugins/ide_code.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/lib/devtool/ide_plugins/ide_code.py b/scripts/lib/devtool/ide_plugins/ide_code.py index 8a8ab8bf3d..f8036f15de 100644 --- a/scripts/lib/devtool/ide_plugins/ide_code.py +++ b/scripts/lib/devtool/ide_plugins/ide_code.py @@ -248,6 +248,19 @@ class IdeVSCode(IdeBase): # Avoid cpptools (if also installed) fighting clangd over IntelliSense. settings_dict["C_Cpp.intelliSenseEngine"] = "disabled" + def __vscode_settings_format(self, settings_dict, modified_recipe): + # clangd is the only formatter wired up here, so only enable it when + # clangd is actually the active IntelliSense engine (its extension is + # recommended/available). + if not (modified_recipe.ide_sdk_intellisense == 'clangd' and modified_recipe.build_tool.is_c_cpp): + return + # Respect the project's own formatting style only if it opted in. + if not os.path.isfile(os.path.join(modified_recipe.real_srctree, '.clang-format')): + return + settings_dict["[cpp]"] = {"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"} + settings_dict["[c]"] = {"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"} + settings_dict["editor.formatOnSave"] = True + def vscode_settings(self, modified_recipe, image_recipe): files_hide = { "**/.git/**": True, @@ -282,6 +295,7 @@ class IdeVSCode(IdeBase): self.__vscode_settings_meson(settings_dict, modified_recipe) self.__vscode_settings_kernel_module(settings_dict, modified_recipe) self.__vscode_settings_clangd(settings_dict, modified_recipe) + self.__vscode_settings_format(settings_dict, modified_recipe) settings_file = 'settings.json' IdeBase.update_json_file( -- 2.55.0
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#245504): https://lists.openembedded.org/g/openembedded-core/message/245504 Mute This Topic: https://lists.openembedded.org/mt/121171400/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
