Clangd LSP set incorrect root and missing arguments #8223

Open
opened 2026-02-16 18:09:27 -05:00 by yindo · 1 comment
Owner

Originally created by @wangzw on GitHub (Feb 1, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

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.

So all we need to do:

  1. set root directory of the project correctly.
  2. pass compile_commands.json using argument.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @wangzw on GitHub (Feb 1, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description 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. So all we need to do: 1. set root directory of the project correctly. 2. pass `compile_commands.json` using argument. ### Plugins _No response_ ### OpenCode version _No response_ ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 18:09:27 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 1, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9521: clangd LSP always fails - reports bogus STL include errors when projects provide compile_commands.json via symlink
  • #7780: [FEATURE]: LSP support for choosing between multiple build directories (c++ / clangd) - discusses the need to configure build directory for clangd, similar to passing compile_commands.json location

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 1, 2026): This issue might be a duplicate of existing issues. Please check: - #9521: clangd LSP always fails - reports bogus STL include errors when projects provide compile_commands.json via symlink - #7780: [FEATURE]: LSP support for choosing between multiple build directories (c++ / clangd) - discusses the need to configure build directory for clangd, similar to passing compile_commands.json location Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8223