[cfe-dev] [LLVMdev] clang code-completion question

Douglas Gregor dgregor at apple.com
Wed Nov 28 07:16:48 PST 2012

On Nov 27, 2012, at 10:51 PM, Nick Lewycky <nicholas at mxc.ca> wrote:

> [bcc llvm-dev, +cfe-dev]
> Dmitry Frank wrote:
>> Dear developers,
>> First of all, thank you for your job on clang, now I use clang as
>> autocompletion tool with my Vim, and it seems to work awesome. But I
>> have some questions:
>>  1) Is it possible to make clang to complete pointers to functions as a
>> functions? I mean, I want to get function prototype, with returning
>> value type and all the parameters.
> Clang certainly knows all the relevant information, but it's not clear how this would work in code completion. What do you expect to have in the buffer, and where would the cursor be for clang to complete?

Presumably, this comes from providing a code completion in an expression context, e.g.,

void foo(int (*fp)(int, int)) {
  /* complete here */

currently produces a result for 'fp', but one one for 'fp(<#int#>, <#int#>)'.

Generally, I think this would be an improvement, for pointers to functions, references to functions, blocks, and lambdas. Perhaps member pointers as well. However, it might be slightly annoying when you're actually trying to pass the function pointer somewhere else:

void bar(int (*fp)(int, int)) { }

void foo(int (*fp)(int, int)) {
  bar(/*complete here*/

Contextual type information can help when we have it, but we often don't have it.

This is work filing a bug on.

>> 2) Is it possible to make completion work inside structure initializers?
>> I mean, like that:
>> typedef  struct  {
>>    int  a;
>>    int  b;
>> } T_MyStruct;
>> int  main(void)
>> {
>>    T_MyStruct my_struct = {
>>       .a =0,
>>       ./*cursor is here. I want to get list of struct members: [a, b]*/
>>    };
>> }
> This sounds like a great missing-feature bug report. Please file it at llvm.org/bugs !

Yes, this is definitely a missing feature.

	- Doug

More information about the cfe-dev mailing list