diff options
| author | Roi Martin | 2025-09-21 20:07:12 +0200 |
|---|---|---|
| committer | Juri Linkov | 2025-09-22 18:11:39 +0300 |
| commit | 85c42b3a87dde7ce9bd375e89dd70fcdc9d03dba (patch) | |
| tree | 3182d1d3a4ac31f2876ffaffbd00ebb07978e6e3 | |
| parent | 77ca60b48d018425c95c110b4c736cddd2d1d336 (diff) | |
| download | emacs-85c42b3a87dde7ce9bd375e89dd70fcdc9d03dba.tar.gz emacs-85c42b3a87dde7ce9bd375e89dd70fcdc9d03dba.zip | |
Fix font lock in php-ts-mode
Fix font lock in php-ts-mode when the tree-sitter grammars are
automatically installed. Also, update php-ts-mode to call the new
`mhtml-ts-mode--treesit-font-lock-settings' function.
* lisp/progmodes/php-ts-mode.el (php-ts-mode--keywords)
(php-ts-mode--operators): Generate the lists after the tree-sitter
grammars are installed.
(php-ts-mode--font-lock-settings, php-ts-mode--font-lock-settings-cached)
(php-ts-mode--custom-html-font-lock-settings)
(php-ts-mode--custom-html-font-lock-settings-cached): Evaluate the rules
after the tree-sitter grammars are installed. Also, add cache for the
rules.
(php-ts-mode): Call the new
`php-ts-mode--custom-html-font-lock-settings' function. (Bug#79363)
| -rw-r--r-- | lisp/progmodes/php-ts-mode.el | 498 |
1 files changed, 256 insertions, 242 deletions
diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el index 0e3bf324b43..fd5727b0f00 100644 --- a/lisp/progmodes/php-ts-mode.el +++ b/lisp/progmodes/php-ts-mode.el | |||
| @@ -888,31 +888,29 @@ characters of the current line." | |||
| 888 | "Return t if the operator '|>' is defined, nil otherwise." | 888 | "Return t if the operator '|>' is defined, nil otherwise." |
| 889 | (treesit-query-valid-p 'php '("|>"))) | 889 | (treesit-query-valid-p 'php '("|>"))) |
| 890 | 890 | ||
| 891 | (defvar php-ts-mode--keywords | 891 | (defun php-ts-mode--keywords () |
| 892 | (when (treesit-available-p) | 892 | "PHP keywords for tree-sitter font-locking." |
| 893 | (append | 893 | (append |
| 894 | '("abstract" "and" "array" "as" "break" "case" "catch" | 894 | '("abstract" "and" "array" "as" "break" "case" "catch" |
| 895 | "class" "clone" "const" "continue" "declare" "default" "do" "echo" | 895 | "class" "clone" "const" "continue" "declare" "default" "do" "echo" |
| 896 | "else" "elseif" "enddeclare" "endfor" "endforeach" "endif" | 896 | "else" "elseif" "enddeclare" "endfor" "endforeach" "endif" |
| 897 | "endswitch" "endwhile" "enum" "exit" "extends" "final" "finally" "fn" | 897 | "endswitch" "endwhile" "enum" "exit" "extends" "final" "finally" "fn" |
| 898 | "for" "foreach" "function" "global" "goto" "if" "implements" | 898 | "for" "foreach" "function" "global" "goto" "if" "implements" |
| 899 | "include" "include_once" "instanceof" "insteadof" "interface" | 899 | "include" "include_once" "instanceof" "insteadof" "interface" |
| 900 | "list" "match" "namespace" "new" "null" "or" "print" "private" | 900 | "list" "match" "namespace" "new" "null" "or" "print" "private" |
| 901 | "protected" "public" "readonly" "require" "require_once" "return" | 901 | "protected" "public" "readonly" "require" "require_once" "return" |
| 902 | "static" "switch" "throw" "trait" "try" "unset" "use" "while" "xor" | 902 | "static" "switch" "throw" "trait" "try" "unset" "use" "while" "xor" |
| 903 | "yield") | 903 | "yield") |
| 904 | (if (php-ts-mode--test-yield-from-p) '("yield from") '("from")))) | 904 | (if (php-ts-mode--test-yield-from-p) '("yield from") '("from")))) |
| 905 | "PHP keywords for tree-sitter font-locking.") | 905 | |
| 906 | 906 | (defun php-ts-mode--operators () | |
| 907 | (defvar php-ts-mode--operators | 907 | "PHP operators for tree-sitter font-locking." |
| 908 | (when (treesit-available-p) | 908 | (append |
| 909 | (append | 909 | '("--" "**=" "*=" "/=" "%=" "+=" "-=" ".=" "<<=" ">>=" "&=" "^=" |
| 910 | '("--" "**=" "*=" "/=" "%=" "+=" "-=" ".=" "<<=" ">>=" "&=" "^=" | 910 | "|=" "??" "??=" "||" "&&" "|" "^" "&" "==" "!=" "<>" "===" "!==" |
| 911 | "|=" "??" "??=" "||" "&&" "|" "^" "&" "==" "!=" "<>" "===" "!==" | 911 | "<" ">" "<=" ">=" "<=>" "<<" ">>" "+" "-" "." "*" "**" "/" "%" |
| 912 | "<" ">" "<=" ">=" "<=>" "<<" ">>" "+" "-" "." "*" "**" "/" "%" | 912 | "->" "?->" "...") |
| 913 | "->" "?->" "...") | 913 | (when (php-ts-mode--test-pipe-p) '("|>")))) |
| 914 | (when (php-ts-mode--test-pipe-p) '("|>")))) | ||
| 915 | "PHP operators for tree-sitter font-locking.") | ||
| 916 | 914 | ||
| 917 | (defconst php-ts-mode--predefined-constant | 915 | (defconst php-ts-mode--predefined-constant |
| 918 | '(;; predefined constant | 916 | '(;; predefined constant |
| @@ -957,228 +955,244 @@ characters of the current line." | |||
| 957 | ("::" . ?∷)) | 955 | ("::" . ?∷)) |
| 958 | "Value for `prettify-symbols-alist' in `php-ts-mode'.") | 956 | "Value for `prettify-symbols-alist' in `php-ts-mode'.") |
| 959 | 957 | ||
| 960 | (defun php-ts-mode--font-lock-settings () | 958 | (defvar php-ts-mode--font-lock-settings-cached nil |
| 961 | "Tree-sitter font-lock settings." | 959 | "Cached tree-sitter font-lock settings for `php-ts-mode'.") |
| 962 | (treesit-font-lock-rules | ||
| 963 | |||
| 964 | :language 'php | ||
| 965 | :feature 'keyword | ||
| 966 | :override t | ||
| 967 | `([,@php-ts-mode--keywords] @font-lock-keyword-face | ||
| 968 | ,@(when (php-ts-mode--test-visibility-modifier-operation-p) | ||
| 969 | '((visibility_modifier (operation) @font-lock-builtin-face))) | ||
| 970 | (var_modifier) @font-lock-builtin-face) | ||
| 971 | |||
| 972 | :language 'php | ||
| 973 | :feature 'comment | ||
| 974 | :override t | ||
| 975 | '((comment) @font-lock-comment-face) | ||
| 976 | |||
| 977 | :language 'php | ||
| 978 | :feature 'constant | ||
| 979 | `((boolean) @font-lock-constant-face | ||
| 980 | (null) @font-lock-constant-face | ||
| 981 | ;; predefined constant or built in constant (part of PHP core) | ||
| 982 | ((name) @font-lock-builtin-face | ||
| 983 | (:match ,(rx-to-string | ||
| 984 | `(: bos (or ,@php-ts-mode--predefined-constant) eos)) | ||
| 985 | @font-lock-builtin-face)) | ||
| 986 | ;; user defined constant | ||
| 987 | ((name) @font-lock-constant-face | ||
| 988 | (:match "\\`_*[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face)) | ||
| 989 | (const_declaration | ||
| 990 | (const_element (name) @font-lock-constant-face)) | ||
| 991 | ;; declare directive | ||
| 992 | (declare_directive ["strict_types" "encoding" "ticks"] @font-lock-constant-face)) | ||
| 993 | |||
| 994 | :language 'php | ||
| 995 | :feature 'name | ||
| 996 | '((goto_statement (name) @font-lock-constant-face) | ||
| 997 | (named_label_statement (name) @font-lock-constant-face)) | ||
| 998 | |||
| 999 | :language 'php | ||
| 1000 | :feature 'delimiter | ||
| 1001 | `((["," ":" ";" "\\"]) @font-lock-delimiter-face) | ||
| 1002 | |||
| 1003 | :language 'php | ||
| 1004 | :feature 'operator | ||
| 1005 | `((error_suppression_expression "@" @font-lock-keyword-face) | ||
| 1006 | [,@php-ts-mode--operators] @font-lock-operator-face) | ||
| 1007 | |||
| 1008 | :language 'php | ||
| 1009 | :feature 'variable-name | ||
| 1010 | :override t | ||
| 1011 | '(((name) @font-lock-keyword-face (:equal "this" @font-lock-keyword-face)) | ||
| 1012 | (variable_name (name) @font-lock-variable-name-face) | ||
| 1013 | (relative_scope ["parent" "self" "static"] @font-lock-builtin-face) | ||
| 1014 | (relative_scope) @font-lock-constant-face | ||
| 1015 | (dynamic_variable_name (name) @font-lock-variable-name-face) | ||
| 1016 | (member_access_expression | ||
| 1017 | name: (_) @font-lock-variable-name-face) | ||
| 1018 | (scoped_property_access_expression | ||
| 1019 | scope: (name) @font-lock-constant-face) | ||
| 1020 | (nullsafe_member_access_expression (name) @font-lock-variable-name-face) | ||
| 1021 | (error_suppression_expression (name) @font-lock-property-name-face)) | ||
| 1022 | |||
| 1023 | :language 'php | ||
| 1024 | :feature 'string | ||
| 1025 | `(("\"") @font-lock-string-face | ||
| 1026 | (encapsed_string) @font-lock-string-face | ||
| 1027 | (string_content) @font-lock-string-face | ||
| 1028 | (string) @font-lock-string-face) | ||
| 1029 | |||
| 1030 | :language 'php | ||
| 1031 | :feature 'literal | ||
| 1032 | '((integer) @font-lock-number-face | ||
| 1033 | (float) @font-lock-number-face | ||
| 1034 | (heredoc identifier: (heredoc_start) @font-lock-constant-face) | ||
| 1035 | (heredoc_body (string_content) @font-lock-string-face) | ||
| 1036 | (heredoc end_tag: (heredoc_end) @font-lock-constant-face) | ||
| 1037 | (nowdoc identifier: (heredoc_start) @font-lock-constant-face) | ||
| 1038 | (nowdoc_body (nowdoc_string) @font-lock-string-face) | ||
| 1039 | (nowdoc end_tag: (heredoc_end) @font-lock-constant-face) | ||
| 1040 | (shell_command_expression) @font-lock-string-face) | ||
| 1041 | |||
| 1042 | :language 'php | ||
| 1043 | :feature 'type | ||
| 1044 | :override t | ||
| 1045 | '((union_type "|" @font-lock-operator-face) | ||
| 1046 | (union_type) @font-lock-type-face | ||
| 1047 | (bottom_type) @font-lock-type-face | ||
| 1048 | (primitive_type) @font-lock-type-face | ||
| 1049 | ((primitive_type) @font-lock-keyword-face | ||
| 1050 | (:equal "callable" @font-lock-keyword-face)) | ||
| 1051 | (cast_type) @font-lock-type-face | ||
| 1052 | (named_type) @font-lock-type-face | ||
| 1053 | (optional_type) @font-lock-type-face) | ||
| 1054 | |||
| 1055 | :language 'php | ||
| 1056 | :feature 'definition | ||
| 1057 | :override t | ||
| 1058 | `((php_tag) @font-lock-preprocessor-face | ||
| 1059 | ,@(if (php-ts-mode--test-php-end-tag-p) | ||
| 1060 | '((php_end_tag) @font-lock-preprocessor-face) | ||
| 1061 | '(("?>") @font-lock-preprocessor-face)) | ||
| 1062 | ;; Highlights identifiers in declarations. | ||
| 1063 | (class_declaration | ||
| 1064 | name: (_) @font-lock-type-face) | ||
| 1065 | (class_interface_clause (name) @font-lock-type-face) | ||
| 1066 | (interface_declaration | ||
| 1067 | name: (_) @font-lock-type-face) | ||
| 1068 | (trait_declaration | ||
| 1069 | name: (_) @font-lock-type-face) | ||
| 1070 | (enum_declaration | ||
| 1071 | name: (_) @font-lock-type-face) | ||
| 1072 | (function_definition | ||
| 1073 | name: (_) @font-lock-function-name-face) | ||
| 1074 | ,@(when (php-ts-mode--test-property-hook-p) | ||
| 1075 | '((property_hook (name) @font-lock-function-name-face))) | ||
| 1076 | (method_declaration | ||
| 1077 | name: (_) @font-lock-function-name-face) | ||
| 1078 | (method_declaration | ||
| 1079 | name: (name) @font-lock-builtin-face | ||
| 1080 | (:match ,(rx-to-string | ||
| 1081 | `(: bos (or ,@php-ts-mode--class-magic-methods) eos)) | ||
| 1082 | @font-lock-builtin-face)) | ||
| 1083 | ("=>") @font-lock-keyword-face | ||
| 1084 | (object_creation_expression | ||
| 1085 | (name) @font-lock-type-face) | ||
| 1086 | ,@(when (php-ts-mode--test-namespace-name-as-prefix-p) | ||
| 1087 | '((namespace_name_as_prefix "\\" @font-lock-delimiter-face) | ||
| 1088 | (namespace_name_as_prefix | ||
| 1089 | (namespace_name (name)) @font-lock-type-face))) | ||
| 1090 | ,@(if (php-ts-mode--test-namespace-aliasing-clause-p) | ||
| 1091 | '((namespace_aliasing_clause (name) @font-lock-type-face)) | ||
| 1092 | '((namespace_use_clause alias: (name) @font-lock-type-face))) | ||
| 1093 | ,@(when (not (php-ts-mode--test-namespace-use-group-clause-p)) | ||
| 1094 | '((namespace_use_group | ||
| 1095 | (namespace_use_clause (name) @font-lock-type-face)))) | ||
| 1096 | (namespace_use_clause (name) @font-lock-type-face) | ||
| 1097 | (namespace_name "\\" @font-lock-delimiter-face) | ||
| 1098 | (namespace_name (name) @font-lock-type-face) | ||
| 1099 | (use_declaration (name) @font-lock-property-use-face) | ||
| 1100 | (use_instead_of_clause (name) @font-lock-type-face) | ||
| 1101 | (binary_expression | ||
| 1102 | operator: "instanceof" | ||
| 1103 | right: (name) @font-lock-type-face)) | ||
| 1104 | |||
| 1105 | :language 'php | ||
| 1106 | :feature 'function-scope | ||
| 1107 | :override t | ||
| 1108 | '((scoped_call_expression | ||
| 1109 | scope: (name) @font-lock-constant-face) | ||
| 1110 | (class_constant_access_expression (name) @font-lock-constant-face)) | ||
| 1111 | 960 | ||
| 1112 | :language 'php | 961 | (defun php-ts-mode--font-lock-settings () |
| 1113 | :feature 'function-call | 962 | "Return tree-sitter font-lock settings for `php-ts-mode'. |
| 1114 | :override t | 963 | |
| 1115 | '((function_call_expression | 964 | Tree-sitter font-lock settings are evaluated the first time this |
| 1116 | function: (name) @font-lock-function-call-face) | 965 | function is called. Subsequent calls return the first evaluated value." |
| 1117 | (scoped_call_expression | 966 | (or php-ts-mode--font-lock-settings-cached |
| 1118 | name: (name) @font-lock-function-call-face) | 967 | (setq php-ts-mode--font-lock-settings-cached |
| 1119 | (member_call_expression | 968 | (treesit-font-lock-rules |
| 1120 | name: (name) @font-lock-function-call-face) | 969 | |
| 1121 | (nullsafe_member_call_expression | 970 | :language 'php |
| 1122 | name: (_) @font-lock-function-call-face)) | 971 | :feature 'keyword |
| 1123 | 972 | :override t | |
| 1124 | :language 'php | 973 | `([,@(php-ts-mode--keywords)] @font-lock-keyword-face |
| 1125 | :feature 'argument | 974 | ,@(when (php-ts-mode--test-visibility-modifier-operation-p) |
| 1126 | '((argument | 975 | '((visibility_modifier (operation) @font-lock-builtin-face))) |
| 1127 | name: (_) @font-lock-constant-face)) | 976 | (var_modifier) @font-lock-builtin-face) |
| 1128 | 977 | ||
| 1129 | :language 'php | 978 | :language 'php |
| 1130 | :feature 'escape-sequence | 979 | :feature 'comment |
| 1131 | :override t | 980 | :override t |
| 1132 | '((string (escape_sequence) @font-lock-escape-face) | 981 | '((comment) @font-lock-comment-face) |
| 1133 | (encapsed_string (escape_sequence) @font-lock-escape-face) | 982 | |
| 1134 | (heredoc_body (escape_sequence) @font-lock-escape-face)) | 983 | :language 'php |
| 1135 | 984 | :feature 'constant | |
| 1136 | :language 'php | 985 | `((boolean) @font-lock-constant-face |
| 1137 | :feature 'base-clause | 986 | (null) @font-lock-constant-face |
| 1138 | :override t | 987 | ;; predefined constant or built in constant (part of PHP core) |
| 1139 | `((base_clause (name) @font-lock-type-face) | 988 | ((name) @font-lock-builtin-face |
| 1140 | (use_as_clause (name) @font-lock-property-use-face) | 989 | (:match ,(rx-to-string |
| 1141 | ,@(when (not (php-ts-mode--test-namespace-name-as-prefix-p)) | 990 | `(: bos (or ,@php-ts-mode--predefined-constant) eos)) |
| 1142 | '((qualified_name prefix: "\\" @font-lock-delimiter-face))) | 991 | @font-lock-builtin-face)) |
| 1143 | (qualified_name (name) @font-lock-constant-face) | 992 | ;; user defined constant |
| 1144 | ,@(when (php-ts-mode--test-relative-name-p) | 993 | ((name) @font-lock-constant-face |
| 1145 | '((relative_name (name) @font-lock-constant-face)))) | 994 | (:match "\\`_*[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face)) |
| 1146 | 995 | (const_declaration | |
| 1147 | :language 'php | 996 | (const_element (name) @font-lock-constant-face)) |
| 1148 | :feature 'property | 997 | ;; declare directive |
| 1149 | '((enum_case | 998 | (declare_directive ["strict_types" "encoding" "ticks"] @font-lock-constant-face)) |
| 1150 | name: (_) @font-lock-type-face)) | 999 | |
| 1151 | 1000 | :language 'php | |
| 1152 | :language 'php | 1001 | :feature 'name |
| 1153 | :feature 'attribute | 1002 | '((goto_statement (name) @font-lock-constant-face) |
| 1154 | '((((attribute (_) @attribute_name) @font-lock-preprocessor-face) | 1003 | (named_label_statement (name) @font-lock-constant-face)) |
| 1155 | (:equal "Deprecated" @attribute_name)) | 1004 | |
| 1156 | (attribute_group (attribute (name) @font-lock-constant-face))) | 1005 | :language 'php |
| 1157 | 1006 | :feature 'delimiter | |
| 1158 | :language 'php | 1007 | `((["," ":" ";" "\\"]) @font-lock-delimiter-face) |
| 1159 | :feature 'bracket | 1008 | |
| 1160 | '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) | 1009 | :language 'php |
| 1161 | 1010 | :feature 'operator | |
| 1162 | :language 'php | 1011 | `((error_suppression_expression "@" @font-lock-keyword-face) |
| 1163 | :feature 'error | 1012 | [,@(php-ts-mode--operators)] @font-lock-operator-face) |
| 1164 | :override t | 1013 | |
| 1165 | '((ERROR) @php-ts-mode--fontify-error))) | 1014 | :language 'php |
| 1015 | :feature 'variable-name | ||
| 1016 | :override t | ||
| 1017 | '(((name) @font-lock-keyword-face (:equal "this" @font-lock-keyword-face)) | ||
| 1018 | (variable_name (name) @font-lock-variable-name-face) | ||
| 1019 | (relative_scope ["parent" "self" "static"] @font-lock-builtin-face) | ||
| 1020 | (relative_scope) @font-lock-constant-face | ||
| 1021 | (dynamic_variable_name (name) @font-lock-variable-name-face) | ||
| 1022 | (member_access_expression | ||
| 1023 | name: (_) @font-lock-variable-name-face) | ||
| 1024 | (scoped_property_access_expression | ||
| 1025 | scope: (name) @font-lock-constant-face) | ||
| 1026 | (nullsafe_member_access_expression (name) @font-lock-variable-name-face) | ||
| 1027 | (error_suppression_expression (name) @font-lock-property-name-face)) | ||
| 1028 | |||
| 1029 | :language 'php | ||
| 1030 | :feature 'string | ||
| 1031 | `(("\"") @font-lock-string-face | ||
| 1032 | (encapsed_string) @font-lock-string-face | ||
| 1033 | (string_content) @font-lock-string-face | ||
| 1034 | (string) @font-lock-string-face) | ||
| 1035 | |||
| 1036 | :language 'php | ||
| 1037 | :feature 'literal | ||
| 1038 | '((integer) @font-lock-number-face | ||
| 1039 | (float) @font-lock-number-face | ||
| 1040 | (heredoc identifier: (heredoc_start) @font-lock-constant-face) | ||
| 1041 | (heredoc_body (string_content) @font-lock-string-face) | ||
| 1042 | (heredoc end_tag: (heredoc_end) @font-lock-constant-face) | ||
| 1043 | (nowdoc identifier: (heredoc_start) @font-lock-constant-face) | ||
| 1044 | (nowdoc_body (nowdoc_string) @font-lock-string-face) | ||
| 1045 | (nowdoc end_tag: (heredoc_end) @font-lock-constant-face) | ||
| 1046 | (shell_command_expression) @font-lock-string-face) | ||
| 1047 | |||
| 1048 | :language 'php | ||
| 1049 | :feature 'type | ||
| 1050 | :override t | ||
| 1051 | '((union_type "|" @font-lock-operator-face) | ||
| 1052 | (union_type) @font-lock-type-face | ||
| 1053 | (bottom_type) @font-lock-type-face | ||
| 1054 | (primitive_type) @font-lock-type-face | ||
| 1055 | ((primitive_type) @font-lock-keyword-face | ||
| 1056 | (:equal "callable" @font-lock-keyword-face)) | ||
| 1057 | (cast_type) @font-lock-type-face | ||
| 1058 | (named_type) @font-lock-type-face | ||
| 1059 | (optional_type) @font-lock-type-face) | ||
| 1060 | |||
| 1061 | :language 'php | ||
| 1062 | :feature 'definition | ||
| 1063 | :override t | ||
| 1064 | `((php_tag) @font-lock-preprocessor-face | ||
| 1065 | ,@(if (php-ts-mode--test-php-end-tag-p) | ||
| 1066 | '((php_end_tag) @font-lock-preprocessor-face) | ||
| 1067 | '(("?>") @font-lock-preprocessor-face)) | ||
| 1068 | ;; Highlights identifiers in declarations. | ||
| 1069 | (class_declaration | ||
| 1070 | name: (_) @font-lock-type-face) | ||
| 1071 | (class_interface_clause (name) @font-lock-type-face) | ||
| 1072 | (interface_declaration | ||
| 1073 | name: (_) @font-lock-type-face) | ||
| 1074 | (trait_declaration | ||
| 1075 | name: (_) @font-lock-type-face) | ||
| 1076 | (enum_declaration | ||
| 1077 | name: (_) @font-lock-type-face) | ||
| 1078 | (function_definition | ||
| 1079 | name: (_) @font-lock-function-name-face) | ||
| 1080 | ,@(when (php-ts-mode--test-property-hook-p) | ||
| 1081 | '((property_hook (name) @font-lock-function-name-face))) | ||
| 1082 | (method_declaration | ||
| 1083 | name: (_) @font-lock-function-name-face) | ||
| 1084 | (method_declaration | ||
| 1085 | name: (name) @font-lock-builtin-face | ||
| 1086 | (:match ,(rx-to-string | ||
| 1087 | `(: bos (or ,@php-ts-mode--class-magic-methods) eos)) | ||
| 1088 | @font-lock-builtin-face)) | ||
| 1089 | ("=>") @font-lock-keyword-face | ||
| 1090 | (object_creation_expression | ||
| 1091 | (name) @font-lock-type-face) | ||
| 1092 | ,@(when (php-ts-mode--test-namespace-name-as-prefix-p) | ||
| 1093 | '((namespace_name_as_prefix "\\" @font-lock-delimiter-face) | ||
| 1094 | (namespace_name_as_prefix | ||
| 1095 | (namespace_name (name)) @font-lock-type-face))) | ||
| 1096 | ,@(if (php-ts-mode--test-namespace-aliasing-clause-p) | ||
| 1097 | '((namespace_aliasing_clause (name) @font-lock-type-face)) | ||
| 1098 | '((namespace_use_clause alias: (name) @font-lock-type-face))) | ||
| 1099 | ,@(when (not (php-ts-mode--test-namespace-use-group-clause-p)) | ||
| 1100 | '((namespace_use_group | ||
| 1101 | (namespace_use_clause (name) @font-lock-type-face)))) | ||
| 1102 | (namespace_use_clause (name) @font-lock-type-face) | ||
| 1103 | (namespace_name "\\" @font-lock-delimiter-face) | ||
| 1104 | (namespace_name (name) @font-lock-type-face) | ||
| 1105 | (use_declaration (name) @font-lock-property-use-face) | ||
| 1106 | (use_instead_of_clause (name) @font-lock-type-face) | ||
| 1107 | (binary_expression | ||
| 1108 | operator: "instanceof" | ||
| 1109 | right: (name) @font-lock-type-face)) | ||
| 1110 | |||
| 1111 | :language 'php | ||
| 1112 | :feature 'function-scope | ||
| 1113 | :override t | ||
| 1114 | '((scoped_call_expression | ||
| 1115 | scope: (name) @font-lock-constant-face) | ||
| 1116 | (class_constant_access_expression (name) @font-lock-constant-face)) | ||
| 1117 | |||
| 1118 | :language 'php | ||
| 1119 | :feature 'function-call | ||
| 1120 | :override t | ||
| 1121 | '((function_call_expression | ||
| 1122 | function: (name) @font-lock-function-call-face) | ||
| 1123 | (scoped_call_expression | ||
| 1124 | name: (name) @font-lock-function-call-face) | ||
| 1125 | (member_call_expression | ||
| 1126 | name: (name) @font-lock-function-call-face) | ||
| 1127 | (nullsafe_member_call_expression | ||
| 1128 | name: (_) @font-lock-function-call-face)) | ||
| 1129 | |||
| 1130 | :language 'php | ||
| 1131 | :feature 'argument | ||
| 1132 | '((argument | ||
| 1133 | name: (_) @font-lock-constant-face)) | ||
| 1134 | |||
| 1135 | :language 'php | ||
| 1136 | :feature 'escape-sequence | ||
| 1137 | :override t | ||
| 1138 | '((string (escape_sequence) @font-lock-escape-face) | ||
| 1139 | (encapsed_string (escape_sequence) @font-lock-escape-face) | ||
| 1140 | (heredoc_body (escape_sequence) @font-lock-escape-face)) | ||
| 1141 | |||
| 1142 | :language 'php | ||
| 1143 | :feature 'base-clause | ||
| 1144 | :override t | ||
| 1145 | `((base_clause (name) @font-lock-type-face) | ||
| 1146 | (use_as_clause (name) @font-lock-property-use-face) | ||
| 1147 | ,@(when (not (php-ts-mode--test-namespace-name-as-prefix-p)) | ||
| 1148 | '((qualified_name prefix: "\\" @font-lock-delimiter-face))) | ||
| 1149 | (qualified_name (name) @font-lock-constant-face) | ||
| 1150 | ,@(when (php-ts-mode--test-relative-name-p) | ||
| 1151 | '((relative_name (name) @font-lock-constant-face)))) | ||
| 1152 | |||
| 1153 | :language 'php | ||
| 1154 | :feature 'property | ||
| 1155 | '((enum_case | ||
| 1156 | name: (_) @font-lock-type-face)) | ||
| 1157 | |||
| 1158 | :language 'php | ||
| 1159 | :feature 'attribute | ||
| 1160 | '((((attribute (_) @attribute_name) @font-lock-preprocessor-face) | ||
| 1161 | (:equal "Deprecated" @attribute_name)) | ||
| 1162 | (attribute_group (attribute (name) @font-lock-constant-face))) | ||
| 1163 | |||
| 1164 | :language 'php | ||
| 1165 | :feature 'bracket | ||
| 1166 | '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) | ||
| 1167 | |||
| 1168 | :language 'php | ||
| 1169 | :feature 'error | ||
| 1170 | :override t | ||
| 1171 | '((ERROR) @php-ts-mode--fontify-error))))) | ||
| 1166 | 1172 | ||
| 1167 | 1173 | ||
| 1168 | ;;; Font-lock helpers | 1174 | ;;; Font-lock helpers |
| 1169 | 1175 | ||
| 1170 | (defconst php-ts-mode--custom-html-font-lock-settings | 1176 | (defvar php-ts-mode--custom-html-font-lock-settings-cached nil |
| 1171 | (treesit-replace-font-lock-feature-settings | 1177 | "Cached tree-sitter font-lock settings for HTML when embedded in PHP.") |
| 1172 | (treesit-font-lock-rules | 1178 | |
| 1173 | :language 'html | 1179 | (defun php-ts-mode--custom-html-font-lock-settings () |
| 1174 | :override t | ||
| 1175 | :feature 'comment | ||
| 1176 | '((comment) @font-lock-comment-face | ||
| 1177 | ;; handle shebang path and others type of comment | ||
| 1178 | (document (text) @font-lock-comment-face))) | ||
| 1179 | mhtml-ts-mode--treesit-font-lock-settings) | ||
| 1180 | "Tree-sitter Font-lock settings for HTML when embedded in PHP. | 1180 | "Tree-sitter Font-lock settings for HTML when embedded in PHP. |
| 1181 | Like `mhtml-ts-mode--font-lock-settings' but adapted for `php-ts-mode'.") | 1181 | Like `mhtml-ts-mode--font-lock-settings' but adapted for `php-ts-mode'. |
| 1182 | |||
| 1183 | Tree-sitter font-lock settings are evaluated the first time this | ||
| 1184 | function is called. Subsequent calls return the first evaluated value." | ||
| 1185 | (or php-ts-mode--custom-html-font-lock-settings-cached | ||
| 1186 | (setq php-ts-mode--custom-html-font-lock-settings-cached | ||
| 1187 | (treesit-replace-font-lock-feature-settings | ||
| 1188 | (treesit-font-lock-rules | ||
| 1189 | :language 'html | ||
| 1190 | :override t | ||
| 1191 | :feature 'comment | ||
| 1192 | '((comment) @font-lock-comment-face | ||
| 1193 | ;; handle shebang path and others type of comment | ||
| 1194 | (document (text) @font-lock-comment-face))) | ||
| 1195 | (mhtml-ts-mode--treesit-font-lock-settings))))) | ||
| 1182 | 1196 | ||
| 1183 | (defvar php-ts-mode--phpdoc-font-lock-settings | 1197 | (defvar php-ts-mode--phpdoc-font-lock-settings |
| 1184 | (treesit-font-lock-rules | 1198 | (treesit-font-lock-rules |
| @@ -1676,7 +1690,7 @@ If FORCE is t setup comment for PHP. Depends on | |||
| 1676 | (setq-local treesit-font-lock-settings | 1690 | (setq-local treesit-font-lock-settings |
| 1677 | (append | 1691 | (append |
| 1678 | (php-ts-mode--font-lock-settings) | 1692 | (php-ts-mode--font-lock-settings) |
| 1679 | php-ts-mode--custom-html-font-lock-settings | 1693 | (php-ts-mode--custom-html-font-lock-settings) |
| 1680 | php-ts-mode--phpdoc-font-lock-settings)) | 1694 | php-ts-mode--phpdoc-font-lock-settings)) |
| 1681 | 1695 | ||
| 1682 | (setq-local treesit-font-lock-feature-list php-ts-mode--feature-list) | 1696 | (setq-local treesit-font-lock-feature-list php-ts-mode--feature-list) |