Subject: bug#74525: closed (Re: bug#74525: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation.)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 29 Nov 2024 04:51:02 +0000

Your bug report

#74525: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation.

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
74525: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=74525
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#74525: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation.
From: Yuan Fu <[email-masked]>
To: Vincenzo Pupillo <[email-masked]>
Cc: [email-masked]
Date: Thu, 28 Nov 2024 20:49:07 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

> On Nov 27, 2024, at 1:12 AM, Vincenzo Pupillo <[email-masked]> wrote:
> 
> Please consider this patch and discard the previous one.
> 
> Thank you.
> Vincenzo
> 
> In data lunedì 25 novembre 2024 11:45:47 Ora standard dell’Europa centrale, Vincenzo Pupillo ha scritto:
>> Ciao,
>> PHP 8.4 has just been released. This patch supports a feature just introduced
>> in tree-sitter-php, the 'property_hook'.
>> It also improves both indentation and syntax highlighting of CSS and 
>> JavaScript blocks.
>> 
>> Thank you.
>> 
>> Vincenzo
From 358c14128943e3fa1e76439e5cab51979c6c677d Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 25 Nov 2024 11:06:02 +0100
Subject: [PATCH] Improved support for PHP 8.4 and more reliable indentation.

Added support for PHP 8.4 property hook. More reliable CSS and
Javascript syntax indentation when there are attributes in <script> and
<style>.

* lisp/progmodes/php-ts-mode.el
(php-ts-mode--language-source-alist): Switch to the latest php grammar.
(php-ts-mode--js-css-tag-bol): CSS and Javascript indentation is now
more more reliable in different formatting styles.
(php-ts-mode--test-property-hook-clause-p): New function that tests
property_hook support.
(php-ts-mode--font-lock-settings): Use the new function.
(php-ts-mode--colorize-css-value): The function now behaves exactly like
the one in css-ts-mode.
(php-ts-mode--feature-list): Changed the list to match css-ts-mode.
---
 lisp/progmodes/php-ts-mode.el | 48 +++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index f9fd03cbf72..6052c79ccf3 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -84,7 +84,7 @@
 
 ;;; Install treesitter language parsers
 (defvar php-ts-mode--language-source-alist
-  '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.23.5" "php/src"))
+  '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.23.11" "php/src"))
     (phpdoc . ("https://github.com/claytonrcarter/tree-sitter-phpdoc"))
     (html . ("https://github.com/tree-sitter/tree-sitter-html"  "v0.23.0"))
     (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.0"))
@@ -477,16 +477,20 @@ php-ts-mode--first-sibling
               (treesit-node-start parent)
               (line-end-position))))))
 
