How to enable remote indexer?

According to this doc, I should be able to get a suitable build of clangd to use a remote index server using the --remote-index-address and --project-root flags. I tried that, and sure enough I do get “Connecting to remote index at localhost:50051” in the log (see here). But no connection attempt is actually made; clangd just goes ahead and builds a local index itself, from the compile_commands.json. For simplicity, to prove the “no connection attempted” thing, I just ran a netcat process with netcat -vv -l -p 50051 rather than actually running an index server.

See the README for details of how I built clangd, and the full verbose log.

Is there something else I need to do, to get clangd to talk to the remote index server?

My platform is Debian 11.3, VSCode 1.71.2, clangd extension 0.1.23, clangd built from source at the 15.0.3 release tag.

Chris

I think your setup is correct.

clangd just goes ahead and builds a local index itself, from the compile_commands.json

What are you basing this on? Local index data is written to <project>/.cache/clangd/index. Are you seeing that populated with files?

(If you’re basing it on the logs, “indexed preamble AST” refers to something else. That’s an in-memory “dynamic” index that clangd builds for opened files only, which it overlays the on-disk (or remote) index, such that modifications made to open files are represented correctly even if the underlying index isn’t up to date with them.)

But no connection attempt is actually made

The log is a bit confusing in that the connection attempt isn’t made at the time the “Connecting to remote index…" message is logged, but rather lazily when information from the index is actually needed.

If you try performing an operation that uses the index, such as workspace/symbol or code completion, do you now see a connection attempt?

As @HighCommander4 pointed out, I don’t think you actually have background-index triggering in your case, there’s only a log saying “Enqueueing 1 commands for indexing”, which means clangd might attempt to index that file. Unfortunately we don’t know in advance whether that file is covered by a remote-index instance or not.

Later on before attempting to index, we actually check for that, and in your case it’s discovered successfully, there are no log lines in the form Indexing {0} (digest:={1}). Hence clangd actually didn’t index that file.

If you try any action that requires index, code completion, go-to-def, workspace/symbols, hover (pretty much anything that requires an explicit trigger). You should see a log line that looks like Associating {0} with remote index at {1}. That means remote-index is being used for that particular file. The logs you’ve attached unfortunately doesn’t have usage of any feature that queries index.