[cfe-dev] libclang's code completion APIs give unexpected results for Objective-C

Michael Bolin bolinfest at gmail.com
Thu Apr 24 10:35:45 PDT 2014


In case anyone else runs into this issue, this Stack Overflow post has a
lot of helpful information:
http://stackoverflow.com/questions/15875800/why-isnt-libclang-returning-meaningful-completion-results
.

In short, the line/column information that you pass should point to the
start of the token, and it is the caller's responsibility to filter by the
partially complete token.

Also, clang has a flag (-code-completion-at) that makes it convenient to
test this API without writing any code; however, it only appears to work
with -cc1, not with -ObjC.


On Wed, Apr 23, 2014 at 5:13 PM, Michael Bolin <bolinfest at gmail.com> wrote:

> Here I have a very small .m file where I have typed "NSL" and would expect
> the top code completion suggestion to be "NSLog()":
>
> https://gist.github.com/bolinfest/11236613
>
> Here is my C code that calls libclang and uses it to get suggested code
> completions:
>
> https://gist.github.com/bolinfest/11236626
>
> Here are the suggestions I get when I run my C code (the command that I
> ran is `./main.o Hello.m 5 6`):
>
> https://gist.github.com/bolinfest/11236652
>
> Some surprising results:
>
> (1) libclang gives me over 5000 suggestions.
> (2) NSLog() is in the list, but its priority is 50. There are all sorts of
> other suggestions that seem less relevant, but have a lower priority
> (counterintuitively, this means higher probability of being clicked on:
> http://clang.llvm.org/doxygen/group__CINDEX__CODE__COMPLET.html#ga46e843acdf63d9a7a0c7341a2d222c49).
> Search for "priority=40" in the gist to see examples of results with a
> lower priority that seem less relevant.
> (3) The order in which things appear in the results appears to be random.
> I see that clang has a convenience function to sort results alphabetically,
> but not by priority.
>
> Are there additional arguments that I need to pass to libclang to tune
> things so that the results I get from clang_codeCompleteAt() are more in
> line with what I expect?
>
> Thank you,
> Michael
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140424/d9350a5d/attachment.html>


More information about the cfe-dev mailing list