[cfe-dev] clangd, completion in header files

Sam McCall via cfe-dev cfe-dev at lists.llvm.org
Wed Mar 28 11:43:37 PDT 2018


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).


I'm playing with heuristics; and have a rough tool to validate them.
This seems to work pretty well:
- 2 points if basenames match (without extension). 1 point for substrings,
in either direction.
- 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"
- break ties by longest common prefix

I've been testing using the LLVM codebase, which has some tricky cases.
(nontrivial directory layout, lots of headers without matching cc files)

Out of ~3000 headers (i.e. any file transitively #included) in my llvm
checkout, working accuracy seems to be extremely good:
PERFECT (~2200): we pick a TU that transitively included the header. (When
there's a corresponding cc file, it's usually that on.)
GOOD (~650): we pick a TU whose args "obviously" work (it contains every
arg that was defined by *every* transitively including TU)
MAYBE_BAD (150):
 - about half of these are *.def and *.inc which I haven't studied, they're
not relevant to clangd
 - most of the remainder are false alarms: the flags are fine, but my
heuristic can't tell
 - 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).

On Wed, Mar 28, 2018 at 4:12 PM Christian Dullweber via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi,
>
> I recently tried to use clangd for Chromium in vscode and hit the same
> issue.
> I experimented a bit with generating a compile_commands.json file with
> valid rules for headers and came to this solution:
> https://gist.github.com/xchrdw/bfd2b3a5f765f4195a55d6351daf1b48
> I sorted all .cc filenames and then looked up the index of the closest
> match for each header 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.
> I found a few issues with system headers and some generated protobuf
> headers but otherwise it works well.
>
Native support from clangd would be amazing :)
>
> Thanks,
> Christian
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180328/802f912d/attachment.html>


More information about the cfe-dev mailing list