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


[-- Attachment #1.1: Type: text/plain, Size: 2389 bytes --]

Hi Yuan,
In data domenica 28 gennaio 2024 08:09:02 CET, Yuan Fu ha scritto:
> 
> 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.
It seems to work, but just try to indent the entire buffer, and the problem 
reappears. Before indenting: 
((#<treesit-parser for html> ((1 . 271))) (#<treesit-parser for css> ((161 . 
223))) (#<treesit-parser for javascript> ((73 . 138))) (#<treesit-parser for 
php> nil) (#<treesit-parser for phpdoc> ((517 . 621))) (#<treesit-parser for 
phpdoc> ((672 . 810))) (#<treesit-parser for phpdoc> ((939 . 1032))) 
(#<treesit-parser for phpdoc> ((1157 . 1223))))

after indenting the whole buffer:

((#<treesit-parser for html> ((1 . 271))) (#<treesit-parser for css> ((161 . 
223))) (#<treesit-parser for javascript> ((73 . 138))) (#<treesit-parser for 
php> nil) (#<treesit-parser for phpdoc> ((517 . 621))) (#<treesit-parser for 
phpdoc> ((672 . 810))) (#<treesit-parser for phpdoc> ((939 . 1032))) 
(#<treesit-parser for phpdoc> ((1157 . 1223))) (#<treesit-parser for phpdoc> 
nil))
 
As you can see the list of parsers has changed, and the latest one is:
(#<treesit-parser for phpdoc> nil)  .

To reproduce the problem:
1. open a php file (for e.g. the php file attached)
2. Indent the entire buffer
3. add a comment line inside a document block

The attached screenshot shows the result.
> 
> I couldn’t fine the patch you mentioned in the thread so I don’t know if
> this is what your patch does.

The modification I attached (that's the one I was talking about that I forgot 
to attach) solves the problem, but downstream, not upstream (I am not familiar 
with how treesit.el works). 
> 
> Yuan
Thanks 

V.


[-- Attachment #1.2: tressit_indent_font-lock_issue.png --]
[-- Type: image/png, Size: 10731 bytes --]

[-- Attachment #1.3: 0001-Remove-local-parser-from-global-parser-list-when-fon.patch --]
[-- Type: text/x-patch, Size: 1870 bytes --]

From c84464e0a8e3d5086af8bf2ff8f510a503f13374 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <vincenzo.pupillo@unimi.it>
Date: Sun, 28 Jan 2024 21:17:51 +0100
Subject: [PATCH] Remove local-parser from global-parser list when fontify
 region

The list of global parsers used by treesit-font-lock-fontify-region
also contains local parsers (parsers embedded with the :local
attribute). As a result, the font-lock range of local parsers overlaps
with others.

* lisp/treesit.el (treesit-font-lock-fontify-region): Drop local
parsers from the global-parsers list.
---
 lisp/treesit.el | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 96222ed81cb..47f06c37793 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1233,7 +1233,20 @@ treesit-font-lock-fontify-region
   (treesit-update-ranges start end)
   (font-lock-unfontify-region start end)
   (let* ((local-parsers (treesit-local-parsers-on start end))
-         (global-parsers (treesit-parser-list))
+         (global-parsers (cl-remove-if
+                          (lambda (parser)
+                            (let ((range-settings treesit-range-settings)
+                                  (finded nil))
+                              (while (and range-settings (not finded))
+                                (let* ((range-setting (pop range-settings))
+                                       (language (nth 1 range-setting))
+                                       (local (nth 2 range-setting)))
+                                  (setq finded
+					(and
+					 local
+					 (eq (treesit-parser-language parser) language)))))
+			      finded))
+                          (treesit-parser-list)))
          (root-nodes
           (mapcar #'treesit-parser-root-node
                   (append local-parsers global-parsers))))
-- 
2.43.0


[-- Attachment #1.4: index4.php --]
[-- Type: application/x-php, Size: 1285 bytes --]

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-01-29 14:04 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
2024-01-29 14:04       ` Vincenzo Pupillo [this message]
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=3273091.aeNJFYEL58@fedora \
    --to=v.pupillo@gmail.com \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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).