You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clangd LSP set incorrect root and missing arguments #11617
Currently clangd root directory is detected by NearestRoot(["compile_commands.json", "compile_flags.txt", ".clangd", "CMakeLists.txt", "Makefile"]), which is usually result in the up directory which contains "CMakeLists.txt" or "Makefile" of active file, and is not the root directory of project. Instead, clangd should run in the root directory.
clangd will search from active file directory up to root directory to find .clangd or compile_flags.txt. We do not need to do the search again in LSPServer.
compile_commands.json is important to clangd, clangd will look in the parent directories of active file looking for it, and also in subdirectories named "build/". But it usually fails if one build project out of source tree. Argument of clangd (--compile-commands-dir) can be used to pass the location.
Not sure if you are using Windows, if so, you might need to ensure opencode is using the clangd that you expect it to use. For me OpenCode by default will attempt to download and use its own clangd but I need to make it use MSYS2's clangd, thus custom configuration needed. See #7405 (comment) for example configuration.
Not sure if you are using Windows, if so, you might need to ensure opencode is using the clangd that you expect it to use. For me OpenCode by default will attempt to download and use its own clangd but I need to make it use MSYS2's clangd, thus custom configuration needed. See #7405 (comment) for example configuration.
I'm working MacOS and Linux. I have already submitted a patch (#11579), but the PR was ignored. So I gave up.
I agree with this issue. In most Make and CMake projects, Makefile and CMakeLists.txt do not indicate the project root — they exist in countless subdirectories throughout the tree.
llvm-project (https://github.com/llvm/llvm-project) is good example. llvm-project has CMakeLists.txt in every single subdirectory like clang/lib/Sema/, clang/lib/AST/, clang/lib/CodeGen/, etc. Opening any file there causes clangd to start in the wrong directory.
These markers should be removed from the clangd root detection. Only compile_commands.json, compile_flags.txt, and .clangd reliably indicate where clangd should run.
If I'm not mistaken, NearestRoot is excluding parent folders, so even if the compile_commands.json file was in ros_ws/compile_commands.json, it wouldn't find it. It would be nice if we could configure the build directory explicitly. It would also be helpful to add a note to https://opencode.ai/docs/lsp#how-it-works which talks about the location of compile commands, or how to configure the build directory for clangd.
I believe this is how we do it now, but making this explicit in the documentation would help.
Activity
github-actions commentedon Feb 1, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
BLumia commentedon Apr 2, 2026
Not sure if you are using Windows, if so, you might need to ensure opencode is using the
clangdthat you expect it to use. For me OpenCode by default will attempt to download and use its own clangd but I need to make it use MSYS2's clangd, thus custom configuration needed. See #7405 (comment) for example configuration.wangzw commentedon Apr 7, 2026
I'm working MacOS and Linux. I have already submitted a patch (#11579), but the PR was ignored. So I gave up.
nonbanana commentedon Apr 8, 2026
I agree with this issue. In most Make and CMake projects, Makefile and CMakeLists.txt do not indicate the project root — they exist in countless subdirectories throughout the tree.
llvm-project (https://github.com/llvm/llvm-project) is good example. llvm-project has CMakeLists.txt in every single subdirectory like clang/lib/Sema/, clang/lib/AST/, clang/lib/CodeGen/, etc. Opening any file there causes clangd to start in the wrong directory.
These markers should be removed from the clangd root detection. Only compile_commands.json, compile_flags.txt, and .clangd reliably indicate where clangd should run.
AadityaRavindran commentedon Apr 23, 2026
For ROS c++ projects, the build directory is not in the src directory. The folder structure is
If I'm not mistaken,
NearestRootis excluding parent folders, so even if the compile_commands.json file was inros_ws/compile_commands.json, it wouldn't find it. It would be nice if we could configure the build directory explicitly. It would also be helpful to add a note to https://opencode.ai/docs/lsp#how-it-works which talks about the location of compile commands, or how to configure the build directory for clangd.I believe this is how we do it now, but making this explicit in the documentation would help.