Closed wanghaiqiangk closed 3 years ago
It is possible. Ctags can tag "signature" field for functions in some languages, including C. We can simply append it after the inserted function name.
However I'm not sure if it will turn out to be handy. If I understand it correctly, you'll have to delete the signature, then fill in the parameters.
Eldoc support was once implemented, but I removed it since it needs to be implemented per language. Now I use citre-ace-peek
instead. A peek window gives you more information anyway, and it works for languages that ctags doesn't support the signature field for.
@AmaiKinono, I guess nth:
fields introduced lately can be utilized to implement this kind of features:
int f(int x, int y, int z);
f foo.c /.../;" kind:prototype typeref:typename:int file: signature:(int x,int y,int z)
x foo.c /.../;" kind:parameter scope:prototype:f typeref:typename:int nth:0
y foo.c /.../;" kind:parameter scope:prototype:f typeref:typename:int nth:1
z foo.c /.../;" kind:parameter scope:prototype:f typeref:typename:int nth:2
As @pragmaware pointed out, nth:
is not enough for C++, however, for C, nth
helps you; citre doesn't have to parse the value for the signature:
fields.
I guess nth: fields introduced lately can be utilized to implement this kind of features
Maybe we are talking different things here... What does it mean by "this kind of features"?
What I think can be implemented using the nth
field is showing the info of current parameter (using eldoc), but this will require linear search of the tags file. Also, it's hard to deal with multiple definitions with the same name.
I think citre-ace-peek
is good enough. It requires some manual operations, but it works for all languages and tags with duplicate names.
However I'm not sure if it will turn out to be handy. If I understand it correctly, you'll have to delete the signature, then fill in the parameters.
Let's see an example:
memcpy(void *restrict __dest, const void *restrict __src, size_t __n)
The code is generated after selecting memcpy
from rtags
Basically this is just copied from the header file where it is defined. But then all three parameters are highlighted and the cursor is re-located at the first one. Right there, as I continue typing, the first parameter will be replaced, then enter a [TAB] key, the cursor jumps to the next one. After the last parameter is substituted, a final [TAB] brings the cursor to the end of line, to let you enter a semi-colon.
Ok. Why do I think this is handy?
Maybe you will not implement this from scratch. I did a little research of how related packages achieve this feature, like rtags, irony, LSP (OK, I didn't read how LSP does, I mention it as it also has this feature)
Since you already integrate with company
, it's possible company-template
will do the job for you.
Since you already integrate with
company
Citre doesn't intergrate with company. Citre intergrates with the built-in completion-at-point-function
mechanism, and company intergrates with that.
A big problem is, if there are multiple functions with the same name, which one should Citre pick? With citre-ace-peek
, you can manually pick one.
A big problem is, if there are multiple functions with the same name, which one should Citre pick? With
citre-ace-peek
, you can manually pick one.
Actually I don't understand this concern, and this leads to a confusion that we may think about different feature or usage situation.
Even if we have several functions with the same name, foo(int a, int b)
and foo(int a, double b)
. P.s. Return type is not considered here. OK, I assume that ctags can tag both functions and distinguish them well. Now, our procedures are the following:
foo
____________________________________________________________
| foo function other attributes prototype (int a, int b)
| foo function other attributes prototype (int a, double b)
| there can be more of that...
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
C-n
and focus on that lineNow, the line on the buffer should be foo(int a, double b)
There should be a prerequisite that ctags must satisfy, which is ctags can tag functions with same name and properly distinguish them.
citre gives a dialog offering us the selection among...
This means Citre needs to implement another completion UI aside with capf, and I need to maintain it for a feature I don't use.
ctags can tag functions with same name and properly distinguish them.
Yes it does. I encourage you to look into a tags file and get an idea of the data behind Citre.
At now I'm not into this idea, since I don't use it and have not seen a easy way to implement it. Sorry.
When I want to insert a function call, only the function name is inserted into the buffer without more prototype info, like its parameter list. Is this possible in citre?
Also can citre integrate eldoc?