clice v1.0 Released: Welcome to Modern C++
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
clice v1.0 Released: Welcome to Modern C++
Table of Contents What is clice? Language Server Command Line The story behind it Why not improve clangd? How did we get here? What about agents? To be continued clice recently hit 1,000 commits, a special milestone for the project. Since July 19, 2026, clice has been shipping nightly builds and going through roughly four months of alpha testing, with a huge number of bugs fixed thanks to real-world feedback from early users. Over the same stretch, I built a rigorous testing system for clice and ran extensive tests across many real open-source projects, tracking down and fixing the issues they uncovered. What does that mean? Every core feature is now stable, and you rarely run into problems in day-to-day use. So I think the time is right to ship the first stable release. The project looks very different today from where it stood two years ago in Design and Implementation of a New C++ Language Server, and this is probably the first time I’m promoting it widely, so please let me introduce it to you once again! This is the project I have poured the past two and a half years into, the work I am proudest of, the one that has excited me the most and left me sad and anxious more times than I can count, and the most ambitious thing I have taken on in my short life.
目录:什么是 clice?语言服务器、命令行、背后的故事、为什么不改进 clangd?我们是如何走到这一步的?代理又如何?未完待续。clice 最近完成了 1000 次提交,这是该项目的一个特殊里程碑。自 2026 年 7 月 19 日以来,clice 一直在发布每日构建版本,并经历了大约四个月的 Alpha 测试,得益于早期用户的真实反馈,大量错误得到了修复。在此期间,我为 clice 构建了一套严格的测试系统,并在许多真实的开源项目上进行了广泛测试,追踪并修复了它们所发现的问题。这意味着什么?现在每一个核心功能都已经稳定,日常使用中几乎不会遇到问题。所以我认为发布第一个稳定版本的时候到了。与两年前《新 C++ 语言服务器的设计与实现》中的状态相比,该项目如今已大不相同,这可能是我第一次广泛推广它,所以请允许我再次向大家介绍它!这是我过去两年半倾注心血的项目,是我最引以为傲的作品,也是最让我兴奋、让我无数次感到悲伤和焦虑,以及我短暂一生中承担过的最雄心勃勃的事情。
What is clice?# In short, clice is a C/C++ language server written in modern C++, but it’s more than just a language server. It is still built on LLVM/Clang, but unlike clangd and ccls, which are also Clang-based, clice was redesigned from the ground up to fix architectural problems that have gone unsolved in those servers for years. 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: Written entirely with C++20 coroutines, using our own libuv-based structured-concurrency async library for intricate asynchronous logic. It is a complex concurrent program running an event loop on the main thread while coordinating both multiple processes (IPC) and multiple threads. Written entirely with C++20 named modules and C++23 import std, and fully self-hosted: module wrappers for third-party libraries are generated automatically by clice modularize, and clice runs smoothly on its own codebase to provide module-aware language services. Uses static reflection built on templates and C++20 concepts for all serialization and deserialization across formats, including TOML, JSON, bincode, blob, and command-line arguments, with Rust-macro-like declarative annotations and zero boilerplate. Data-oriented code design throughout, with almost no virtual functions outside the callback interfaces Clang requires. Makes heavy use of modern C++ APIs like std::format, std::expected, std::ranges, and std::views, steering clear of outdated legacy C++98/11 APIs. A completely hermetic, reproducible build powered by Bazel, compiled with the unified xclang toolchain for a consistent cross-platform cross-compilation workflow. Compiled binaries are heavily optimized (PGO + LTO), and build artifacts depend on nothing beyond system libraries. People are always debating whether modern C++ features like modules are actually ready for real work. clice’s answer is: yes, of course, completely usable! They hold up for complex software like clice, with hundreds of thousands of lines of code. Maybe this is what the modern C++ we have been hoping for looks like. That said, the surrounding ecosystem really is inconvenient enough right now that getting this whole workflow running end to end took a huge amount of effort on my part to track issues and adapt everything.
什么是 clice?简而言之,clice 是一个用现代 C++ 编写的 C/C++ 语言服务器,但它不仅仅是一个语言服务器。它仍然构建在 LLVM/Clang 之上,但与同样基于 Clang 的 clangd 和 ccls 不同,clice 是从零开始重新设计的,旨在解决这些服务器多年来未解决的架构问题。它完全用 C++23 编写,本身就是现代 C++ 最佳实践的典范,所有主要的现代 C++ 特性都结合得非常出色:完全使用 C++20 协程编写,使用我们自己基于 libuv 的结构化并发异步库来处理复杂的异步逻辑。它是一个复杂的并发程序,在主线程上运行事件循环,同时协调多个进程(IPC)和多个线程。完全使用 C++20 命名模块和 C++23 import std 编写,并完全自托管:第三方库的模块包装器由 clice modularize 自动生成,clice 在其自身代码库上运行顺畅,以提供感知模块的语言服务。使用基于模板和 C++20 Concepts 构建的静态反射,用于跨格式的所有序列化和反序列化,包括 TOML、JSON、bincode、blob 和命令行参数,具有类似 Rust 宏的声明式注解且零样板代码。全程采用面向数据的代码设计,除了 Clang 要求的回调接口外,几乎没有虚函数。大量使用 std::format、std::expected、std::ranges 和 std::views 等现代 C++ API,避开了过时的 C++98/11 旧 API。由 Bazel 提供支持的完全封闭、可重复的构建,使用统一的 xclang 工具链编译,以实现一致的跨平台交叉编译工作流。编译后的二进制文件经过深度优化(PGO + LTO),构建产物不依赖于系统库之外的任何东西。人们总是在争论模块等现代 C++ 特性是否真的为实际工作做好了准备。clice 的回答是:是的,当然,完全可用!它们经受住了像 clice 这样拥有数十万行代码的复杂软件的考验。也许这就是我们一直期待的现代 C++ 的样子。话虽如此,目前的周边生态系统确实还不够方便,以至于我花费了巨大的努力来追踪问题并适配所有内容,才使整个工作流端到端地运行起来。
Language Server# Here is an overview of clice’s main features: Multi-process compilation: clice compiles code in a process pool modeled after modern web browsers, whereas clangd uses multithreading. Why multiple processes? Because C++ is simply too complex, and on certain corner cases the compiler can easily crash or leak memory. That is especially true for incomplete code in the middle of editing: a huge downstream user base tests compilers on complete code, while very few people test them on half-written code, where the compiler mostly falls back on best-effort heuristics. In clangd, a compiler crash takes down the whole server and forces a restart. In clice, compilation happens in isolated child processes: losing one worker does not affect the rest of the server, so go-to-definition, highlighting, and other services keep working. It also makes it much easier to manage memory usage and schedule compilation priorities, cutting down on unnecessary resource consumption. Modules and shared caching: clice has full support for C++20 named modules. All you need is a compile_commands.json containing all module files, and clice scans dependencies on its own and lazily builds required modules on demand, regardless of your build system or compiler, with full support for module completion, highlighting, go-to-definition, hover, and more. Built PCHs and PCMs are also cached on local disk for reuse across sessions. By comparison, clangd offers only very limited module support and no persistent cache. Compilation context: clice has full support for non-self-contained files, and more generally for the concept of a compilation context. You can explicitly pick the active context of a file: a specific compile command for a source file, or a specific inclusion site for a header. When you open a non-self-contained file, clice detects its context automatically, so it works out of the box. More broadly, it also supports grouping compile commands into build configurations, letting you switch between, say, debug and release. Better template support: clice implements a DFS pseudo instantiator that infers what many dependent names resolve to without needing concrete template arguments for a full instantiation. When a template has been instantiated once, clice also draws on that instantiation to power language features, such a
语言服务器:以下是 clice 主要功能的概述:多进程编译:clice 模仿现代网络浏览器,在进程池中编译代码,而 clangd 使用多线程。为什么要使用多进程?因为 C++ 实在太复杂了,在某些极端情况下,编译器很容易崩溃或内存泄漏。对于编辑过程中不完整的代码尤其如此:庞大的下游用户群在完整代码上测试编译器,而很少有人在半成品代码上进行测试,此时编译器大多只能退回到尽力而为的启发式方法。在 clangd 中,编译器崩溃会导致整个服务器宕机并强制重启。而在 clice 中,编译发生在隔离的子进程中:丢失一个工作进程不会影响服务器的其他部分,因此转到定义、高亮显示和其他服务可以继续工作。这也使得管理内存使用和调度编译优先级变得更加容易,减少了不必要的资源消耗。模块和共享缓存:clice 完全支持 C++20 命名模块。你只需要一个包含所有模块文件的 compile_commands.json,clice 就会自行扫描依赖项,并根据需要按需延迟构建所需的模块,无论你的构建系统或编译器是什么,它都完全支持模块补全、高亮显示、转到定义、悬停提示等功能。构建好的 PCH 和 PCM 也会缓存在本地磁盘上,以便在会话间重用。相比之下,clangd 仅提供非常有限的模块支持,且没有持久化缓存。编译上下文:clice 完全支持非自包含文件,更广泛地支持编译上下文的概念。你可以显式选择文件的活动上下文:源文件的特定编译命令,或头文件的特定包含位置。当你打开一个非自包含文件时,clice 会自动检测其上下文,因此它可以开箱即用。更广泛地说,它还支持将编译命令分组为构建配置,让你可以在例如调试和发布模式之间切换。更好的模板支持:clice 实现了一个深度优先搜索(DFS)伪实例化器,它可以在不需要具体模板参数进行完全实例化的情况下,推断出许多依赖名称的解析结果。当一个模板被实例化一次后,clice 还会利用该实例化结果来驱动语言功能,例如……