All of lore.kernel.org
 help / color / mirror / Atom feed
From: AdrianF <adrian.freihofer@siemens.com>
To: openembedded-core@lists.openembedded.org
Cc: Adrian Freihofer <adrian.freihofer@siemens.com>
Subject: [PATCH 10/15] devtool: ide-sdk: add clangd support for VSCode IntelliSense
Date: Wed,  9 Sep 2026 23:53:10 +0200	[thread overview]
Message-ID: <20260909215337.89106-11-adrian.freihofer@siemens.com> (raw)
In-Reply-To: <20260909215337.89106-1-adrian.freihofer@siemens.com>

From: Adrian Freihofer <adrian.freihofer@siemens.com>

Add an llvm-vs-code-extensions.vscode-clangd based IntelliSense provider
as an alternative to cpptools for ide=code. clangd is matched to the
recipe's real cross compiler via compile_commands.json and --query-driver,
which works for gcc cross-compilers as well as clang. As a fisrst step
clangd is supported if TOOLCHAIN is clang.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 scripts/lib/devtool/ide_plugins/ide_code.py | 41 ++++++++++++++++++---
 scripts/lib/devtool/ide_sdk.py              |  2 +
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/scripts/lib/devtool/ide_plugins/ide_code.py b/scripts/lib/devtool/ide_plugins/ide_code.py
index 7c700f258e..acf3db7494 100644
--- a/scripts/lib/devtool/ide_plugins/ide_code.py
+++ b/scripts/lib/devtool/ide_plugins/ide_code.py
@@ -228,6 +228,26 @@ class IdeVSCode(IdeBase):
             }
         ]
 
+    def __vscode_settings_clangd(self, settings_dict, modified_recipe):
+        if not (modified_recipe.ide_sdk_intellisense == 'clangd' and modified_recipe.build_tool.is_c_cpp):
+            return
+        # Use the recipe's real cross compiler (gcc or clang, whichever TOOLCHAIN
+        # actually builds it), not a hardcoded 'clang'/'clang++' name.
+        cross_cc = os.path.join(modified_recipe.staging_bindir_toolchain, modified_recipe.cc.split()[0])
+        cross_cxx = os.path.join(modified_recipe.staging_bindir_toolchain, modified_recipe.cxx.split()[0])
+        settings_dict["clangd.path"] = os.path.join(
+            modified_recipe.recipe_sysroot_native, 'usr', 'bin', 'clangd')
+        settings_dict["clangd.arguments"] = [
+            # Allow-list the cross compiler so clangd queries it (not its own
+            # bundled clang) for target-specific builtin includes/defines.
+            # Works for gcc cross-compilers too, not just clang.
+            "--query-driver=%s,%s" % (cross_cc, cross_cxx),
+            "--compile-commands-dir=%s" % modified_recipe.b,
+            "--background-index"
+        ]
+        # Avoid cpptools (if also installed) fighting clangd over IntelliSense.
+        settings_dict["C_Cpp.intelliSenseEngine"] = "disabled"
+
     def vscode_settings(self, modified_recipe, image_recipe):
         files_hide = {
             "**/.git/**": True,
@@ -261,6 +281,7 @@ class IdeVSCode(IdeBase):
         self.__vscode_settings_cmake(settings_dict, modified_recipe)
         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)
 
         settings_file = 'settings.json'
         IdeBase.update_json_file(
@@ -268,16 +289,22 @@ class IdeVSCode(IdeBase):
 
     def vscode_extensions(self, modified_recipe):
         recommendations = []
-        if modified_recipe.build_tool.is_c_cpp_kernel:
+        # clangd (matched to the recipe's real cross compiler via
+        # compile_commands.json) replaces cpptools as the IntelliSense provider
+        # if toolchain is clang. CodeLLDB/GDB debugging is unaffected either way.
+        use_clangd = (modified_recipe.ide_sdk_intellisense == 'clangd'
+                      and modified_recipe.build_tool.is_c_cpp)
+        if use_clangd:
+            recommendations += [
+                "llvm-vs-code-extensions.vscode-clangd",
+                "vadimcn.vscode-lldb"
+            ]
+        elif modified_recipe.build_tool.is_c_cpp_kernel:
             recommendations += [
                 "ms-vscode.cpptools",
                 "ms-vscode.cpptools-extension-pack",
                 "ms-vscode.cpptools-themes"
             ]
-        # For clang toolchain, CodeLLDB provides native LLDB debugging in VSCode
-        if (modified_recipe.toolchain == 'clang'
-                and modified_recipe.build_tool.is_c_cpp):
-            recommendations.append("vadimcn.vscode-lldb")
         if modified_recipe.build_tool is BuildTool.CMAKE:
             recommendations.append("ms-vscode.cmake-tools")
         if modified_recipe.build_tool is BuildTool.MESON:
@@ -290,6 +317,10 @@ class IdeVSCode(IdeBase):
             self.dot_code_dir(modified_recipe), extensions_file, {"recommendations": recommendations})
 
     def vscode_c_cpp_properties(self, modified_recipe, image_recipe):
