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

Sam McCall via clangd-dev clangd-dev at lists.llvm.org
Fri Jan 11 02:52:33 PST 2019


On Fri, Jan 11, 2019 at 1:06 AM Nathan Ridge via clangd-dev <
clangd-dev at lists.llvm.org> wrote:

> Thanks for the info! I was aware of the auto-index functionality, but
> didn't know that it already supported multiple CDBs.
>
> > Then if you've just files open from source/bar directory in your clangd
> instance,
> > it won't become aware of the other compilation database that lies in
> libfoo and
> > only give you declaration for Multiply, but if you open any source file
> under
> > source/libfoo (not necessarily libfoo/foo.cpp itself) clangd will be
> able to index
> > that directory as well and start giving you definition location for
> Multiply as well.
> > (You also need to #include "foo.h" in foo.cpp but I assume that was
> unintentional.)
> >
> > Does that sound good?
>
> It sounds very good!
>
Caveats here: how the auto-index behaves with multiple CDBs hasn't been
heavily tested yet, and I think there are likely bugs.
What Ilya describes is the behavior that naturally fell out of the design
(given that a clangd instance supports multiple CDBs, which aren't known
up-front).
The index works by building a whole TU at once (using a command from the
main-file's CDB), and then partitioning the symbols according to the files
they appear in. We probably accidentally assumed that each partition is
then associated with the TU's CDB, which may cause some problems (if
leaf/leaf.cc and lib/lib.cc and both include lib/lib.h, then we'll end up
indexing lib.h in both the leaf/ and lib/ projects).


> Out of curiosity, though - if a client wanted to send all the CDBs
> upfront, to avoid the requirement that you have to open a file from each
> project, would that be a reasonable capability to add?
>
That seems doable. The way this currently works is:
 - A CDB is "discovered" the first time we try to get the command for a
file under its directory
 - once a CDB is "discovered", the auto-index loads any index shards that
exist for the CDB, and starts indexing files that don't have an up-to-date
shard
So we could add a custom command or a startup option to make clangd
discover particular CDBs (e.g. by looking for a compile command for
dir/dummy.txt, and then throwing it away).


>
> Thanks,
> Nate
> _______________________________________________
> clangd-dev mailing list
> clangd-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/clangd-dev/attachments/20190111/cc9fa44a/attachment.html>


More information about the clangd-dev mailing list