<div dir="ltr"><div>Are there any interesting codebases I should be trying this stuff out on? Ideally - builds on linux without too much fuss, uses cmake and generates compile_commands.json. Preferably not incredibly huge (though I will try chromium).</div><div><br></div><div><br></div>I'm playing with heuristics; and have a rough tool to validate them.<div>This seems to work pretty well:</div><div>- 2 points if basenames match (without extension). 1 point for substrings, in either direction.</div><div>- for /a/b/c/d/foo.h, 1 point each for "/c/" and "/d/" in the candidate path, and 1 point if it starts with "/a/b"</div><div>- break ties by longest common prefix</div><div><br></div><div><div>I've been testing using the LLVM codebase, which has some tricky cases. (nontrivial directory layout, lots of headers without matching cc files)</div></div><div><br></div><div>Out of ~3000 headers (i.e. any file transitively #included) in my llvm checkout, working accuracy seems to be extremely good:</div><div>PERFECT (~2200): we pick a TU that transitively included the header. (When there's a corresponding cc file, it's usually that on.)</div><div>GOOD (~650): we pick a TU whose args "obviously" work (it contains every arg that was defined by *every* transitively including TU)</div><div>MAYBE_BAD (150):</div><div> - about half of these are *.def and *.inc which I haven't studied, they're not relevant to clangd</div><div> - most of the remainder are false alarms: the flags are fine, but my heuristic can't tell</div><div> - I haven't found any that would give wrong results, though some results are confused (clang/Parse/ParseDiagnostic.h gets associated with clang/lib/Basic/Diagnostic.cpp rather than e.g. clang/lib/Parse/ParseAST.cpp).</div><div><br></div><div><div class="gmail_quote"><div dir="ltr">On Wed, Mar 28, 2018 at 4:12 PM Christian Dullweber via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-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">Hi,<div><br></div><div>I recently tried to use clangd for Chromium in vscode and hit the same issue. </div><div>I experimented a bit with generating a compile_commands.json file with valid rules for headers and came to this solution: <a href="https://gist.github.com/xchrdw/bfd2b3a5f765f4195a55d6351daf1b48" target="_blank">https://gist.github.com/xchrdw/bfd2b3a5f765f4195a55d6351daf1b48</a></div><div>I sorted all .cc filenames and then looked up the index of the closest match<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>for each header </span>using binary search. As there were some edge cases like the first or last file in a directory, I additionally compared which file at the index has the largest prefix with the header.</div><div>I found a few issues with system headers and some generated protobuf headers but otherwise it works well. </div></div></blockquote><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>Native support from clangd would be amazing :)</div><div><br></div><div>Thanks,</div><div>Christian</div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div></div>