<div dir="ltr"><div>What you want to do is possible (we do something very similar), though isn't quite working out-of-the-box yet.<br></div><div>There's two main parts:</div><div> - <b>Building and distributing an index</b> is pretty easy: run clangd-indexer and copy the file to each machine.[1]</div><div> - <b>Translating filenames in the index to match those on the machine</b> is what the URIs Eric mentioned are for, and isn't polished.</div><div> The idea is clangd-indexer will see a file in /path/a/project/Foo.cc, and clangd (on another machine) will see it in a different /path/b/project/Foo.cc.</div><div>   So it's the indexer's job to translate the path into a machine-agnostic URI like myproject:///Foo.cc, and then clangd's job is to work out which concrete file that refers to in the current context. The clangd::URIScheme implementations handle this at both ends.</div><div>   However open-source clangd only has the file scheme today, people need to patch it to handle these cases[2].</div><div><br></div><div>-- design speculation follows --</div><div>I think we should ship a generic "project-relative" URI scheme with clangd so this can work.</div><div><br></div><div>One idea I have is a scheme like project://somebasedir/path/file.cc</div><div>Here the assumption is that the project is rooted under a directory with a fixed name "somebasedir" recorded in the URI authority.</div><div> - URI -> path is easy: find the concrete somebasedir based on the currently edited file, and concatenate.</div><div> - path -> URI is tricky: we need to determine which (if any) parent directory is the relevant base.</div><div>    - A flag makes sense for clangd-indexer, but clangd also needs to do this conversion sometimes and a flag is a burden there.</div><div>    - Maybe we can get away with just keeping track of the authorities we've seen the external index return? But this doesn't really help for background index, and mixed internal/external index cases could get messy.</div><div>    - looking for compilation databases is tempting too, but complicated (requires IO in the URI scheme, and we have ways to use clangd with an external CDB, and the CDB interfaces aren't quite right for this today)</div><div>So I don't see a way to do this that's super-clean (cheap, zero-config, correct) but interested in ideas others have.</div><div><br></div><div>Obviously this has the weakness that indexes only transfer between projects where the root has the same name, not sure how big a problem this would be in practice.</div><div><br></div><div>[1] There are certainly fancier variations: for google's index we distribute the index building by running Index/IndexAction in a mapreduce, and also run the index as an RPC server and use a custom implementation of SymbolIndex that queries it. The latter means our developers have to use a patched clangd. Building the index file and copying it is a good place to start, you'll see where the scaling limits are.</div><div><br></div><div>[2] Ours is pretty simple, as the project is always rooted at a directory with a fixed name.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 3, 2019 at 10:38 AM Eric Liu via clangd-dev <<a href="mailto:clangd-dev@lists.llvm.org">clangd-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Just to add on what Ilya said.<div><br></div><div>> Note that both indexes store absolute paths, so sharing the produced index across multiple machines would only be possible if the directory structure is kept the same.</div><div>> If having the same directory structure is plausible, please try it out and let us know if it works, we haven't tried sharing the same index across multiple machines.</div><div>Paths are stored as URI in the index. By default, "file" scheme is used, so URI would simply be absolute path (e.g. file:///user/home/llvm/x/y.h). But you could also define your own URI schemes. For example, you can choose to store relative paths in the URI (e.g. llvm:///x/y.h) in a custom scheme, and they can be resolved with potentially different project roots on users' machines to get correct full paths. For more information, please take a look at clangd/URI.h library. You could also find some sample URIScheme implementations in unit tests.</div><div><br></div><div>Cheers,</div><div>Eric</div><br class="gmail-m_-9026172865775791970gmail-Apple-interchange-newline"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 3, 2019 at 10:27 AM Ilya Biryukov via clangd-dev <<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi William,<div><br></div><div>The difference between background-indexer and clangd-indexer is the layout of the output:</div><div>- background-indexer would put the resulting index into the folder <project-root>/.clangd/index.</div><div>  The index is split per-file, i.e. it's incremental and clangd would be able to update the files that changed after the index was built.</div><div>  You would need to run clangd with '-background-index' to load the index, it will also automatically update the index for files that changed on load.</div><div>- clangd-indexer would produce a <b>merged </b>index, it can't be incrementally updated and you have more control for the location of the output:</div><div>  ./bin/clangd-indexer -executor=all-TUs path/to/compile_commands.json > path/to/output.riff<br></div><div>  You would need to run clangd with '-index-file=path/to/output.riff' to load the index.</div><div><br></div><div>Note that both indexes store absolute paths, so sharing the produced index across multiple machines would only be possible if the directory structure is kept the same.</div><div>If having the same directory structure is plausible, please try it out and let us know if it works, we haven't tried sharing the same index across multiple machines.</div><div><br></div><div>Which option to prefer? Depending on your situation, either of the two might be better:</div><div>- If you always want an up-to-date index and storing the shared snapshot is just a performance optimization, use background-indexer.</div><div>- If you not wasting resources to rebuild the index for changed files is more important than the fact that some results are stale (e.g. it's too expensive, you want to save laptop battery, etc.), clangd-indexer might be a better choice.</div><div><br></div><div>Here's a short summary on what each index means:</div><div>- Static index is an index that is persisted across multiple runs of clangd. There are two flavours of it:</div><div>  1. Background index. Incremental (split per-file) index living in '<project-root>/.clangd/index'.  Built automatically by clangd when -background-index is specified. Long-term, we want this to be enabled by default (and possibly be the only option).</div><div>  2. Old-style "merged" index produced by clangd-indexer. The results will not get updated by clangd automatically, you can ask clangd to load it with '-index-file=path/to/index.riff'. </div><div>- Dynamic index is an overlay for a small number of updated files (currently the open files for which we built the AST). Kept in memory, not persisted across multiple runs. We use to adjust for the fact that static index might be stale. We want the correct results for the open files in all cases.</div><div>- Dex is an efficient implementation of running search queries (e.g. it models fuzzy-matching algorithm, etc.). It's an "index" in an information retrieval sense, it is not actually specific to C++ or clangd.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 1, 2019 at 6:36 PM William Wagner (BLOOMBERG/ 731 LEX) via clangd-dev <<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="gmail-m_-9026172865775791970gmail-m_-4105990047554174080gmail-m_-9189427934623238491rte-style-maintainer gmail-m_-9026172865775791970gmail-m_-4105990047554174080gmail-m_-9189427934623238491rte-pre-wrap" style="font-family:Arial,"BB.Proportional";white-space:pre-wrap;font-size:small"><div>Hello!</div><div><br></div><div>I work on a fairly large C++ project and wanted to figure out a way to regularly build (e.g. nightly via Jenkins) a global project index that can be shared with all the members of my team. I want to share it because it takes a fairly long time to build the index after starting up, and it seems pretty redundant to have each team member doing so, seeing as most of the code is not changing on a day-to-day basis. I’ve tried peeking around the mailing lists and commit history of clangd, but I’m not sure whether this is possible yet - and if it was, what flags to use, what indexer etc.</div><br><div>I see there’s background-indexer WIP (<a href="https://reviews.llvm.org/D59605" target="_blank"><span>https://reviews.llvm.org/D59605</span></a>) and an existing clangd-indexer <a href="https://github.com/llvm-mirror/clang-tools-extra/blob/master/clangd/indexer/IndexerMain.cpp" target="_blank"><span>https://github.com/llvm-mirror/clang-tools-extra/blob/master/clangd/indexer/IndexerMain.cpp</span></a></div><div>What is the difference between these?</div><br><div>Additionally, if anyone could provide some clarification on the different types of indexes clangd currently has (dex, background, static, etc.) that would be great :)</div><br><div>Thanks!</div><div><br></div></div></div>_______________________________________________<br>
clangd-dev mailing list<br>
<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-9026172865775791970gmail-m_-4105990047554174080gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div>
_______________________________________________<br>
clangd-dev mailing list<br>
<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev</a><br>
</blockquote></div>
_______________________________________________<br>
clangd-dev mailing list<br>
<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev</a><br>
</blockquote></div>