all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Randy Taylor <dev@rjt.dev>
To: Yuan Fu <casouri@gmail.com>
Cc: Dmitry Gutov <dmitry@gutov.dev>, 69625@debbugs.gnu.org
Subject: bug#69625: 30.0.50; [PATCH] rust-ts-mode doesn't fontify some enum
Date: Sat, 09 Mar 2024 03:50:38 +0000	[thread overview]
Message-ID: <36fGsZdSJ-V_6XVD6SuMoXHJKJ3e5x6xytnwwi2VJ0zzfcRRgOnY2FnWmCLfz4hifa1fkoMw0xCv4glCe8MZkoMqsUxsaY2N8LA1avOeaQk=@rjt.dev> (raw)
In-Reply-To: <CD02B2B2-ACA6-484B-B832-B7F0F3F3B385@gmail.com>

On Thursday, March 7th, 2024 at 23:43, Yuan Fu <casouri@gmail.com> wrote:
> 
> X-Debug-CC: dev@rjt.dev mailto:dev@rjt.dev

Should be X-Debbugs-CC ;).

> 
> 
> (I lied a little bit about on the [PATCH] part: I have a solution but didn’t turn it into a patch yet.)
> 
> The problem is follows: given the rust code below, some enum are not fontified with type face under font lock level 3, and those enum are fontified as function or variable under font lock level 4.
> 
> fn main() {
> func(MyEnum::VariantA(0));
> func(MyEnum::VariantB);
> func(VariantC);
> func(VariantD(0));
> }
> 
> VariantA and VariantB are fontified correctly, but VariantC and VariantD are not.
> 
> I think a simple rule that fontifies every capitalized identifier would fix this. But I don’t know if that’ll create other problem. AFAIK capitalized identifier is always some type in rust, right?
> 

For VariantA and VariantD, these are constructors being used as functions,
so I think they are technically being highlighted correctly at level 4.
Whether or not that is desired is another question - I think that is simply
a matter of opinion/preference.
VariantA gets highlighted as a type and not a function at level 3 because that
level doesn't support functions, but does support types. Maybe that could be
considered a bug in that it shouldn't be highlighted at all for level 3?
I'm not sure how worth it would be to do something about that though, or how
easy.

For VariantC, our (and tree-sitter's) best guess is that it's a variable.
We can't really know it's a type without guessing - like assuming a capitalized
identifier is a type, and I don't think that's something we can assume. People
can have capitalized functions and variables even if that goes against Rust's
usual style. Perhaps as a compromise we could introduce a variable (or something)
that lets the user specify that all capitalized identifiers should be treated as
types? Maybe it even makes sense to default it to that behaviour since I believe
most Rust code follows that style.

I don't really think this is a tree-sitter problem to solve but more so an LSP one:
tree-sitter can't know that all of these are enums based on how they are used.
As was mentioned in that GitHub thread, LSP with semantic tokens is the way to go
for the most accuracy. But even with semantic tokens, how to highlight enum variants
being used as functions comes down to opinion methinks.

> This is first reported on rust-mode’s GitHub repo: https://github.com/rust-lang/rust-mode/issues/518
> 
> Yuan





  parent reply	other threads:[~2024-03-09  3:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08  4:43 bug#69625: 30.0.50; [PATCH] rust-ts-mode doesn't fontify some enum Yuan Fu
2024-03-08 22:56 ` Dmitry Gutov
2024-03-09  3:50 ` Randy Taylor [this message]
2024-03-15  1:52   ` Dmitry Gutov
2024-03-16  1:37     ` Randy Taylor
2024-04-08  7:25     ` Yuan Fu
2024-06-22 11:07       ` Stefan Kangas
2024-06-22 23:17         ` Yuan Fu
2024-06-28  2:40           ` Randy Taylor
2024-06-28  4:43             ` Yuan Fu
2024-06-29  2:37               ` Randy Taylor
2024-06-29  3:03                 ` Stefan Kangas
2024-06-29  5:41                   ` Yuan Fu
2024-06-29 19:08                     ` Randy Taylor

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

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

  git send-email \
    --in-reply-to='36fGsZdSJ-V_6XVD6SuMoXHJKJ3e5x6xytnwwi2VJ0zzfcRRgOnY2FnWmCLfz4hifa1fkoMw0xCv4glCe8MZkoMqsUxsaY2N8LA1avOeaQk=@rjt.dev' \
    --to=dev@rjt.dev \
    --cc=69625@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=dmitry@gutov.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.