<div dir="ltr">Clarification: I misunderstood what -cc1 meant (<a href="http://stackoverflow.com/questions/8991662/can-u-tell-me-what-does-the-clang-cc1-option-do">http://stackoverflow.com/questions/8991662/can-u-tell-me-what-does-the-clang-cc1-option-do</a> cleared that up).<div>
<br></div><div>The following is a convenient way to test out the code completion API without writing any code:</div><div><br></div><div>clang -cc1 -fsyntax-only -code-completion-at=PATH_TO_M_FILE:LINE:COL PATH_TO_M_FILE</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 24, 2014 at 10:35 AM, Michael Bolin <span dir="ltr"><<a href="mailto:bolinfest@gmail.com" target="_blank">bolinfest@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In case anyone else runs into this issue, this Stack Overflow post has a lot of helpful information: <a href="http://stackoverflow.com/questions/15875800/why-isnt-libclang-returning-meaningful-completion-results" target="_blank">http://stackoverflow.com/questions/15875800/why-isnt-libclang-returning-meaningful-completion-results</a>.<div>

<br></div><div>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.</div><div><br></div><div>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.</div>

</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 23, 2014 at 5:13 PM, Michael Bolin <span dir="ltr"><<a href="mailto:bolinfest@gmail.com" target="_blank">bolinfest@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Here I have a very small .m file where I have typed "NSL" and would expect the top code completion suggestion to be "NSLog()":<div>

<br></div><div><a href="https://gist.github.com/bolinfest/11236613" target="_blank">https://gist.github.com/bolinfest/11236613</a><br>
</div><div><br></div><div>Here is my C code that calls libclang and uses it to get suggested code completions:</div><div><br></div><div><a href="https://gist.github.com/bolinfest/11236626" target="_blank">https://gist.github.com/bolinfest/11236626</a><br>


</div><div><br></div><div>Here are the suggestions I get when I run my C code (the command that I ran is `<span style="color:rgb(102,102,102);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:19.600000381469727px">./main.o Hello.m 5 6`)</span>:</div>


<div><br></div><div><a href="https://gist.github.com/bolinfest/11236652" target="_blank">https://gist.github.com/bolinfest/11236652</a><br></div><div><br></div><div>Some surprising results:</div><div><br></div><div>(1) libclang gives me over 5000 suggestions.</div>


<div>(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: <a href="http://clang.llvm.org/doxygen/group__CINDEX__CODE__COMPLET.html#ga46e843acdf63d9a7a0c7341a2d222c49" target="_blank">http://clang.llvm.org/doxygen/group__CINDEX__CODE__COMPLET.html#ga46e843acdf63d9a7a0c7341a2d222c49</a>). Search for "priority=40" in the gist to see examples of results with a lower priority that seem less relevant.</div>


<div>(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.</div><div><br></div><div>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?</div>


<div><br></div><div>Thank you,</div><div>Michael</div><div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>