This documents a working setup to hack on FreeCAD using the Zed editor, clangd, and CMake on Arch Linux.
It focuses on four pieces:
- A reproducible build configuration (
conf.sh,build.sh) - A
compile_commands.jsonflow that keeps clangd happy - Local clangd/clang-tidy noise control (
.clangd) - File locations and symlinks that make everything line up
- Arch Linux (or derivative) with:
base-devel,cmake,ninja,gitclang,clang-tools-extra(forclangd/clang-tidy)- FreeCAD build dependencies as per the FreeCAD wiki / Developers Handbook
- Zed editor
- A FreeCAD source checkout
Example layout:
$HOME/source/git/FreeCAD # FreeCAD git clone
$HOME/source/git/FreeCAD-build # (optional) out-of-tree build dir
This gist assumes an in-tree build/zed-relwithdebinfo directory inside the FreeCAD repo:
FreeCAD/
build/
zed-relwithdebinfo/
compile_commands.json
Location: FreeCAD/.zed/
Contains Zed-specific development helpers:
conf.sh- Configures CMake build directory withCMAKE_EXPORT_COMPILE_COMMANDS=ON.build.sh- Convenience wrapper to rebuild with Ninja.tasks.json- Zed tasks (optional, for reference).settings.json- Zed settings (optional, for reference).
These files are automatically excluded from git by FreeCAD's .gitignore .* pattern.
Location: FreeCAD/.clangd (at repo root)
Per-checkout clangd configuration file that:
- Points clangd at the correct compilation database if needed
(for example ifcompile_commands.jsonlives only in the build dir). - Tunes diagnostics and clang-tidy checks to reduce noise while keeping important issues.
Also excluded by FreeCAD's .gitignore .* pattern (intended to be local-only).
Example .clangd (to adapt):
CompileFlags:
# If you do NOT symlink compile_commands.json to the repo root,
# uncomment the following to point clangd at the build dir explicitly.
# CompilationDatabase: build/zed-relwithdebinfo
Diagnostics:
# Example: tone down some clang-tidy noise while keeping important diagnostics.
Suppress:
- 'clang-tidy:readability-isolate-declaration'
- 'clang-tidy:readability-else-after-return'
- 'clang-tidy:cppcoreguidelines-avoid-magic-numbers'
- 'clang-tidy:cppcoreguidelines-narrowing-conversions'
ClangTidy:
# Let clangd pick up the project's .clang-tidy, but we can explicitly
# remove or add checks here if needed.
Add: []
Remove: []clangd will automatically look for compile_commands.json starting at the directory of the file you open and walking up parent directories.
Two common approaches:
-
Symlink to the build dir (simple and explicit):
cd $HOME/source/git/FreeCAD ln -sf build/zed-relwithdebinfo/compile_commands.json .
With this, clangd sees
compile_commands.jsonat the repo root and you usually don't needCompilationDatabasein.clangd. -
Use
CompilationDatabasein.clangd:If you don't like the symlink, keep
compile_commands.jsononly underbuild/zed-relwithdebinfoand set:CompileFlags: CompilationDatabase: build/zed-relwithdebinfo
This gist does not contain Zed config files, but it assumes:
- Zed is using system
clangd. - The FreeCAD repo root is opened as the project in Zed.
- Diagnostics severity is tuned to your preference (e.g. only errors/warnings) via Zed's settings.
Typical project layout with all pieces in place:
$HOME/source/git/FreeCAD/
.zed/
conf.sh # from PKGBUILD
build.sh # from this gist
tasks.json # VS Code reference (optional)
settings.json # VS Code reference (optional)
.clangd # local-only clangd config (untracked)
compile_commands.json # symlink to build/zed-relwithdebinfo/compile_commands.json
build/
zed-relwithdebinfo/
compile_commands.json
src/
...
With this:
conf.shprepares the build directory and compilation database.build.shkeeps rebuilds one command away.compile_commands.json+.clangdensure clangd (and thus Zed's C++ LSP) uses the same flags/includes as your real FreeCAD build.- You can further customize
.clangdto suppress or tweak clang-tidy diagnostics without changing the upstream FreeCAD configuration.