unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Vincenzo Pupillo <v.pupillo@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: treesit-range-settings with ':local' : I missed something or it's a bug?
Date: Sat, 27 Jan 2024 23:09:02 -0800	[thread overview]
Message-ID: <D850EA6B-66BA-40D4-9029-613911A412FE@gmail.com> (raw)
In-Reply-To: <10408919.nUPlyArG6x@fedora>



> On Jan 27, 2024, at 2:23 AM, Vincenzo Pupillo <v.pupillo@gmail.com> wrote:
> 
> No. I defined a function for "treesit-language-at", which works correctly 
> without tree-sitter-phodoc parser (the version without phpdoc is here https://
> github.com/vpxyz/php-ts-mode)
> I find two problems: 
> 1. treesit-range-rules does not reset the variable "local" at the end of pcase 
> as it does with "host", "embed" and "offset". If there is a parser with the 
> :local attribute, all parsers defined after it are marked as :local 
> Without fix: 
> treesit-range-settings is a variable defined in ‘~/Projects/Emacs/php-ts-mode/
> treesit.el’.
> 
> Its value is
> ((#<treesit-compiled-query> phpdoc t nil)
> (#<treesit-compiled-query> html t nil)
> (#<treesit-compiled-query> javascript t (1 . -1))
> (#<treesit-compiled-query> css t (1 . -1)))
> Local in buffer index4.php; global value is nil
> 
> with fix:
> treesit-range-settings is a variable defined in ‘~/Projects/Emacs/php-ts-mode/
> treesit.el’.
> 
> Its value is
> ((#<treesit-compiled-query> phpdoc t nil)
> (#<treesit-compiled-query> html nil nil)
> (#<treesit-compiled-query> javascript nil (1 . -1))
> (#<treesit-compiled-query> css nil (1 . -1)))
> Local in buffer index4.php; global value is nil

Thanks, I pushed a fix for it.

> 2.  treesit-font-lock-fontify-region: the variable "global-parser" is set with 
> all parsers defined, including local parsers. As result the root-nodes 
> variable, without fix are ("document node" is  a phpdoc node): 
> root-nodes (#<treesit-node document in 517-621> #<treesit-node document in 
> 672-810> #<treesit-node program in 1-1057> #<treesit-node program in 79-138> 
> #<treesit-node stylesheet in 167-223> #<treesit-node fragment in 1-271> 
> #<treesit-node document in 1-1057>)
> 
> with fix:  
> root-nodes (#<treesit-node document in 517-621> #<treesit-node document in 
> 672-810> #<treesit-node program in 1-1057> #<treesit-node program in 79-138> 
> #<treesit-node stylesheet in 167-223> #<treesit-node fragment in 1-271>)
> 
> you can see the difference in the attached screenshots.
> The patch I wrote is not a solution (it's trivial) . I think there are other 
> "moving parts" to take into account.
> 
> Thanks.

Actually, local parsers are not included in the return value of (treesit-parser-list). By default, treesit-parser-list returns all the parsers whose tag is nil, but all the local parsers carry a tag of ‘embedded. To actually return all the parsers in the buffer you need to use (treesit-parser-list nil nil t), ie, pass t to the TAG parameter. 

I pulled your php-ts-mode_phpdoc.el and played around with it. I found the root cause to be the call to 

(treesit-parser-create ‘phpdoc)

In the major mode body. This creates a global phpdoc parser that fontifies everything in doc face.

Removing that, plus the fix for #1 that I just pushed to master, should fix the font-lock problem you are observing.

I couldn’t fine the patch you mentioned in the thread so I don’t know if this is what your patch does.

Yuan


  reply	other threads:[~2024-01-28  7:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 11:15 treesit-range-settings with ':local' : I missed something or it's a bug? Vincenzo Pupillo
2024-01-25 12:21 ` Vincenzo Pupillo
2024-01-27  4:32 ` Yuan Fu
2024-01-27 10:23   ` Vincenzo Pupillo
2024-01-28  7:09     ` Yuan Fu [this message]
2024-01-29 14:04       ` Vincenzo Pupillo
2024-01-31  6:32         ` Yuan Fu
2024-01-31 20:05           ` Vincenzo Pupillo
2024-01-31 20:24             ` Yuan Fu

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=D850EA6B-66BA-40D4-9029-613911A412FE@gmail.com \
    --to=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=v.pupillo@gmail.com \
    /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).