GNU bug report logs - #75164
treesit-font-lock-fontify-region is easy to lost color on parse error. suggest to remain fontify on parse error.

Previous Next

Package: emacs;

Reported by: Eval Exec <execvy <at> gmail.com>

Date: Sat, 28 Dec 2024 16:26:01 UTC

Severity: minor

Tags: moreinfo

To reply to this bug, email your comments to 75164 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#75164; Package emacs. (Sat, 28 Dec 2024 16:26:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eval Exec <execvy <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 28 Dec 2024 16:26:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Eval Exec <execvy <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: treesit-font-lock-fontify-region is easy to lost color on parse
 error. suggest to remain fontify on parse error.
Date: Sun, 29 Dec 2024 00:25:24 +0800
Hello.
When I enable rust-ts-mode on a rust file, I found treesitter is easy
to make emacs buffer to lost color.
For example, on the following rust code:
```rust

struct Dog {
    name: String,
    age: u8,
}


struct ManyStruct {
    a: u8,
}

fn many_code(){
    fn fib(n: u32) -> u32 {
        if n == 0 {
            return 0;
        }
        if n == 1 {
            return 1;
        }
        fib(n - 1) + fib(n - 2)
    }
}

fn main() {
    // change below `//` to `/` to see the difference
    // {
}
```

the rust code is right, and the emacs buffer color is right on every
struct/functions.
But, if I change `// {` to `/ {`, then the rust code is wrong, this
buffer will lost all colors.
You can see the change on bellow images:

https://imgur.com/a/4Tnv0GJ

I suggest emacs can remain colors even if the code is wrong.

My emacs version info: GNU Emacs 31.0.50




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#75164; Package emacs. (Mon, 30 Dec 2024 00:30:03 GMT) Full text and rfc822 format available.

Message #8 received at 75164 <at> debbugs.gnu.org (full text, mbox):

From: Charalampos Mitrodimas <charmitro <at> posteo.net>
To: Eval Exec <execvy <at> gmail.com>
Cc: 75164 <at> debbugs.gnu.org
Subject: Re: bug#75164: treesit-font-lock-fontify-region is easy to lost
 color on parse error. suggest to remain fontify on parse error.
Date: Mon, 30 Dec 2024 00:28:58 +0000
Hi,

Eval Exec <execvy <at> gmail.com> writes:

> Hello.
> When I enable rust-ts-mode on a rust file, I found treesitter is easy
> to make emacs buffer to lost color.
> For example, on the following rust code:
> ```rust
>
> struct Dog {
>     name: String,
>     age: u8,
> }
>
>
> struct ManyStruct {
>     a: u8,
> }
>
> fn many_code(){
>     fn fib(n: u32) -> u32 {
>         if n == 0 {
>             return 0;
>         }
>         if n == 1 {
>             return 1;
>         }
>         fib(n - 1) + fib(n - 2)
>     }
> }
>
> fn main() {
>     // change below `//` to `/` to see the difference
>     // {
> }
> ```
>
> the rust code is right, and the emacs buffer color is right on every
> struct/functions.
> But, if I change `// {` to `/ {`, then the rust code is wrong, this
> buffer will lost all colors.

Thanks for reporting this.

I attempted to reproduce this, using your example, when I change `// {`
to `/{` only "main" from `fn main()` loses color. The rest of the syntax
highlighting remains intact in my setup.


                            C. Mitrodimas

> You can see the change on bellow images:
>
> https://imgur.com/a/4Tnv0GJ
>
> I suggest emacs can remain colors even if the code is wrong.
>
> My emacs version info: GNU Emacs 31.0.50




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#75164; Package emacs. (Tue, 31 Dec 2024 21:05:02 GMT) Full text and rfc822 format available.

Message #11 received at 75164 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Charalampos Mitrodimas <charmitro <at> posteo.net>
Cc: Eval Exec <execvy <at> gmail.com>, 75164 <at> debbugs.gnu.org
Subject: Re: bug#75164: treesit-font-lock-fontify-region is easy to lost color
 on parse error. suggest to remain fontify on parse error.
