Tip of the day: Almost every channel mode can be disabled. Don't like halfops? Use blacklist-module chanmodes/halfop;
|
Dev:Visual Studio Code
This article explains how to configure Visual Studio Code for UnrealIRCd (C) development. In particular, how to get automatic code formatting on save, using the same formatting rules as the project itself.
UnrealIRCd uses clang-format for code formatting, with the rules stored in the .clang-format file in the source.
You can always format the code by running make format.
Pull requests containing unformatted code will be rejected by the CI. The configuration below makes Visual Studio Code do the formatting automatically every time you save, so you never have to think about it.
Install the clangd extension
Open the Extensions sidebar (Ctrl+Shift+X) and search for clangd (the one published by LLVM, id llvm-vs-code-extensions.vscode-clangd).
If you develop on a remote machine through SSH (the Remote - SSH extension), make sure to install clangd on the remote side: the install button should say Install in SSH: yourhost.
If the extension offers to download a clangd binary for you, decline, and instead install clangd through your OS package manager. On Ubuntu 26.04 that is simply:
$ sudo apt-get install clangd
This is important because the clang-format version matters: different versions format slightly differently. UnrealIRCd currently uses clang-format version 21, so your clangd should be major version 21 as well: this is what Ubuntu 26.04 ships. On older distributions you can get version 21 from apt.llvm.org (the same source the UnrealIRCd CI uses). You can check your version with:
$ clangd --version Ubuntu clangd version 21.1.8 (6ubuntu1)
Enable format on save
Press Ctrl+Shift+P, choose Preferences: Open User Settings (JSON) and add this inside the top-level { } object (careful: if you accidentally paste it outside the outer braces then it is silently ignored):
"[c]": {
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
"editor.formatOnSave": true
}
Test it
Open any .c file, paste something sloppy like:
int my_sloppy_test( int a,int b ){if(a>b)return a;return b;}
...and press Ctrl+S. It should instantly be reformatted to proper style (spaces around operators, brace on its own line, and so on). Then undo your test change.
Troubleshooting
If saving does nothing, or Format Document complains "There is no formatter for 'c' files installed" even though you installed the clangd extension: clangd has probably crashed earlier in your session. Press Ctrl+Shift+P and run clangd: Restart language server, or simply restart Visual Studio Code. Only start reinstalling or reconfiguring things if a restart did not help.
Notes
- In the end,
make formatis what decides how properly formatted code looks. The CI runs the same check viamake format-check, no matter what your editor did or did not do. - Formatting on save is always safe: the entire source tree is kept in exactly the state that clang-format produces, so formatting a file that you did not edit changes nothing.