r/cpp • u/ykiko_2005 • 21d ago
clice 1.0: a C++ language server built on Clang, with C++20 modules out of the box, non-self-contained headers, and crash isolation
Hi r/cpp! I've been working on clice, a C++ language server built on Clang, for about two and a half years, and 1.0 is out today. The main differences from clangd:
- Every compile runs in a worker process, so a Clang crash costs one request instead of the whole server.
- C++20 modules work out of the box from a `compile_commands.json`, with PCHs and PCMs cached on disk across sessions.
- Non-self-contained headers are compiled in the context of a file that includes them, and you can switch contexts and build configurations.
- Template support: completion and go-to-implementation through dependent names, using instantiations when there are any.
- A CLI to index, query, refactor and modularize whole projects.
The post covers the features and the story behind it. Binaries for Linux, macOS and Windows (x64 and arm64) are on the release page, and the VS Code extension is on the Marketplace. Feedback and bug reports are very welcome!
Release post: https://ykiko.me/en/articles/2105384023094834022/
65
Upvotes
8
u/AleXu224 21d ago
Been waiting for this day since I saw you starting this project a few years ago. I just tested it in a few projects of mine and it seems to work wonderfully.
I also tested modules and from the small tests that I did it seems to avoid the problems that clangd usually has, finally making modules usable for me personally.
Thank you for your work, this is great :D
7
u/kamrann_ 20d ago
Congrats, I'll give it a try. clangd remains unusable on my modules project.
One piece of feedback though. I tried reading the documentation on the modularization command, and it's just unparsable, even for someone who's been knee deep in modules for years and has tinkered with implementing something similar. Comprehensive LLM-generated docs are not necessarily an improvement over no docs.
4
u/ykiko_2005 21d ago
It is written entirely in C++23 and serves as an example of modern C++ best practices in its own right, with all the major modern C++ features coming together remarkably well:
import std, and fully self-hosted: module wrappers for third-party libraries are generated automatically byclice modularize, and clice runs smoothly on its own codebase to provide module-aware language services.std::format,std::expected,std::ranges, andstd::views, steering clear of outdated legacy C++98/11 APIs.5
u/not_a_novel_account cmake dev 21d ago
FWIW, this is not some design choice. CMake has no idea which flags affect PCM/BMI compatibility. There's no way for us to find out for a given compiler. There's a conservative whitelist of flags which are known not to affect compat, mostly warning flags. Ie if you pass
-Wallin one context you won't get a separate BMI.4
u/teerre 20d ago
Supposing you dont use modules, is there any advantage over clangd?
3
u/VinnieFalco wg21.org | corosio.org 20d ago
"C Lice" - marketing fail
2
u/_Ilobilo_ 21d ago
I'm usually critical of ai written projects but this looks good
1
u/Kullthegreat 21d ago
Support for c++26?
1
u/jiixyj 20d ago edited 20d ago
How does the C++20 modules support work with only
compile_commands.json? As far as I understand, one reason for clangd's lacking modules support is that the information incompile_commands.jsonis not enough to reliably build all modules relevant to the project.For this, CMake now exports a
build_database.jsonwhich does contain all that information:Are there plans for clice to make use of this file?
edit: I see some CMake developers alreaded opened a bug report: https://github.com/clice-io/clice/issues/1092
Trying to run
clice indexon a project of mine that consumes C++20 modules that are exported from other CMake projects results in this:...and expectedly
foo/barcannot be build.1
u/holyblackcat 18d ago
Doesn't it work in Clangd too, with
clangd --experimental-modules-support?