Setup and use clangd LSP for C++ code intelligence in Unity. Ensures compile_commands.json is generated before using LSP tools on C++ files.
Before using any LSP tools (lsp_diagnostics, lsp_hover, lsp_definition,
lsp_references, lsp_symbols, lsp_completions) on C++ files, clangd
needs a compile_commands.json in the repo root.
Run the CompileCommands jam target to produce it. Use Strawberry Perl, not
Git Bash Perl:
"C:/Users/harald/scoop/apps/perl/current/perl/bin/perl.exe" jam.pl CompileCommands 2>&1 | tail -20
This only needs to be done once per session, or after build configuration
changes. If compile_commands.json already exists and is up to date, skip
this step.
test -f compile_commands.json && echo "compile_commands.json exists" || echo "MISSING — run jam CompileCommands"
Once compile_commands.json is present, clangd will start lazily on
the first LSP tool call targeting a C++ file. No manual server start is
needed.
Tools like lsp_hover, lsp_definition, lsp_symbols, and
lsp_references require the file to be synced to clangd first. Use read
on the file before calling these tools. lsp_diagnostics works without
this step since it operates at the workspace level.
Typical workflow:
read the C++ filelsp_hover, lsp_definition, lsp_symbols, etc. on it