unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Randy Taylor <dev@rjt.dev>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: eliz@gnu.org, "Jostein Kjønigsen" <jostein@secure.kjonigsen.net>,
	"Yuan Fu" <casouri@gmail.com>,
	61302@debbugs.gnu.org
Subject: bug#61302: 29.0.60; rust-ts-mode does not show function-invocation on field-properties
Date: Wed, 15 Feb 2023 02:07:19 +0000	[thread overview]
Message-ID: <FkWzkG8TJQ5P3ddy0EiqpdZL2cx7mPl6E5of48w3-avt1AJsvTTds3BfRvo85viWhTAOFFSUMM1mWCASgpeumEL0VDYY5lEcHAse9-64Pxo=@rjt.dev> (raw)
In-Reply-To: <6b75a99f-05fd-cde9-e9fe-7191f12d72e1@yandex.ru>

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

On Tuesday, February 14th, 2023 at 17:14, Dmitry Gutov <dgutov@yandex.ru> wrote:
> On 14/02/2023 14:39, Randy Taylor wrote:
> 
> > On Tuesday, February 14th, 2023 at 06:42, Jostein Kjønigsen
> > jostein@secure.kjonigsen.net wrote:
> > 
> > > Haven given the latest patch a try on a less macro-ridden codebase I have to
> > > say it looks a lot better. In general I would say for this other
> > > code-base it looks favourable to rust-mode.
> > > 
> > > If there's one thing which still seems to be done better in rust-mode
> > > (not nitpicking the variable highlighting), it would be fully namespaces
> > > function calls within classes.
> > > 
> > > Consider the following code:
> > > 
> > > extern crate claxon;
> > > let result = claxon::FlacReader::open(path);
> > > 
> > > While rust-ts-mode correctly identifies that open() is a function-call,
> > > rust-mode correctly identified FlacReader as a class.
> > 
> > Thanks for testing. I've attached a patch fixing this.
> > 
> > I had deleted a query I thought was now covered :). I look forward to
> > the day we have highlight tests!
> 
> 
> Thank you, looks almost perfect (see below), I've pushed that to emacs-29.

Thanks!

> 
> Highlighting tests are a pain to write, but the initiative is always
> welcome. ;-) In the meantime, at least tree-sitter validates the
> queries, which lowers the odds of typos in font-lock rules.
> 
> Speaking of a problem, the solution with applying the explicit 'default'
> face doesn't seem ideal. Aside from the redundancy in the resulting
> buffer structure (with very little practical downside), it also makes
> the 'vc-diff' buffers look like this on the attached screenshots (the
> 'default' face's background overrides the greens and reds).
> 
> I couldn't find a quick solution to this problem, so I pushed the
> existing code for now.

The following patch fixes it for me, but it's a hack since the face doesn't exist (and I don't think the override option matters for the current patch either, I only realized these things as I was about the send the email).

I tried using 'default with all the different override options and nothing worked. Yuan, any ideas?

Basically what we have here are general scoped_identifier queries that we want to apply only to the actual code (i.e. not imports). However, these scoped_identifiers also exist in the imports and the same highlighting semantics don't apply there, so we have specific queries for the different kinds of imports that specify how they want their scoped_identifier stuff highlighted. For some of those specific queries, we want to leave the face as it and make sure nothing else gets applied to it (i.e. default is what we want). Apparently that causes issues with vc-diff buffers, and maybe other things we have yet to discover.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-rust-ts-mode-highlights-overriding-vc-diff-buffe.patch --]
[-- Type: text/x-patch; name=0001-Fix-rust-ts-mode-highlights-overriding-vc-diff-buffe.patch, Size: 3871 bytes --]

From bd405ab9dc1b02d76f56a94b984b7bea9e597bc2 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Tue, 14 Feb 2023 20:40:05 -0500
Subject: [PATCH] Fix rust-ts-mode highlights overriding vc-diff buffers
 (Bug#61302)

* lisp/progmodes/rust-ts-mode.el (rust-ts-mode--fontify-default): New
function.
(rust-ts-mode--font-lock-settings): Use it.
---
 lisp/progmodes/rust-ts-mode.el | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index f510b7bb6c9..0b2619c51ad 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -217,7 +217,8 @@ rust-ts-mode--font-lock-settings
                      (scoped_identifier path: (_)
                                         name: (identifier) @font-lock-type-face))
       (:match "^[A-Z]" @font-lock-type-face))
-     (use_as_clause path: (scoped_identifier name: (identifier) @default))
+     (use_as_clause
+      path: (scoped_identifier name: (identifier) @rust-ts-mode--fontify-default))
 
      ((use_declaration
        argument: (scoped_identifier
@@ -226,14 +227,14 @@ rust-ts-mode--font-lock-settings
       (:match "^[A-Z]" @font-lock-type-face))
      (use_declaration
       argument: (scoped_identifier
-                 name: (identifier) @default))
+                 name: (identifier) @rust-ts-mode--fontify-default))
 
      (use_declaration
       argument: (scoped_identifier
                  path: (scoped_identifier
                         path: (_) @font-lock-constant-face
                         name: (identifier) @font-lock-constant-face)
-                 name: (identifier) @default))
+                 name: (identifier) @rust-ts-mode--fontify-default))
 
      (use_declaration
       argument: (scoped_use_list
@@ -243,12 +244,12 @@ rust-ts-mode--font-lock-settings
 
      ((use_list (identifier) @font-lock-type-face)
       (:match "^[A-Z]" @font-lock-type-face))
-     (use_list (identifier) @default)
+     (use_list (identifier) @rust-ts-mode--fontify-default)
      ((use_list (scoped_identifier path: (_)
                                    name: (identifier) @font-lock-type-face))
       (:match "^[A-Z]" @font-lock-type-face))
      (use_list (scoped_identifier path: (_)
-                                  name: (identifier) @default))
+                                  name: (identifier) @rust-ts-mode--fontify-default))
      (use_wildcard (scoped_identifier
                     name: (identifier) @font-lock-constant-face))
 
