Subject: bug#60296: Re: bug#60296: The imenu is not created properly in c-ts-mode

From: "[email-masked]" <[email-masked]>
Date: Tue, 27 Dec 2022 18:03:14 +0800

>> On Dec 25, 2022, at 11:58 PM, [email-masked] wrote:
>>
>> >> On Dec 24, 2022, at 10:53 PM, Eli Zaretskii <[email-masked]> wrote:
>> >>
>> >>> Cc: [email-masked]
>> >>> From: Yuan Fu <[email-masked]>
>> >>> Date: Sat, 24 Dec 2022 19:00:21 -0800
>> >>>
>> >>>> From: sniper <[email-masked]>
>> >>>> To: [email-masked]
>> >>>> Subject: 29.0.60; The imenu is not created properly in c-ts-mode.
>> >>>>
>> >>>> ``` c
>> >>>> char *test(int size){
>> >>>> return NULL;
>> >>>> }
>> >>>> ```
>> >>>> If c-ts-mode is enabled in a c file, the imenu created will be [` test(int size)`] if the return type of the function is a
>> >>>> pointer.
>> >>>> The expected display should just be the function name [` test `], with no subsequent arguments
>> >>>
>> >>> Thanks, this should be fixed now.
>> >>
>> >> This change leads to
>> >>
>> >>  In c-ts-mode--fontify-declarator:
>> >>  progmodes/c-ts-mode.el:405:69: Warning: Unused lexical argument `args'
>> >>
>> >> And "&rest args" is indeed unused there, AFAICT.
>> 
>> >My bad. I’ve fixed that by changing args to _.
>> Hi, Yuan:
>>
>> I tested it in the latest version and found several more issues.
>> ``` c
>> int main(int argc, char *argv[])
>> {
>> .....
>>    struct name_t name = (struct name_t)name;
>>    name.a = sizeof(struct name_t);
>> .....
>> }
>> ```
>> If Forced conversion or ` sizeof(struct name_t) ` occurs in a function, it will occur in the Struct entry of imenu.
>>
>>
>> ``` c
>> int func_1(int v);  //  <-- function declaration
>> int main(int argc, char *argv[])
>> {
>> }
>> ```
>> If there is a function declaration in the c file, it will also appear in imenu's Variable entry.
> 
>Thanks, I fixed those. Further more, I improved the whole imenu thing in c-ts-mode and it should be robust now.

Hi, Yuan:
I found another problem, this problem can not be easy to solve.
```
int func_1(int v) { if(v == 0){ } #ifdef MMM else if(v == 1){ } #endif return v; } 
```
A function like this has macros in it.
The imenu created looks like this

```
+ Function main + func_1 func_1 if 
```
Thanks.

[email-masked]
 
From: Yuan Fu
Date: 2022-12-26 17:47
To: e190
CC: Eli Zaretskii; 60296
Subject: Re: bug#60296: The imenu is not created properly in c-ts-mode

> On Dec 25, 2022, at 11:58 PM, [email-masked] wrote:
> 
> >> On Dec 24, 2022, at 10:53 PM, Eli Zaretskii <[email-masked]> wrote:
> >>
> >>> Cc: [email-masked]
> >>> From: Yuan Fu <[email-masked]>
> >>> Date: Sat, 24 Dec 2022 19:00:21 -0800
> >>>
> >>>> From: sniper <[email-masked]>
> >>>> To: [email-masked]
> >>>> Subject: 29.0.60; The imenu is not created properly in c-ts-mode.
> >>>>
> >>>> ``` c
> >>>> char *test(int size){
> >>>> return NULL;
> >>>> }
> >>>> ```
> >>>> If c-ts-mode is enabled in a c file, the imenu created will be [` test(int size)`] if the return type of the function is a
> >>>> pointer.
> >>>> The expected display should just be the function name [` test `], with no subsequent arguments
> >>>
> >>> Thanks, this should be fixed now.
> >>
> >> This change leads to
> >>
> >>  In c-ts-mode--fontify-declarator:
> >>  progmodes/c-ts-mode.el:405:69: Warning: Unused lexical argument `args'
> >>
> >> And "&rest args" is indeed unused there, AFAICT.
>  
> >My bad. I’ve fixed that by changing args to _.
> Hi, Yuan:
> 
> I tested it in the latest version and found several more issues.
> ``` c
> int main(int argc, char *argv[])
> {
> .....
>    struct name_t name = (struct name_t)name;
>    name.a = sizeof(struct name_t);
> .....
> }
> ```
> If Forced conversion or ` sizeof(struct name_t) ` occurs in a function, it will occur in the Struct entry of imenu.
> 
> 
> ``` c
> int func_1(int v);  //  <-- function declaration
> int main(int argc, char *argv[])
> {
> }
> ```
> If there is a function declaration in the c file, it will also appear in imenu's Variable entry.
 
Thanks, I fixed those. Further more, I improved the whole imenu thing in c-ts-mode and it should be robust now.
 
Yuan