Using a remote index

Usually clangd will build an index of your project in the background. For large projects, this can be slow.

If someone has set up a clangd index server for your project, then you can query this central index instead of building your own.

Obtaining a suitable version of clangd

You need a remote-index-enabled version (12 or later) of clangd, such as the latest clangd release on github.

The official LLVM releases and Debian etc packages of clangd 12 are not remote-index-enabled!

(If building clangd from source, you need -DCLANGD_ENABLE_REMOTE=On in CMake).

Configuring clangd to use the remote index

You’ll need the address of the server you want to connect to, and the local source code it matches.

In your user configuration, add a section like:

  PathMatch: /path/to/code/.*
    Server: someserver:5900
    MountPoint: /path/to/code/

What to expect

After restarting clangd, it should no longer want to index your whole project, and you should get complete results for find-references etc.

Results may not be entirely up-to-date. Index servers usually scan the project once a day, and if you’re working on a branch you may get further skew. Files that you’ve had open will still be indexed locally and will be up-to-date.

Queries to the index server may reveal information about the code you’re editing (e.g. partial identifiers). Public servers should have a privacy policy.

Public index servers

Some open-source projects have public servers:

Running up an index server

This is a little more involved, and you’ll want to understand the design of the remote index. In short:

The clangd-indexer and clangd-index-server tools can be found in on the release page.

clangd/llvm-remote-index is an example of a production-ready instance, with the indexing step running on GitHub Actions and the server running on Google Compute Engine.