Skip to content

C++

C++ support is built in and shares everything with C: clangd for the language server, clang-format for formatting, and CodeLLDB or GDB for debugging.

Tyrn uses clangd from your PATH if it finds one, and downloads one otherwise.

Compile commands

clangd needs a compile_commands.json. With CMake:

Terminal window
cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

Put it, or a symlink to it, at the project root, or leave it in build. See C.

Configure clangd

Pass arguments, or change the binary:

settings.json
{
"lsp": {
"clangd": {
"binary": {
"path": "/path/to/clangd",
"arguments": ["--function-arg-placeholders=0", "--background-index"]
}
}
}
}

More server options live in a .clangd file in your project:

.clangd
CompileFlags:
Add:
- "--include-directory=/path/to/include"

Formatting

Add a .clang-format file to your project. Format with cmd-shift-i. To format on save:

settings.json
{
"languages": {
"C++": { "format_on_save": "on", "tab_size": 2 }
}
}

Source and header

Switch between a source file and its header with the editor: switch source header action. It has no default key. See C.

Debugging

.tyrn/debug.json
[
{
"label": "Debug native binary",
"adapter": "CodeLLDB",
"request": "launch",
"program": "./build/prog",
"build": { "command": "make", "args": ["-j8"] }
}
]

See Debugger.