Subject: bug#61655: [Tree sitter] [Feature Request] font-lock function calls, definitions, separately

From: Jacob Faibussowitsch <[email-masked]>
Date: Mon, 20 Feb 2023 15:45:37 -0500

Hello All,

> Jacob, do you have any examples where it is wrong and what you expect instead?

I had attached some screen grabs in my initial email, if they don’t show up on your end they do show up on the web archives: https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-02/msg01638.html.

The key differences are:

1. `foo()` (i.e. a function definition) is light-blue.
2. `bar()`, and `baz()` (function calls) are dark blue.
3. The member function call `b.mem_func()` highlights the `mem_func()` part in red.

On the other hand, the builtin tree sitter mode font-locks them all using the same light-blue color. Indeed performing M-x describe-face over each separate part yields only `font-lock-function-name-face` for builtin, while 3rd party returns separate faces (which are available to customize) for each case.

I looked through `c-ts-mode.el` as an example and found `c-ts-mode--font-lock-settings`. Treesitter already identifies all of the above cases as different nodes in the AST (as evidenced in treesit-explor-mode) so it seems that adding another set of matchers (and appropriate faces, e.g. font-lock-function-call-face)

:language mode
:feature 'label
'((call_expression
   function: (identifier) @font-lock-function-call-face))

Should do the trick no?

Best regards,

Jacob Faibussowitsch
(Jacob Fai - booss - oh - vitch)

> On Feb 20, 2023, at 15:24, Theodor Thornhill <[email-masked]> wrote:
> 
> Eli Zaretskii <[email-masked]> writes:
> 
>>> From: Jacob Faibussowitsch <[email-masked]>
>>> Date: Mon, 20 Feb 2023 10:54:42 -0500
>>> 
>>> Is it possible to have the builtin tree sitter give differentiate font-locking for function calls and function definitions?
>> 
>> AFAIU, it already does.  Yuan and Theo, am I wrong?
> 
> You're not wrong, but it depends on each implementation whether or not
> the definition gets a different color or not.  Jacob, do you have any
> examples where it is wrong and what you expect instead?
> 
> Theo