unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Yuan Fu <casouri@gmail.com>
Cc: 61205@debbugs.gnu.org, randy taylor <dev@rjt.dev>
Subject: bug#61205: 'function' in 3rd element of treesit-font-lock-feature-list
Date: Thu, 2 Feb 2023 04:34:44 +0200	[thread overview]
Message-ID: <775e21ae-6513-8dca-a669-bedae86bf02d@yandex.ru> (raw)
In-Reply-To: <D4799783-D0D3-47EC-8F28-3EC5331746CC@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1772 bytes --]

On 01/02/2023 07:18, Yuan Fu wrote:
> 
> 
>> On Jan 31, 2023, at 6:08 PM, Dmitry Gutov <dgutov@yandex.ru> wrote:
>>
>> X-Debbugs-Cc: Yuan Fu <casouri@gmail.com>, Randy Taylor <dev@rjt.dev>
>>
>> Some new built-in modes has 'function' feature highlighting thus enabled by default.
>>
>> rust-ts-mode, go-ts-mode, cmake-mode
>>
>> Should we move it to 4 for consistency with the rest?
>>
>> Previously, we talked about that and concluded that function calls are usually everywhere and are easy to notice without additional highlighting.
> 
> Right, I think they should be level 4.

OK, I tried simply changing that, and it turned out none of these modes 
have a 'definition' feature, so highlightings get stripped from all 
definitions as well.

And in a couple of cases function calls got highlighted either as a 
type, or as a property. I fixed the latter by deleting one selector, and 
the latter didn't touch per se.

But since the same modes had 'variable' and 'property' features in the 
3rd level as well, I moved them to the 4th (that resolved the incorrect 
highlighting as property mentioned above, but it's probably need to be 
improved later, in case someone will want to enable 'property' but not 
'function' highlighting).

And I added the 'definition' features and moved some highlighting rules 
there. And added some.

So the patch looks a bit more complex than expected, see attached.

cmake-ts-mode, in the end, I ended up keeping as-is. The 'variable' 
selector is more functional there than everywhere else (the grammar uses 
those nodes for template expansion), and if 'function' is removed, the 
buffer looks almost devoid of highlighting.

Also none of these modes have highlighting for function parameters or 
assignments. That can be improved later.

[-- Attachment #2: ts-modes-refine-features.diff --]
[-- Type: text/x-patch, Size: 4556 bytes --]

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 5f3e1ea3e68..3536a6cb0cd 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -119,17 +119,27 @@ go-ts-mode--font-lock-settings
    :feature 'delimiter
    '((["," "." ";" ":"]) @font-lock-delimiter-face)
 
+   :language 'go
+   :feature 'definition
+   '((function_declaration
+      name: (identifier) @font-lock-function-name-face)
+     (method_declaration
+      name: (field_identifier) @font-lock-function-name-face)
+     (method_spec
+      name: (field_identifier) @font-lock-function-name-face))
+
+   :language 'go
+   :feature 'definition
+   '((field_declaration
+      name: (field_identifier) @font-lock-property-face))
+
    :language 'go
    :feature 'function
    '((call_expression
       function: (identifier) @font-lock-function-name-face)
      (call_expression
       function: (selector_expression
-                 field: (field_identifier) @font-lock-function-name-face))
-     (function_declaration
-      name: (identifier) @font-lock-function-name-face)
-     (method_declaration
-      name: (field_identifier) @font-lock-function-name-face))
+                 field: (field_identifier) @font-lock-function-name-face)))
 
    :language 'go
    :feature 'keyword
@@ -218,10 +228,10 @@ go-ts-mode
     (setq-local treesit-font-lock-settings go-ts-mode--font-lock-settings)
     (setq-local treesit-font-lock-feature-list
                 '(( comment)
-                  ( keyword string type)
-                  ( constant escape-sequence function label number
-                    property variable)
-                  ( bracket delimiter error operator)))
+                  ( keyword string type definition)
+                  ( constant escape-sequence label number)
+                  ( bracket delimiter error operator function variable
+                    property)))
 
     (treesit-major-mode-setup)))
 
diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index e317793d211..20ee2e420d3 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -155,6 +155,16 @@ rust-ts-mode--font-lock-settings
    :feature 'delimiter
    '((["," "." ";" ":" "::"]) @font-lock-delimiter-face)
 
+   :language 'rust
+   :feature 'definition
+   '((function_item name: (identifier) @font-lock-function-name-face)
+     (macro_definition "macro_rules!" @font-lock-constant-face)
+     (macro_definition (identifier) @font-lock-preprocessor-face))
+
+   :language 'rust
+   :feature 'definition
+   '((field_declaration name: (field_identifier) @font-lock-property-face))
+
    :language 'rust
    :feature 'function
    '((call_expression
@@ -164,15 +174,12 @@ rust-ts-mode--font-lock-settings
         field: (field_identifier) @font-lock-function-name-face)
        (scoped_identifier
         name: (identifier) @font-lock-function-name-face)])
-     (function_item (identifier) @font-lock-function-name-face)
      (generic_function
       function: [(identifier) @font-lock-function-name-face
                  (field_expression
                   field: (field_identifier) @font-lock-function-name-face)
                  (scoped_identifier
                   name: (identifier) @font-lock-function-name-face)])
-     (macro_definition "macro_rules!" @font-lock-constant-face)
-     (macro_definition (identifier) @font-lock-preprocessor-face)
      (macro_invocation macro: (identifier) @font-lock-preprocessor-face))
 
    :language 'rust
@@ -208,7 +215,6 @@ rust-ts-mode--font-lock-settings
      (mod_item name: (identifier) @font-lock-constant-face)
      (primitive_type) @font-lock-type-face
      (type_identifier) @font-lock-type-face
-     (scoped_identifier name: (identifier) @font-lock-type-face)
      (scoped_identifier path: (identifier) @font-lock-constant-face)
      (scoped_identifier
       (scoped_identifier
@@ -318,10 +324,10 @@ rust-ts-mode
     (setq-local treesit-font-lock-settings rust-ts-mode--font-lock-settings)
     (setq-local treesit-font-lock-feature-list
                 '(( comment)
-                  ( keyword string)
+                  ( keyword string definition)
                   ( attribute builtin constant escape-sequence
-                    function number property type variable)
-                  ( bracket delimiter error operator)))
+                    number type)
+                  ( bracket delimiter error operator function property variable)))
 
     ;; Imenu.
     (setq-local treesit-simple-imenu-settings

  reply	other threads:[~2023-02-02  2:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01  2:08 bug#61205: 'function' in 3rd element of treesit-font-lock-feature-list Dmitry Gutov
2023-02-01  5:18 ` Yuan Fu
2023-02-02  2:34   ` Dmitry Gutov [this message]
2023-02-02  3:18     ` Randy Taylor
2023-02-02 11:03       ` Dmitry Gutov
2023-02-02 20:25   ` Dmitry Gutov
2023-02-03  2:38     ` Yuan Fu
2023-02-03  2:51       ` Dmitry Gutov
2023-02-03  6:45         ` Eli Zaretskii
2023-02-03  6:46     ` Eli Zaretskii
2023-02-03 11:42       ` Dmitry Gutov
2023-02-03 12:19         ` Eli Zaretskii
2023-02-03 15:15           ` Dmitry Gutov
2023-02-03 15:54             ` Eli Zaretskii
2023-02-03 17:10               ` Dmitry Gutov
2023-02-04  3:36                 ` Dmitry Gutov
2023-02-04  6:53                   ` Eli Zaretskii
2023-02-04 23:44                     ` Dmitry Gutov
2023-02-05  6:05                       ` Eli Zaretskii
2023-02-05 13:52                         ` Dmitry Gutov
2023-02-02  2:34 ` Randy Taylor
2023-02-02  2:44   ` Dmitry Gutov
2023-02-02  3:29     ` Randy Taylor
2023-02-02 11:11       ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=775e21ae-6513-8dca-a669-bedae86bf02d@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=61205@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=dev@rjt.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).