[clangd-dev] Multi-project workflow via multiple CDBs

Nathan Ridge via clangd-dev clangd-dev at lists.llvm.org
Tue Jan 8 16:04:46 PST 2019


Hi clangd-dev,

Suppose you are working on a codebase that involves multiple projects: for example, an application and one or more libraries it depends on. The projects may live in distinct repositories, have distinct build systems, and therefore produce distinct compilation database files; yet, it may be useful to treat the set of projects as a single codebase for editing purposes.

Specifically, it would be useful to have a way for clangd to index a set of such projects together and cross-reference them as a single codebase.

To give a concrete example, consider the following toy repository:

https://github.com/simark/clangd-multi-project-test

It consists of a library called "libfoo" and an application "bar" which uses the library. For ease of demonstration they are together in the same repository, but they are built separately and produce separate compilation database files. There is a "setup.sh" script to easily configure and build them both.

To be specific about what I mean by cross-referencing them as a single codebase: we would like to be able to set up clangd in such a way that:

* "Go to definition" on the use of Multiply() in bar.cpp takes you to the definition in foo.cpp (not the declaration in foo.h)
* Searching for references of Multiply() in foo.cpp finds the usage in bar.cpp

We also have a suggestion for how clangd could support such a setup:

* Clangd could be modified to accept multiple compilation database files, either at startup time via command line flags, or in the "initialize" request, or both.
* When given multiple compilation database files, clangd would merge them into a single compilation database, and then proceed as if it had been given the merged database.

Any feedback on either the described use case, or the suggested solution, would be appreciated!

Thanks,
Nate


More information about the clangd-dev mailing list