[clangd-dev] Clangd Path Mappings for Docker Container

William Wagner via clangd-dev clangd-dev at lists.llvm.org
Tue Jan 8 11:58:21 PST 2019


I’ve been using clangd for developing a C++ project at work. Our
development setup requires that we build and run our code inside a docker
container. From a language server perspective this presents a few

   1. Communicating with the language server running in the container
   2. Synchronizing the files between the host and the container
   3. Translating file paths between the host lsp client  and docker lsp
   4. Having dependency files that are only in the container available to
   view on the host (for textDocument/definition on dependencies installed
   only in the container)

Fortunately, docker’s facilities make 1) and 2) pretty easy to deal with.

1) can be solved by creating a bash script that contains something similar
`docker exec -i <build_container> /path/to/clangd ${@:1}`
and pointing clangd.path to this script

2) can be solved by using a docker bind mount, which maps the directory of
the project you’re working on into the container

3) can be solved by mounting the host:/path/to/project to an identical path
in the container. Then there doesn't have to be any translation between the
requests/responses between the file uris that the client and server send
back and forth. However, this may not always be possible and still leaves
the problem of external dependency paths.

4) has no easy solution yet afaik. A potentially simple one would be to
copy just the dependency headers from the container over to some directory
on the host, and be able to translate clangd response file uris to the
appropriate path on the host. The way I envision that is an extra arg to
the clangd server that supports path substitution, such as:


So if I “Go To Definition” on an external symbol e.g. Foo, which is defined
in /container/deps/foo.hh”, and I have the foo.hh header in
/host/home/project/.deps/foo.hh, then the response from the servers
textDocument/definition would substitute the /container/deps/foo.hh →
/host/home/project/.deps/foo.hh and all would be well.

I believe sourcegraph has implemented an extension to the LSP to handle
missing files on the client/server, but I cannot find the proposed spec.
Also these are some github discussions that touch on the topics above:

   - Ccls supports a path Mappings config option that allows substitution,
   see https://github.com/MaskRay/ccls/issues/75
   - Discussion on remote langauge server proposal

I’d be happy to implement this path mapping functionality, but thought it’d
be prudent to see what everyone else thinks before doing so.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/clangd-dev/attachments/20190108/0a12d8bb/attachment.html>

More information about the clangd-dev mailing list