-(defun php-ts-mode--js-css-tag-bol (node _parent &rest _)
+(defun php-ts-mode--js-css-tag-bol (_node parent &rest _)
   "Find the first non-space characters of html tags <script> or <style>.
 
-If NODE is nil return `line-beginning-position'.  PARENT is ignored.
-NODE is the node to match and PARENT is its parent."
-  (if (null node)
-      (line-beginning-position)
-    (save-excursion
-      (goto-char (treesit-node-start node))
-      (re-search-backward "<script>\\|<style>" nil t))))
+Return `line-beginning-position' when `treesit-node-at' is HTML or PHP.
+Otherwise go to the PARENT and search backward for <script> or <style> tags.
+Should be used only for Javascript or CSS indenting rules.
+NODE, ignored, is the node to match and PARENT is its parent."
+  (let ((lang (treesit-language-at (point))))
+    (if (or (eq lang 'javascript)
+	    (eq lang 'css))
+	(save-excursion
+	  (goto-char (treesit-node-start parent))
+	  (re-search-backward "<script.*>\\|<style.*>" nil t))
+      (line-beginning-position))))
 
 (defun php-ts-mode--parent-eol (_node parent &rest _)
   "Find the last non-space characters of the PARENT of the current NODE.
@@ -840,6 +844,11 @@ php-ts-mode--test-visibility-modifier-operation-clause-p
   (ignore-errors
     (progn (treesit-query-compile 'php "(visibility_modifier (operation))" t) t)))
 
+(defun php-ts-mode--test-property-hook-clause-p ()
+  "Return t if property_hook is a named node, nil otherwise."
+  (ignore-errors
+    (progn (treesit-query-compile 'php "(property_hook)" t) t)))
+
 (defun php-ts-mode--font-lock-settings ()
   "Tree-sitter font-lock settings."
   (treesit-font-lock-rules
@@ -948,6 +957,8 @@ php-ts-mode--font-lock-settings
       name: (_) @font-lock-type-face)
      (function_definition
       name: (_) @font-lock-function-name-face)
+     ,@(when (php-ts-mode--test-property-hook-clause-p)
+	 '((property_hook (name) @font-lock-function-name-face)))
      (method_declaration
       name: (_) @font-lock-function-name-face)
      (method_declaration
@@ -1108,14 +1119,13 @@ php-ts-mode--colorize-css-value
            (string-equal "plain_value" (treesit-node-type node)))
       (let ((color (css--compute-color start (treesit-node-text node t))))
         (when color
-          (treesit-fontify-with-override
-           (treesit-node-start node) (treesit-node-end node)
-           (list 'face
-                 (list :background color
-                       :foreground (readable-foreground-color
-                                    color)
-                       :box '(:line-width -1)))
-           override start end)))
+	  (with-silent-modifications
+	    (add-text-properties
+	     (treesit-node-start node) (treesit-node-end node)
+	     (list 'face (list :background color
+			       :foreground (readable-foreground-color
+                                            color)
+			       :box '(:line-width -1)))))))
     (treesit-fontify-with-override
      (treesit-node-start node) (treesit-node-end node)
      'font-lock-variable-name-face
@@ -1372,14 +1382,14 @@ php-ts-mode--feature-list
      ;; PHPDOC specific
      document
      phpdoc-error)
-    (keyword string type name)
+    (keyword string property type name)
     (;; common
      attribute assignment constant escape-sequence function-scope
      base-clause literal variable-name variable
      ;; Javascript specific
      jsx number pattern string-interpolation)
     (;; common
-     argument bracket delimiter error function-call operator property
+     argument bracket delimiter error function-call operator
      ;; Javascript specific
      function)))
 
-- 
2.47.0

Thanks! Since this is all fixes. I pushed to emacs-30.

Yuan

Subject: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation.
From: Vincenzo Pupillo <[email-masked]>
To: [email-masked]
Date: Mon, 25 Nov 2024 11:45:47 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Ciao,
PHP 8.4 has just been released. This patch supports a feature just introduced
in tree-sitter-php, the 'property_hook'.
It also improves both indentation and syntax highlighting of CSS and 
JavaScript blocks.

Thank you.

Vincenzo

>From ec8a2e49bae788a98147bbfaff460f12e29b5901 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 25 Nov 2024 11:06:02 +0100
Subject: [PATCH] Improved support for PHP 8.4 and more reliable indentation.

Added support for PHP 8.4 property hook. More reliable CSS and
Javascript syntax indentation and highlighting.

* lisp/progmodes/php-ts-mode.el
(php-ts-mode--language-source-alist): Switch to the latest php grammar.
(php-ts-mode--js-css-tag-bol): CSS and Javascript indentation is now
more more reliable in different formatting styles.
(php-ts-mode--test-property-hook-clause-p): New function that tests
property_hook support.
(php-ts-mode--font-lock-settings): Use the new function.
(php-ts-mode--colorize-css-value): The function now behaves exactly like
the one in css-ts-mode.
(php-ts-mode--feature-list): Changed the list to match css-ts-mode.
---
 lisp/progmodes/php-ts-mode.el | 48 +++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index f9fd03cbf72..d090c068d31 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -84,7 +84,7 @@
 
 ;;; Install treesitter language parsers
 (defvar php-ts-mode--language-source-alist
-  '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.23.5" "php/src"))
+  '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.23.11" "php/src"))
     (phpdoc . ("https://github.com/claytonrcarter/tree-sitter-phpdoc"))
     (html . ("https://github.com/tree-sitter/tree-sitter-html"  "v0.23.0"))
     (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.0"))
@@ -477,16 +477,20 @@ php-ts-mode--first-sibling
               (treesit-node-start parent)
               (line-end-position))))))
 
-(defun php-ts-mode--js-css-tag-bol (node _parent &rest _)
+(defun php-ts-mode--js-css-tag-bol (_node parent &rest _)
   "Find the first non-space characters of html tags <script> or <style>.
 
-If NODE is nil return `line-beginning-position'.  PARENT is ignored.
-NODE is the node to match and PARENT is its parent."
-  (if (null node)
-      (line-beginning-position)
-    (save-excursion
-      (goto-char (treesit-node-start node))
-      (re-search-backward "<script>\\|<style>" nil t))))
+Return `line-beginning-position' when `treesit-node-at' is HTML or PHP.
+Otherwise go to the PARENT and search backward for <script> or <style> tags.
+Should be used only for Javascript or CSS indenting rules.
+NODE, ignored, is the node to match and PARENT is its parent."
+  (let ((lang (treesit-language-at (point))))
+    (if (or (eq lang 'javascript)
+	    (eq lang 'css))
+	(save-excursion
+	  (goto-char (treesit-node-start parent))
+	  (re-search-backward "<script>\\|<style>" nil t))
+      (line-beginning-position))))
 
 (defun php-ts-mode--parent-eol (_node parent &rest _)
   "Find the last non-space characters of the PARENT of the current NODE.
@@ -840,6 +844,11 @@ php-ts-mode--test-visibility-modifier-operation-clause-p
   (ignore-errors
     (progn (treesit-query-compile 'php "(visibility_modifier (operation))" t) t)))
 
+(defun php-ts-mode--test-property-hook-clause-p ()
+  "Return t if property_hook is a named node, nil otherwise."
+  (ignore-errors
+    (progn (treesit-query-compile 'php "(property_hook)" t) t)))
+
 (defun php-ts-mode--font-lock-settings ()
   "Tree-sitter font-lock settings."
   (treesit-font-lock-rules
@@ -948,6 +957,8 @@ php-ts-mode--font-lock-settings
       name: (_) @font-lock-type-face)
      (function_definition
       name: (_) @font-lock-function-name-face)
+     ,@(when (php-ts-mode--test-property-hook-clause-p)
+	 '((property_hook (name) @font-lock-function-name-face)))
      (method_declaration
       name: (_) @font-lock-function-name-face)
      (method_declaration
@@ -1108,14 +1119,13 @@ php-ts-mode--colorize-css-value
            (string-equal "plain_value" (treesit-node-type node)))
       (let ((color (css--compute-color start (treesit-node-text node t))))
         (when color
-          (treesit-fontify-with-override
-           (treesit-node-start node) (treesit-node-end node)
-           (list 'face
-                 (list :background color
-                       :foreground (readable-foreground-color
-                                    color)
-                       :box '(:line-width -1)))
-           override start end)))
+	  (with-silent-modifications
+	    (add-text-properties
+	     (treesit-node-start node) (treesit-node-end node)
+	     (list 'face (list :background color
+			       :foreground (readable-foreground-color
+                                            color)
+			       :box '(:line-width -1)))))))
     (treesit-fontify-with-override
      (treesit-node-start node) (treesit-node-end node)
      'font-lock-variable-name-face
@@ -1372,14 +1382,14 @@ php-ts-mode--feature-list
      ;; PHPDOC specific
      document
      phpdoc-error)
-    (keyword string type name)
+    (keyword string property type name)
     (;; common
      attribute assignment constant escape-sequence function-scope
      base-clause literal variable-name variable
      ;; Javascript specific
      jsx number pattern string-interpolation)
     (;; common
-     argument bracket delimiter error function-call operator property
+     argument bracket delimiter error function-call operator
      ;; Javascript specific
      function)))
 
-- 
2.47.0