clangd: add compilation database configuration
diff mbox series

Message ID 20260509210758.F3F7F1EA006C@mailuser.phl.internal
State New
Headers show
Series
  • clangd: add compilation database configuration
Related show

Commit Message

Javier Tia May 9, 2026, 9:06 p.m. UTC
Without this, clangd cannot find build-generated headers such as
build/src/libcamera/tracepoints.h and build/config.h, causing spurious
diagnostics for any file that includes them.

build/ is the project-canonical build directory, already listed in
.gitignore and used in the contributing documentation. Developers using
a custom build directory can place a local .clangd override; if build/
is absent, clangd falls back to its normal heuristics with no regression.

Signed-off-by: Javier Tia <floss@jetm.me>
---
 .clangd | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 .clangd

Comments

Barnabás Pőcze May 9, 2026, 11:35 p.m. UTC | #1
Hi

2026. 05. 09. 23:06 keltezéssel, Javier Tia írta:
> Without this, clangd cannot find build-generated headers such as
> build/src/libcamera/tracepoints.h and build/config.h, causing spurious
> diagnostics for any file that includes them.
> 
> build/ is the project-canonical build directory, already listed in
> .gitignore and used in the contributing documentation. Developers using
> a custom build directory can place a local .clangd override; if build/
> is absent, clangd falls back to its normal heuristics with no regression.
> 
> Signed-off-by: Javier Tia <floss@jetm.me>
> ---
>   .clangd | 2 ++
>   1 file changed, 2 insertions(+)
>   create mode 100644 .clangd
> 
> diff --git a/.clangd b/.clangd
> new file mode 100644
> index 00000000..e95990a8
> --- /dev/null
> +++ b/.clangd
> @@ -0,0 +1,2 @@
> +CompileFlags:
> +  CompilationDatabase: build/

Isn't this the default? I've been using clangd for years and it
has always recognized `build/compile_commands.json`.

https://clangd.llvm.org/installation#compile_commandsjson says

```
clangd will look in the parent directories of the files you edit looking for it,
and also in subdirectories named build/. For example, if editing $SRC/gui/window.cpp,
we search in $SRC/gui/, $SRC/gui/build/, $SRC/, $SRC/build/, …
```

Based on the above this change should not be necessary. Do you maybe have
something in your top-level clangd config?


Regards,
Barnabás Pőcze

> --
> Javier Tia
Javier Tia May 10, 2026, 2:23 a.m. UTC | #2
Hi Barnabás,

On 2026-05-09 Barnabás Pőcze wrote:
> Isn't this the default? I've been using clangd for years and it
> has always recognized `build/compile_commands.json`.
[...]
> Based on the above this change should not be necessary. Do you maybe
> have something in your top-level clangd config?

You're right. I checked and have no ~/.config/clangd/config.yaml or
any other override, and the documentation you quoted matches the
default discovery behavior. The patch is redundant - please drop it.

Thanks for the catch.

Patch
diff mbox series

diff --git a/.clangd b/.clangd
new file mode 100644
index 00000000..e95990a8
--- /dev/null
+++ b/.clangd
@@ -0,0 +1,2 @@ 
+CompileFlags:
+  CompilationDatabase: build/