GNU bug report logs - #63390
29.0.90; c-ts-mode fails to recognize functions in xterm.c

Previous Next

Package: emacs;

Reported by: Eli Zaretskii <eliz <at> gnu.org>

Date: Tue, 9 May 2023 12:03:01 UTC

Severity: normal

Found in version 29.0.90

Done: Yuan Fu <casouri <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 63390 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 63390 <at> debbugs.gnu.org
Subject: Re: bug#63390: 29.0.90; c-ts-mode fails to recognize functions in
 xterm.c
Date: Sun, 14 May 2023 22:47:06 -0700

> On May 12, 2023, at 4:11 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
> Yuan, could you please look into this?
> 
>> Date: Tue, 09 May 2023 15:03:08 +0300
>> From: Eli Zaretskii <eliz <at> gnu.org>
>> 
>> To reproduce:
>> 
>>  emacs -Q
>>  M-x load-library RET c-ts-mode RET
>>  C-x C-f src/xterm.c
>>  C-u 8290 M-g g
>> 
>> Observe that the name of the function x_draw_glyph_string_foreground
>> is not fontified in font-lock-function-name-face, but in the default
>> face.
>> 
>> Starting treesit-explore-mode seems to indicate that tree-sitter
>> interprets this as a function declaration, not a function definition:
>> 
>>  (function_declarator declarator: (identifier)
>>   parameters: 
>>    (parameter_list (
>>     (parameter_declaration
>>      type: (struct_specifier struct name: (type_identifier))
>>      declarator: (pointer_declarator * declarator: (identifier)))
>>     )))
>> 
>> Same with the next function, x_draw_composite_glyph_string_foreground.
>> But the function after that, x_draw_glyphless_glyph_string_foreground,
>> is again recognized as function definition.  I wonder if the
>> preprocessor conditionals around there have something to do with that.

Ok, so that’s because there are ifdef’s inside the function, which cuts the function into pieces and tree-sitter can’t make out a function_definition, which is what we use to fontify the function name. A function_declarator alone can be used in many places, like in an argument list for function pointers, I think?

I can fix this by fontifying top-level function_declaration, I think a top-level function_declaration should always be a function definition?

>> 
>> Btw, function declarations in a header file are recognized as such,
>> but the names of the functions there are still correctly fontified.

They are fine because there’s a semicolon in the end, so the function_decalration is wrapped in a declaration node, which we (the fontification rules) recognize.

Yuan



This bug report was last modified 2 years and 6 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.