clang code-completion question

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.

  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]*/
   };
}

Thanks.

[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?

You'll need to have already typed something that makes it clear that the next thing clang ought to do is complete the type of function prototype. Usually completion looks forwards, and wouldn't you have already needed to type the return type to get to the function name? Maybe I'm just failing to visualize what we're doing here.

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 !

Nick

Hello, Nick!

Thank you for your reply.

Regarding to pointers to functions: look at this code:

static void _some_func(int a, int b, int c)
{
//-- do something
}

typedef void (*T_pMyFunc) (int a, int b, int c);

typedef struct {
T_pMyFunc p_my_func;
} T_MyStruct;

int main(void)
{
T_MyStruct my_struct = {
.p_my_func = _some_func,
};

_some_func/cursor is here. I see function signature: int a, int b, int c. Everything is great/

my_struct./cursor is here. I see only member T_pMyFunc p_my_func, but there’s no function signature. There would be even greater if clang could handle this/

}

Hope I explained this clear.

As to second one (completion inside structure initializer), thanks for the suggestion, I filed it as you suggested: http://llvm.org/bugs/show_bug.cgi?id=14446

Hello, Nick!

Thank you for your reply.

Regarding to pointers to functions: look at this code:

static void _some_func(int a, int b, int c)
{
//-- do something
}

typedef void (*T_pMyFunc) (int a, int b, int c);

typedef struct {
T_pMyFunc p_my_func;

} T_MyStruct;

int main(void)
{
T_MyStruct my_struct = {

.p_my_func = _some_func,
};

_some_func/cursor is here. I see function signature: int a, int b, int c. Everything is great/

my_struct./cursor is here. I see only member T_pMyFunc p_my_func, but there’s no function signature. There would be even greater if clang could handle this/

}

Hope I explained this clear.

As to second one (completion inside structure initializer), thanks for the suggestion, I filed it as you suggested: http://llvm.org/bugs/show_bug.cgi?id=14446

[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