+        # cpptools' IntelliSense is disabled in settings.json when clangd is
+        # the active provider, so this file would be inert clutter.
+        if modified_recipe.build_tool.is_c_cpp and modified_recipe.ide_sdk_intellisense == 'clangd':
+            return
         properties_dict = {
             "name": modified_recipe.recipe_id_pretty,
         }
diff --git a/scripts/lib/devtool/ide_sdk.py b/scripts/lib/devtool/ide_sdk.py
index ba9d4adff1..a3fbe7cdcb 100755
--- a/scripts/lib/devtool/ide_sdk.py
+++ b/scripts/lib/devtool/ide_sdk.py
@@ -789,6 +789,7 @@ class RecipeModified:
         self.target_arch = None
         self.tmpdir = None
         self.toolchain = None
+        self.ide_sdk_intellisense = None
         self.topdir = None
         self.workdir = None
         # Maps each package name (from PACKAGES) to the glob patterns from its FILES variable
@@ -884,6 +885,7 @@ class RecipeModified:
         self.target_arch = recipe_d.getVar('TARGET_ARCH')
         self.tmpdir = os.path.realpath(recipe_d.getVar('TMPDIR'))
         self.toolchain = recipe_d.getVar('TOOLCHAIN')
+        self.ide_sdk_intellisense = 'clangd' if self.toolchain == 'clang' else 'cpptools'
         self.topdir = recipe_d.getVar('TOPDIR')
         self.workdir = os.path.realpath(recipe_d.getVar('WORKDIR'))
 
-- 
2.55.0



  parent reply	other threads:[~2026-09-09 21:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 21:53 [PATCH 00/15] devtool ide-sdk: support booting from NFS, VSCode clangd AdrianF
2026-09-09 21:53 ` [PATCH 01/15] devtool: deploy: split ssh deployment into a separate function AdrianF
2026-09-09 21:53 ` [PATCH 02/15] devtool: deploy: allow deploying directly into a local rootfs directory AdrianF
2026-09-09 21:53 ` [PATCH 03/15] oe-selftest: devtool deploy-target: test deploying into a local rootfs path AdrianF
2026-09-09 21:53 ` [PATCH 04/15] devtool: ide-sdk: support NFS rootfs AdrianF
2026-09-09 21:53 ` [PATCH 05/15] oe-selftest: devtool ide-sdk: test NFS debug rootfs AdrianF
2026-09-09 21:53 ` [PATCH 06/15] runqemu-extract-sdk: refactor in Python AdrianF
2026-09-10 17:45   ` [OE-core] " Richard Purdie
2026-09-09 21:53 ` [PATCH 07/15] devtool: ide-sdk: reuse pseudo_rootfs_utils for SDK rootfs extraction AdrianF
2026-09-09 21:53 ` [PATCH 08/15] cpp-example: update formatting and code style AdrianF
2026-09-09 21:53 ` [PATCH 09/15] cpp-example: fix clang-tidy warnings AdrianF
2026-09-09 21:53 ` AdrianF [this message]
2026-09-09 21:53 ` [PATCH 11/15] devtool: ide-sdk: support clangd for non-clang toolchain recipes AdrianF
2026-09-09 21:53 ` [PATCH 12/15] devtool: ide-sdk: format C/C++ with clangd when .clang-format is present AdrianF
2026-09-09 21:53 ` [PATCH 13/15] devtool: ide-sdk: support LLDB ATTACH mode AdrianF
2026-09-09 21:53 ` [PATCH 14/15] devtool: ide-sdk: pin BBPATH in generated do_install script AdrianF
2026-09-09 21:53 ` [PATCH 15/15] buildstats: close proc/disk log files via weakref.finalize safety net AdrianF

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260909215337.89106-11-adrian.freihofer@siemens.com \
    --to=adrian.freihofer@siemens.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.