[cfe-dev] clangd, completion in header files

Sam McCall via cfe-dev cfe-dev at lists.llvm.org
Wed Mar 28 16:50:32 PDT 2018


Looks like our mail crossed :)
Cquery's success with this is another point in favor.

I have a prototype in https://reviews.llvm.org/D45006 (+ 2-line patch to
enable in clangd: https://reviews.llvm.org/D45007).
It seems to work pretty well at first glance, but it needs rigorous
testing. If anyone's feeling this pain, feel free to try it out!

It does a little bit of indexing to avoid traversing all the entries every
time, not sure if that's worth it.

On Wed, Mar 28, 2018 at 9:58 PM Fāng-ruì Sòng via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Another heuristic solution:
>
> Enumerate all compilation database entries and calculate the matching
> score for each entry with the target file
> Bonus for common leading components
> Penalty for diverged path components
> Bonus for common trailing characters sans filename extension (e.g.
> Match.cc Match.h are the same sans extension)
>
> This heuristic is used in cquery.
>
> Add another point for textDocument/didOpen on an unseen filename:
> The inferred command line options are not authoritative, they should be
> overriden by other translation units when later it turns out the header
> file is included by some entry in the compilation database.
>
>
> On Wed, Mar 28, 2018 at 7:12 AM 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
>>
>
>
> --
> 宋方睿
> _______________________________________________
> 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/8ab62e2c/attachment.html>


More information about the cfe-dev mailing list