all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Vincenzo Pupillo <v.pupillo@gmail.com>
To: emacs-devel@gnu.org
Subject: treesit-range-settings with ':local' : I missed something or it's a bug?
Date: Thu, 11 Jan 2024 12:15:24 +0100	[thread overview]
Message-ID: <6107698.MhkbZ0Pkbq@3-191.divsi.unimi.it> (raw)

Hi, 
in the php-ts-mode I am writing, I am trying to use the tree-sitter-phpdoc parser 
(I had tried before but without success, and I currently use a font block based 
on regular expressions). 
tree-sitter-phpdoc requires a single doc block (a single /** */ doc block and 
nothing else, no /* */ or #). I wrote these range rules:
(setq-local treesit-range-settings
		      (treesit-range-rules
		       :embed 'phpdoc
		       :host 'php
		       :local t
		       '(((comment) @cap
			 (:match "/\\*\\*" @cap)))

		       :embed 'html
		       :host 'php
		       '((program (text) @cap)
			 (text_interpolation (text) @cap))

		       :embed 'javascript
		       :host 'html
		       :offset '(1 . -1)
		       '((script_element
			  (start_tag (tag_name))
			  (raw_text) @cap))

		       :embed 'css
		       :host 'html
		       :offset '(1 . -1)
		       '((style_element
			  (start_tag (tag_name))
			  (raw_text) @cap))))

With html, js and css it works fine. With phpdoc I tried with or without :local. 
Without :local the parse intervals are all null. Without :local on the other hand they are correct.
With this simple php snippet:
<?php

/**
 * Test class
 * @author v <v.pupillo@gmail.com>
 */
class Test {
    /** @see http://example.com the lib */
    function test() {
	echo "prova";
    }
}

Without :local the field rules are:
((#<treesit-parser for phpdoc> ((1 . 1) (8 . 64) (82 . 120))) (#<treesit-
parser for html> ((1 . 1) (1 . 2))) (#<treesit-parser for css> ((1 . 1))) 
(#<treesit-parser for javascript> ((1 . 1))) (#<treesit-parser for php> nil))

With :local the result is:
((#<treesit-parser for phpdoc> nil) (#<treesit-parser for html> nil) 
(#<treesit-parser for css> nil) (#<treesit-parser for javascript> nil) 
(#<treesit-parser for php> nil))


With :local the treesit-language-at breaks, and js or css rules 
are also applied to php code :-(

I tried tracking the node location sent from the parser to the font-lock-rules I wrote for phpdoc, 
with :local the result is:

phpdoc-block node-start= 8 node-end= 64 start= 1 end= 166
phpdoc-block node-start= 82 node-end= 120 start= 1 end= 166
phpdoc-block node-start= 1 node-end= 166 start= 1 end= 166

the first two are right, the last one is not.

Any idea?
Tested with:
GNU Emacs 30.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.39, cairo version 1.18.0) of 2024-01-11


Thanks

p.s. the function I wrote to get the ranges is:
(defun php-ts-mode--get-parser-ranges ()
  "Return the ranges covered by the parsers.

`php-ts-mode' use 5 parsers, this function returns, for the
current buffer, the ranges covered by each parser.
Usefull for debugging."
  (let ((ranges))
    (if (not (treesit-parser-list))
	(message "At least one parser must be initialized"))
    (cl-loop
     for parser in (treesit-parser-list)
     do (push (list parser (treesit-parser-included-ranges parser)) ranges)
     finally return ranges)))






             reply	other threads:[~2024-01-11 11:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 11:15 Vincenzo Pupillo [this message]
2024-01-25 12:21 ` treesit-range-settings with ':local' : I missed something or it's a bug? 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
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

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

  git send-email \
    --in-reply-to=6107698.MhkbZ0Pkbq@3-191.divsi.unimi.it \
    --to=v.pupillo@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 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.