@@ -286,7 +287,9 @@ rust-ts-mode--font-lock-settings
              name: (identifier) @font-lock-constant-face))
      (type_identifier) @font-lock-type-face
      ;; Ensure function calls aren't highlighted as types.
-     (call_expression function: (scoped_identifier name: (identifier) @default)))
+     (call_expression function:
+                      (scoped_identifier
+                       name: (identifier) @rust-ts-mode--fontify-default)))
 
    :language 'rust
    :feature 'property
@@ -304,7 +307,7 @@ rust-ts-mode--font-lock-settings
    :feature 'variable
    '((identifier) @font-lock-variable-name-face
      ;; Everything in a token_tree is an identifier.
-     (token_tree (identifier) @default))
+     (token_tree (identifier) @rust-ts-mode--fontify-default))
 
    :language 'rust
    :feature 'escape-sequence
@@ -317,6 +320,12 @@ rust-ts-mode--font-lock-settings
    '((ERROR) @font-lock-warning-face))
   "Tree-sitter font-lock settings for `rust-ts-mode'.")
 
+(defun rust-ts-mode--fontify-default (node _ start end &rest _)
+  "Fontify the node with the default face."
+  (treesit-fontify-with-override
+   (treesit-node-start node) (treesit-node-end node)
+   'default-face 'append start end))
+
 (defalias 'rust-ts-mode--fontify-pattern
   (and
    (treesit-available-p)
-- 
2.39.2


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

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-05 20:15 bug#61302: 29.0.60; rust-ts-mode does not show function-invocation on field-properties Jostein Kjønigsen
2023-02-05 21:30 ` Randy Taylor
2023-02-05 21:52   ` Jostein Kjønigsen
2023-02-05 21:59     ` Jostein Kjønigsen
2023-02-06  1:50       ` Randy Taylor
2023-02-06  2:45         ` Dmitry Gutov
2023-02-06  2:57           ` Randy Taylor
2023-02-07 14:26           ` Randy Taylor
2023-02-07 18:16             ` Dmitry Gutov
2023-02-07 18:25               ` Dmitry Gutov
2023-02-08  3:38                 ` Randy Taylor
2023-02-08 15:44                   ` Dmitry Gutov
2023-02-09  3:38                     ` Randy Taylor
2023-02-09 21:19                       ` Dmitry Gutov
2023-02-10  3:44                         ` Randy Taylor
     [not found]                           ` <33cec9a6-7e69-2eb3-a8a6-58ce23a5c185@yandex.ru>
2023-02-12  2:48                             ` Randy Taylor
2023-02-13  3:37                               ` Dmitry Gutov
2023-02-14  3:25                                 ` Randy Taylor
2023-02-14 11:42                                   ` Jostein Kjønigsen
2023-02-14 12:39                                     ` Randy Taylor
2023-02-14 14:28                                       ` Jostein Kjønigsen
2023-02-14 22:14                                       ` Dmitry Gutov
2023-02-15  2:07                                         ` Randy Taylor [this message]
2023-02-16  1:53                                           ` Dmitry Gutov
2023-02-18  3:27                                             ` Dmitry Gutov
2023-02-18 20:42                                               ` Randy Taylor
2023-02-18 21:45                                                 ` Dmitry Gutov
2023-02-18 23:31                                                   ` Randy Taylor
2023-02-19  0:13                                                     ` Dmitry Gutov
2023-02-19  0:50                                                       ` Randy Taylor
2023-02-19 17:23                                                         ` Dmitry Gutov
2023-02-18 20:59                                               ` Dmitry Gutov
2023-02-13 10:17                           ` Jostein Kjønigsen
2023-02-13 14:39                             ` Randy Taylor
2023-02-13 15:04                               ` Jostein Kjønigsen
2023-02-13 18:19                                 ` Randy Taylor
2023-02-13 19:57                               ` Dmitry Gutov
2023-02-13 20:49                                 ` Dmitry Gutov
2023-02-13 19:59                             ` Dmitry Gutov
2023-02-05 21:56   ` Dmitry Gutov
2023-02-06  2:06     ` Randy Taylor
2023-02-06  2:16       ` Dmitry Gutov
2023-02-05 21:44 ` 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='FkWzkG8TJQ5P3ddy0EiqpdZL2cx7mPl6E5of48w3-avt1AJsvTTds3BfRvo85viWhTAOFFSUMM1mWCASgpeumEL0VDYY5lEcHAse9-64Pxo=@rjt.dev' \
    --to=dev@rjt.dev \
    --cc=61302@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=dgutov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=jostein@secure.kjonigsen.net \
    /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).