[cfe-dev] clangd, completion in header files

Christian Dullweber via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 29 02:33:31 PDT 2018


Sound great, thanks!

One interesting case in Chromium might be generated jni headers. I would be
interested what the heuristic finds for these files:
src/out/Android/gen/chrome/browser/jni_headers/chrome/jni/
BrowsingDataBridge_jni.h

the implementation is in:
src/chrome/browser/android/browsing_data/browsing_data_bridge.cc
I don't think that will get matched.

I don't really care if code completion works in generated files but at
least there shouldn't be incorrect error messages in vscode. Is it possible
to exclude a folder from being analyzed by clangd?



On Thu, Mar 29, 2018 at 1:50 AM, Sam McCall <sammccall at google.com> wrote:

> 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/20180329/dd3877b9/attachment.html>


More information about the cfe-dev mailing list