Clangd-index-server generated files mapping

Hi everyone!

I’m trying to set up a remote index for an extremely large project (over 35M lines of C/C++ code) but I’m having troubles with queries involving generated files. The problem is, generated files are placed in some user-specified directory possibly outside project’s root, and clangd-index-server has no way of mapping them for the client to be able to find locally. As a consequence, the server logs error E[11:30:17.791] Unable to convert Ref to protobuf: File path '/path/to/generated/code/subproject/genfile.h' doesn't start with '/path/to/project/'. and the response is missing references to generated code.

My config.yaml looks like this:

  PathMatch: /home/user/path/to/userproject/subproject/.*
    MountPoint: /home/user/path/to/userproject/subproject/

Is there any workaround for this setup?

As it usually happens, found the answer by myself. Hope it’ll be helpfull for the community. clangd has the --path-mappings option, which, together with properly placed symbolic link, does the trick. The setup is:

  • remote index server:
    • usual code root: /path/to/project
    • generated code root: /path/to/project/.generated
  • developer workstation:
    • usual code root: /home/dev/project
    • generated code root: /tmp/dev/generated
    • magic symlink: /home/dev/project/.generated/tmp/dev/generated
    • additional clangd options: --path-mappings=/tmp/dev/generated=/home/dev/project/.generated