Date: Tue, 31 Dec 2024 13:02:52 -0800

> On Dec 29, 2024, at 4:28 PM, Charalampos Mitrodimas <charmitro <at> posteo.net> wrote:
> 
> Hi,
> 
> Eval Exec <execvy <at> gmail.com> writes:
> 
>> Hello.
>> When I enable rust-ts-mode on a rust file, I found treesitter is easy
>> to make emacs buffer to lost color.
>> For example, on the following rust code:
>> ```rust
>> 
>> struct Dog {
>>    name: String,
>>    age: u8,
>> }
>> 
>> 
>> struct ManyStruct {
>>    a: u8,
>> }
>> 
>> fn many_code(){
>>    fn fib(n: u32) -> u32 {
>>        if n == 0 {
>>            return 0;
>>        }
>>        if n == 1 {
>>            return 1;
>>        }
>>        fib(n - 1) + fib(n - 2)
>>    }
>> }
>> 
>> fn main() {
>>    // change below `//` to `/` to see the difference
>>    // {
>> }
>> ```
>> 
>> the rust code is right, and the emacs buffer color is right on every
>> struct/functions.
>> But, if I change `// {` to `/ {`, then the rust code is wrong, this
>> buffer will lost all colors.
> 
> Thanks for reporting this.
> 
> I attempted to reproduce this, using your example, when I change `// {`
> to `/{` only "main" from `fn main()` loses color. The rest of the syntax
> highlighting remains intact in my setup.

It’s indeed strange to see the whole buffer lost fontification. I don’t see it either.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#75164; Package emacs. (Sun, 02 Mar 2025 04:22:02 GMT) Full text and rfc822 format available.

Message #14 received at 75164 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Charalampos Mitrodimas <charmitro <at> posteo.net>, Eval Exec <execvy <at> gmail.com>,
 75164 <at> debbugs.gnu.org
Subject: Re: bug#75164: treesit-font-lock-fontify-region is easy to lost color
 on parse error. suggest to remain fontify on parse error.
Date: Sun, 2 Mar 2025 04:20:55 +0000
Yuan Fu <casouri <at> gmail.com> writes:

>> On Dec 29, 2024, at 4:28 PM, Charalampos Mitrodimas <charmitro <at> posteo.net> wrote:
>>
>> Hi,
>>
>> Eval Exec <execvy <at> gmail.com> writes:
>>
>>> Hello.
>>> When I enable rust-ts-mode on a rust file, I found treesitter is easy
>>> to make emacs buffer to lost color.
>>> For example, on the following rust code:
>>> ```rust
>>>
>>> struct Dog {
>>>    name: String,
>>>    age: u8,
>>> }
>>>
>>>
>>> struct ManyStruct {
>>>    a: u8,
>>> }
>>>
>>> fn many_code(){
>>>    fn fib(n: u32) -> u32 {
>>>        if n == 0 {
>>>            return 0;
>>>        }
>>>        if n == 1 {
>>>            return 1;
>>>        }
>>>        fib(n - 1) + fib(n - 2)
>>>    }
>>> }
>>>
>>> fn main() {
>>>    // change below `//` to `/` to see the difference
>>>    // {
>>> }
>>> ```
>>>
>>> the rust code is right, and the emacs buffer color is right on every
>>> struct/functions.
>>> But, if I change `// {` to `/ {`, then the rust code is wrong, this
>>> buffer will lost all colors.
>>
>> Thanks for reporting this.
>>
>> I attempted to reproduce this, using your example, when I change `// {`
>> to `/{` only "main" from `fn main()` loses color. The rest of the syntax
>> highlighting remains intact in my setup.
>
> It’s indeed strange to see the whole buffer lost fontification. I don’t see it either.

Eval Exec, are there any steps missing in the recipe to reproduce this?

Can you reproduce it starting from emacs -Q?




Added tag(s) moreinfo. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 02 Mar 2025 04:22:02 GMT) Full text and rfc822 format available.

Severity set to 'minor' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 02 Mar 2025 04:22:03 GMT) Full text and rfc822 format available.

This bug report was last modified 202 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.