bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#61302: 29.0.60; rust-ts-mode does not show function-invocation on fi


From: Dmitry Gutov
Subject: bug#61302: 29.0.60; rust-ts-mode does not show function-invocation on field-properties
Date: Sun, 5 Feb 2023 23:44:16 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

Hi!

On 05/02/2023 22:15, Jostein Kjønigsen wrote:
Steps to reproduce:

- set font-lock level 4 to enable highlighting of function-invocations
- create a new buffer and activate rust-ts-mode

Try writing a function which invokes functions indirectly trough field-properties. Example below:

pub fn should_handle(url: String) -> bool {
     if url.ends_with(".css")
        || url.ends_with(".js")
        || url.ends_with(".png")
        || url.ends_with(".jpg")
     {
         false
     } else {
         true
     }
}

Observe that:

- ends_with() is fontified as a property-access, not as a function-invocation.
- (plain function invocation is highlighted as expected though)

From my preliminary inspection of the rust-ts-mode source-code, this seems to be because of a very general override later in the file:

rust-ts-mode.el, line 248 or so:

    :language 'rust
    :feature 'property
    :override t
    '((field_identifier) @font-lock-property-face
      (shorthand_field_initializer (identifier) @font-lock-property-face))

Dissabling "override" for this feature fixes the fontification of method invocations, but I haven't done enough testing to see if there are other unexpected side-effects.

Thanks for the report. I've installed the patch below, commit a529b0d6463.

Note that I wouldn't recommend using the level 4 straight away, because of the 'variable' feature that's not very precise.

It's probably better to use level 3 and add the extra features you need using treesit-font-lock-recompute-features, or use level 4 and drop 'variable'. But that's my opinion.

diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index 18b42b9eced..5c71a8ad461 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -234,6 +234,11 @@ rust-ts-mode--font-lock-settings
      (use_as_clause alias: (identifier) @font-lock-type-face)
      (use_list (identifier) @font-lock-type-face))

+   :language 'rust
+   :feature 'property
+   '((field_identifier) @font-lock-property-face
+     (shorthand_field_initializer (identifier) @font-lock-property-face))
+
    :language 'rust
    :feature 'variable
    '((identifier) @font-lock-variable-name-face
@@ -245,12 +250,6 @@ rust-ts-mode--font-lock-settings
    :override t
    '((escape_sequence) @font-lock-escape-face)

-   :language 'rust
-   :feature 'property
-   :override t
-   '((field_identifier) @font-lock-property-face
-     (shorthand_field_initializer (identifier) @font-lock-property-face))
-
    :language 'rust
    :feature 'error
    :override t






reply via email to

[Prev in Thread] Current Thread [Next in Thread]