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

Ilya Biryukov via clangd-dev clangd-dev at lists.llvm.org
Thu Jan 10 10:09:02 PST 2019

Hi Nathan,

clangd has an experimental option to automatically build an index for the
projects (i.e. the CDBs) of the files you're editing in the background and
load them on subsequent runs.
We hope this is going to become the default in the long-term, the idea is
that the index will into per-file chunks and those chunks will be loaded
when the files are accessed.
I believe it currently won't provide the definition locations, because they
would be in the chunks for the '.cpp' files and '.cpp' files are not
included by the users of the library.

However, if we figure out how to load this extra information for the
symbols from the headers chunks, we should be covered.
+Sam McCall <sammccall at google.com>, +Kadir Çetinkaya <kadircet at google.com>,
who are actually working on this, they might have ideas on how to do it

PS to try out the background index, build clangd from the latest head (it's
important to sync before building, a change that loads the index has landed
today) and run clangd with '-background-index' flag.

On Thu, Jan 10, 2019 at 9:12 AM Nathan Ridge via clangd-dev <
clangd-dev at lists.llvm.org> wrote:

> 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
> _______________________________________________
> clangd-dev mailing list
> clangd-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev

Ilya Biryukov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/clangd-dev/attachments/20190110/b27e60a9/attachment-0001.html>

More information about the clangd-dev mailing list