1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-26 07:11:34 -08:00

Remove the cached values in tree-sitter modes (bug#79363)

The cached values are not needed anymore since Emacs now caches
the compiled queries.

* lisp/progmodes/cmake-ts-mode.el:
(cmake-ts-mode--indent-rules-cached): Remove.
(cmake-ts-mode--indent-rules): Return values directly.
(cmake-ts-mode--font-lock-settings-cached): Remove.
(cmake-ts-mode--font-lock-settings): Return values directly.
* lisp/progmodes/php-ts-mode.el:
(php-ts-mode--font-lock-settings-cached): Remove.
(php-ts-mode--font-lock-settings): Return values directly.
(php-ts-mode--custom-html-font-lock-settings-cached): Remove.
(php-ts-mode--custom-html-font-lock-settings): Return values directly.
* lisp/textmodes/mhtml-ts-mode.el:
(mhtml-ts-mode--treesit-font-lock-settings-cached): Remove.
(mhtml-ts-mode--treesit-font-lock-settings): Return values directly.
(mhtml-ts-mode--treesit-indent-rules-cached): Remove.
(mhtml-ts-mode--treesit-indent-rules): Return values directly.
* lisp/progmodes/cmake-ts-mode.el:
(cmake-ts-mode--indent-rules-cached): Remove
(cmake-ts-mode--indent-rules): Return values directly.
(cmake-ts-mode--font-lock-settings-cached): Remove.
(cmake-ts-mode--font-lock-settings): Return values directly.
* lisp/progmodes/csharp-mode.el:
(csharp-ts-mode--font-lock-settings-cached): Remove.
(csharp-ts-mode--font-lock-settings): Return values directly.
This commit is contained in:
Yuan Fu 2025-11-28 00:10:17 -08:00
parent 85f2bf2bc7
commit 2c19f6087e
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
5 changed files with 796 additions and 868 deletions

View file

@ -61,35 +61,27 @@
table) table)
"Syntax table for `cmake-ts-mode'.") "Syntax table for `cmake-ts-mode'.")
(defvar cmake-ts-mode--indent-rules-cached nil
"Cached tree-sitter indent rules for `cmake-ts-mode'.")
(defun cmake-ts-mode--indent-rules () (defun cmake-ts-mode--indent-rules ()
"Return tree-sitter indent rules for `cmake-ts-mode'. "Return tree-sitter indent rules for `cmake-ts-mode'."
`((cmake
Tree-sitter indent rules are evaluated the first time this function is ((node-is ")") parent-bol 0)
called. Subsequent calls return the first evaluated value." ((node-is "else_command") parent-bol 0)
(or cmake-ts-mode--indent-rules-cached ((node-is "elseif_command") parent-bol 0)
(setq cmake-ts-mode--indent-rules-cached ((node-is "endforeach_command") parent-bol 0)
`((cmake ((node-is "endfunction_command") parent-bol 0)
((node-is ")") parent-bol 0) ((node-is "endif_command") parent-bol 0)
((node-is "else_command") parent-bol 0) ((parent-is "foreach_loop") parent-bol cmake-ts-mode-indent-offset)
((node-is "elseif_command") parent-bol 0) ((parent-is "function_def") parent-bol cmake-ts-mode-indent-offset)
((node-is "endforeach_command") parent-bol 0) ((parent-is "if_condition") parent-bol cmake-ts-mode-indent-offset)
((node-is "endfunction_command") parent-bol 0) ((parent-is "normal_command") parent-bol cmake-ts-mode-indent-offset)
((node-is "endif_command") parent-bol 0) ;; Release v0.4.0 wraps arguments in an argument_list node.
((parent-is "foreach_loop") parent-bol cmake-ts-mode-indent-offset) ,@(ignore-errors
((parent-is "function_def") parent-bol cmake-ts-mode-indent-offset) (treesit-query-capture 'cmake '((argument_list) @capture))
((parent-is "if_condition") parent-bol cmake-ts-mode-indent-offset) `(((parent-is "argument_list") grand-parent cmake-ts-mode-indent-offset)))
((parent-is "normal_command") parent-bol cmake-ts-mode-indent-offset) ;; Release v0.3.0 wraps the body of commands into a body node.
;; Release v0.4.0 wraps arguments in an argument_list node. ,@(ignore-errors
,@(ignore-errors (treesit-query-capture 'cmake '((body) @capture))
(treesit-query-capture 'cmake '((argument_list) @capture)) `(((parent-is "body") grand-parent cmake-ts-mode-indent-offset))))))
`(((parent-is "argument_list") grand-parent cmake-ts-mode-indent-offset)))
;; Release v0.3.0 wraps the body of commands into a body node.
,@(ignore-errors
(treesit-query-capture 'cmake '((body) @capture))
`(((parent-is "body") grand-parent cmake-ts-mode-indent-offset))))))))
(defvar cmake-ts-mode--constants (defvar cmake-ts-mode--constants
'("ON" "TRUE" "YES" "Y" "OFF" "FALSE" "NO" "N" "IGNORE" "NOTFOUND") '("ON" "TRUE" "YES" "Y" "OFF" "FALSE" "NO" "N" "IGNORE" "NOTFOUND")
@ -148,76 +140,68 @@ Check if a node type is available, then return the right font lock rules."
eol)) eol))
@font-lock-constant-face)))))))) @font-lock-constant-face))))))))
(defvar cmake-ts-mode--font-lock-settings-cached nil
"Cached tree-sitter font-lock settings for `cmake-ts-mode'.")
(defun cmake-ts-mode--font-lock-settings () (defun cmake-ts-mode--font-lock-settings ()
"Return tree-sitter font-lock settings for `cmake-ts-mode'. "Return tree-sitter font-lock settings for `cmake-ts-mode'."
(treesit-font-lock-rules
:language 'cmake
:feature 'bracket
'((["(" ")"]) @font-lock-bracket-face)
Tree-sitter font-lock settings are evaluated the first time this :language 'cmake
function is called. Subsequent calls return the first evaluated value." :feature 'builtin
(or cmake-ts-mode--font-lock-settings-cached (cmake-ts-mode--font-lock-compatibility-fe9b5e0)
(setq cmake-ts-mode--font-lock-settings-cached
(treesit-font-lock-rules
:language 'cmake
:feature 'bracket
'((["(" ")"]) @font-lock-bracket-face)
:language 'cmake :language 'cmake
:feature 'builtin :feature 'comment
(cmake-ts-mode--font-lock-compatibility-fe9b5e0) '([(bracket_comment) (line_comment)] @font-lock-comment-face)
:language 'cmake :language 'cmake
:feature 'comment :feature 'constant
'([(bracket_comment) (line_comment)] @font-lock-comment-face) `(((argument) @font-lock-constant-face
(:match ,(rx-to-string
`(seq bol
(or ,@cmake-ts-mode--constants)
eol))
@font-lock-constant-face)))
:language 'cmake :language 'cmake
:feature 'constant :feature 'function
`(((argument) @font-lock-constant-face '((normal_command (identifier) @font-lock-function-call-face))
(:match ,(rx-to-string
`(seq bol
(or ,@cmake-ts-mode--constants)
eol))
@font-lock-constant-face)))
:language 'cmake :language 'cmake
:feature 'function :feature 'keyword
'((normal_command (identifier) @font-lock-function-call-face)) `([,@cmake-ts-mode--keywords] @font-lock-keyword-face)
:language 'cmake :language 'cmake
:feature 'keyword :feature 'number
`([,@cmake-ts-mode--keywords] @font-lock-keyword-face) '(((unquoted_argument) @font-lock-number-face
(:match "\\`-?[[:digit:]]*\\.?[[:digit:]]*\\.?[[:digit:]]+\\'"
@font-lock-number-face)))
:language 'cmake :language 'cmake
:feature 'number :feature 'string
'(((unquoted_argument) @font-lock-number-face '([(bracket_argument) (quoted_argument)] @font-lock-string-face)
(:match "\\`-?[[:digit:]]*\\.?[[:digit:]]*\\.?[[:digit:]]+\\'"
@font-lock-number-face)))
:language 'cmake :language 'cmake
:feature 'string :feature 'escape-sequence
'([(bracket_argument) (quoted_argument)] @font-lock-string-face) :override t
'((escape_sequence) @font-lock-escape-face)
:language 'cmake :language 'cmake
:feature 'escape-sequence :feature 'misc-punctuation
:override t ;; Don't override strings.
'((escape_sequence) @font-lock-escape-face) :override 'nil
'((["$" "{" "}"]) @font-lock-misc-punctuation-face)
:language 'cmake :language 'cmake
:feature 'misc-punctuation :feature 'variable
;; Don't override strings. :override t
:override 'nil '((variable) @font-lock-variable-use-face)
'((["$" "{" "}"]) @font-lock-misc-punctuation-face)
:language 'cmake :language 'cmake
:feature 'variable :feature 'error
:override t :override t
'((variable) @font-lock-variable-use-face) '((ERROR) @font-lock-warning-face)))
:language 'cmake
:feature 'error
:override t
'((ERROR) @font-lock-warning-face)))))
(defun cmake-ts-mode--defun-name (node) (defun cmake-ts-mode--defun-name (node)
"Return the defun name of NODE. "Return the defun name of NODE.

View file

@ -779,345 +779,337 @@ compilation and evaluation time conflicts."
(if (csharp-ts-mode--test-method-declaration-type-field) (if (csharp-ts-mode--test-method-declaration-type-field)
'type: 'returns:)) 'type: 'returns:))
(defvar csharp-ts-mode--font-lock-settings-cached nil
"Cached tree-sitter font-lock settings for `csharp-ts-mode'.")
(defun csharp-ts-mode--font-lock-settings () (defun csharp-ts-mode--font-lock-settings ()
"Return tree-sitter font-lock settings for `csharp-ts-mode'. "Return tree-sitter font-lock settings for `csharp-ts-mode'."
(treesit-font-lock-rules
:language 'c-sharp
:feature 'expression
'((conditional_expression (identifier) @font-lock-variable-use-face)
(postfix_unary_expression (identifier)* @font-lock-variable-use-face)
(initializer_expression (assignment_expression left: (identifier) @font-lock-property-use-face))
(anonymous_object_creation_expression
(identifier) @font-lock-property-use-face
(identifier) @font-lock-variable-use-face)
(anonymous_object_creation_expression
(identifier) @font-lock-property-use-face
[(object_creation_expression)
(integer_literal)
(string_literal)
(binary_expression)
(invocation_expression)
(member_access_expression)
(conditional_expression)])
(interpolated_string_expression
(interpolation
(identifier) @font-lock-variable-use-face))
(interpolated_string_expression
(interpolation
(member_access_expression
name: (identifier) @font-lock-property-use-face)))
((interpolated_string_expression
(interpolation
(member_access_expression
expression: (identifier) @font-lock-variable-use-face)))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((element_access_expression (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((element_access_expression (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((return_statement (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((return_statement (member_access_expression
expression: (identifier) @font-lock-variable-use-face))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((is_pattern_expression
expression: (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((is_pattern_expression
expression: (member_access_expression
expression: (identifier) @font-lock-variable-use-face))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
(is_pattern_expression
expression: (member_access_expression
name: (identifier) @font-lock-property-use-face))
(is_pattern_expression
pattern: (constant_pattern (identifier) @font-lock-type-face))
(is_pattern_expression
pattern: (constant_pattern (member_access_expression
name: (identifier) @font-lock-type-face)))
((binary_expression
left: (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((binary_expression
right: (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
(assignment_expression
right: (identifier) @font-lock-variable-use-face)
(expression_statement ;; capture parent node to NOT shadow variable_declaration.
(assignment_expression
left: (identifier) @font-lock-variable-use-face))
(if_statement condition: (identifier) @font-lock-variable-use-face)
Tree-sitter font-lock settings are evaluated the first time this ;; handle more specific matchers before generalized variable-use fallback.
function is called. Subsequent calls return the first evaluated value." (invocation_expression
(or csharp-ts-mode--font-lock-settings-cached function: (member_access_expression
(setq csharp-ts-mode--font-lock-settings-cached name: (identifier) @font-lock-function-call-face))
(treesit-font-lock-rules (invocation_expression
:language 'c-sharp function: (member_access_expression
:feature 'expression name: (generic_name (identifier) @font-lock-function-call-face)))
'((conditional_expression (identifier) @font-lock-variable-use-face) (member_access_expression
(postfix_unary_expression (identifier)* @font-lock-variable-use-face) expression: (identifier) @font-lock-variable-use-face
(initializer_expression (assignment_expression left: (identifier) @font-lock-property-use-face)) name: (identifier) @font-lock-property-use-face))
(anonymous_object_creation_expression
(identifier) @font-lock-property-use-face
(identifier) @font-lock-variable-use-face)
(anonymous_object_creation_expression
(identifier) @font-lock-property-use-face
[(object_creation_expression)
(integer_literal)
(string_literal)
(binary_expression)
(invocation_expression)
(member_access_expression)
(conditional_expression)])
(interpolated_string_expression
(interpolation
(identifier) @font-lock-variable-use-face))
(interpolated_string_expression
(interpolation
(member_access_expression
name: (identifier) @font-lock-property-use-face)))
((interpolated_string_expression
(interpolation
(member_access_expression
expression: (identifier) @font-lock-variable-use-face)))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((element_access_expression (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((element_access_expression (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((return_statement (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((return_statement (member_access_expression
expression: (identifier) @font-lock-variable-use-face))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((is_pattern_expression
expression: (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((is_pattern_expression
expression: (member_access_expression
expression: (identifier) @font-lock-variable-use-face))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
(is_pattern_expression
expression: (member_access_expression
name: (identifier) @font-lock-property-use-face))
(is_pattern_expression
pattern: (constant_pattern (identifier) @font-lock-type-face))
(is_pattern_expression
pattern: (constant_pattern (member_access_expression
name: (identifier) @font-lock-type-face)))
((binary_expression
left: (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
((binary_expression
right: (identifier) @font-lock-variable-use-face)
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
(assignment_expression
right: (identifier) @font-lock-variable-use-face)
(expression_statement ;; capture parent node to NOT shadow variable_declaration.
(assignment_expression
left: (identifier) @font-lock-variable-use-face))
(if_statement condition: (identifier) @font-lock-variable-use-face)
;; handle more specific matchers before generalized variable-use fallback. :language 'c-sharp
(invocation_expression :feature 'bracket
function: (member_access_expression '((["(" ")" "[" "]" "{" "}" (interpolation_brace)]) @font-lock-bracket-face)
name: (identifier) @font-lock-function-call-face))
(invocation_expression :language 'c-sharp
function: (member_access_expression :feature 'delimiter
name: (generic_name (identifier) @font-lock-function-call-face))) '((["," ":" ";"]) @font-lock-delimiter-face)
(member_access_expression
expression: (identifier) @font-lock-variable-use-face :language 'c-sharp
:feature 'error
'((ERROR) @font-lock-warning-face)
:language 'c-sharp
:override t
:feature 'comment
'((comment) @font-lock-comment-face)
:language 'c-sharp
:override t
:feature 'keyword
`([,@csharp-ts-mode--keywords] @font-lock-keyword-face
(modifier) @font-lock-keyword-face
,@(if (csharp-ts-mode--test-this-expression)
'((this_expression) @font-lock-keyword-face)
'("this" @font-lock-keyword-face))
;; avoid fontifying indentifiers with a keyword-values as identifiers.
((identifier) @font-lock-keyword-face
(:match ,(concat "\\`" (regexp-opt csharp-ts-mode--keywords t) "\\'") @font-lock-keyword-face)))
:language 'c-sharp
:override t
:feature 'attribute
`((attribute_list
"[" @csharp-ts-mode-attribute-face
(attribute name: (identifier) @csharp-ts-mode-attribute-face)
"]" @csharp-ts-mode-attribute-face))
:language 'c-sharp
:override t
:feature 'escape-sequence
'((escape_sequence) @font-lock-escape-face)
:language 'c-sharp
:override t
:feature 'literal
`((integer_literal) @font-lock-number-face
(real_literal) @font-lock-number-face
(null_literal) @font-lock-constant-face
(boolean_literal) @font-lock-constant-face)
:language 'c-sharp
:feature 'string
`([(string_literal)
(verbatim_string_literal)
,@ (when (csharp-ts-mode--test-string-content)
'((string_content)
"\""))
,@(if (csharp-ts-mode--test-interpolated-string-text)
'((interpolated_string_text)
(interpolated_verbatim_string_text)
(character_literal)
"\""
"$\""
"@$\""
"$@\"")
'((interpolation_start)
(interpolation_quote)))]
@font-lock-string-face)
:language 'c-sharp
:feature 'type
`((predefined_type) @font-lock-type-face
(implicit_type) @font-lock-type-face
(nullable_type) @font-lock-type-face
(type_parameter
(identifier) @font-lock-type-face)
(type_argument_list
(identifier) @font-lock-type-face)
(type_argument_list
(generic_name
(identifier) @font-lock-type-face))
(base_list
(generic_name
(identifier) @font-lock-type-face))
(array_type
(identifier) @font-lock-type-face)
(qualified_name
name: (generic_name (identifier) @font-lock-type-face))
(cast_expression (identifier) @font-lock-type-face)
(cast_expression (generic_name (identifier) @font-lock-type-face))
["operator"] @font-lock-type-face
(type_parameter_constraints_clause
(identifier) @font-lock-type-face)
,@(if (csharp-ts-mode--test-type-constraint)
'((type_constraint type: (identifier) @font-lock-type-face)
(type_constraint type: (generic_name (identifier) @font-lock-type-face)))
'((type_parameter_constraint (type type: (identifier) @font-lock-type-face))
(type_parameter_constraint (type type: (generic_name (identifier) @font-lock-type-face)))))
,@(when (csharp-ts-mode--test-type-of-expression)
'((type_of_expression (identifier) @font-lock-type-face)))
,@(when (csharp-ts-mode--test-typeof-expression)
'((typeof_expression (identifier) @font-lock-type-face)))
(object_creation_expression
type: (identifier) @font-lock-type-face)
(object_creation_expression
type: (generic_name (identifier) @font-lock-type-face))
(as_expression right: (identifier) @font-lock-type-face)
(as_expression right: (generic_name (identifier) @font-lock-type-face)))
:language 'c-sharp
:feature 'definition
`((qualified_name (identifier) @font-lock-type-face)
(using_directive (identifier) @font-lock-type-face)
,@(when (csharp-ts-mode--test-name-equals)
'((using_directive (name_equals
(identifier) @font-lock-type-face))))
(enum_declaration (identifier) @font-lock-type-face)
(enum_member_declaration (identifier) @font-lock-variable-name-face)
(field_declaration (variable_declaration (variable_declarator
name: (identifier) @font-lock-variable-name-face)))
(interface_declaration (identifier) @font-lock-type-face)
(struct_declaration (identifier) @font-lock-type-face)
(record_declaration (identifier) @font-lock-type-face)
(namespace_declaration (identifier) @font-lock-type-face)
(base_list (identifier) @font-lock-type-face)
(property_declaration
type: (nullable_type) @font-lock-type-face
name: (identifier) @font-lock-variable-name-face)
(property_declaration
type: (predefined_type) @font-lock-type-face
name: (identifier) @font-lock-variable-name-face)
(property_declaration
type: (identifier) @font-lock-type-face
name: (identifier) @font-lock-variable-name-face)
(class_declaration (identifier) @font-lock-type-face)
(constructor_declaration name: (_) @font-lock-type-face)
;; Handle different releases of tree-sitter-c-sharp.
;; Check if keyword void_keyword is available, then return the correct rule."
,@(condition-case nil
(progn (treesit-query-capture 'csharp '((void_keyword) @capture))
`((method_declaration ,csharp-ts-mode--type-field [(identifier) (void_keyword)] @font-lock-type-face)))
(error
`((method_declaration ,csharp-ts-mode--type-field [(identifier) (predefined_type)] @font-lock-type-face))))
(method_declaration ,csharp-ts-mode--type-field (generic_name (identifier) @font-lock-type-face))
(method_declaration name: (_) @font-lock-function-name-face)
;; only fontify known expression-types, to avoid the need to use :override
;; for lambda-expressions in 'function below.
(variable_declarator
name: (identifier) @font-lock-variable-name-face
[(object_creation_expression)
(integer_literal)
(string_literal)
(binary_expression)
(invocation_expression)
(await_expression)
(member_access_expression)
(conditional_expression)])
(catch_declaration
((identifier) @font-lock-type-face))
(catch_declaration
((identifier) @font-lock-type-face
(identifier) @font-lock-variable-name-face))
(variable_declaration (identifier) @font-lock-type-face)
(variable_declaration (qualified_name
name: (generic_name (identifier) @font-lock-type-face)))
(variable_declaration (generic_name (identifier) @font-lock-type-face))
(parameter type: (identifier) @font-lock-type-face)
(parameter type: (generic_name (identifier) @font-lock-type-face))
(parameter name: (identifier) @font-lock-variable-name-face)
(lambda_expression (identifier) @font-lock-variable-name-face)
(lambda_expression
parameters: (implicit_parameter) @font-lock-variable-name-face)
(declaration_expression type: (identifier) @font-lock-type-face)
(declaration_expression name: (identifier) @font-lock-variable-name-face))
:language 'c-sharp
:feature 'function
'((invocation_expression
function: (identifier) @font-lock-function-call-face)
((invocation_expression
function: (member_access_expression
expression: (identifier) @font-lock-variable-use-face))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
(argument (identifier) @font-lock-variable-use-face)
((argument (member_access_expression
expression: (identifier) @font-lock-variable-use-face))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
(argument (member_access_expression
name: (identifier) @font-lock-property-use-face)) name: (identifier) @font-lock-property-use-face))
;; only highlight as function if variable contains lambda expression
(variable_declarator
name: (identifier) @font-lock-function-name-face
(lambda_expression)))
:language 'c-sharp :language 'c-sharp
:feature 'bracket :feature 'directives
'((["(" ")" "[" "]" "{" "}" (interpolation_brace)]) @font-lock-bracket-face) :override t
(if (csharp-ts-mode--test-if-directive)
:language 'c-sharp '((if_directive
:feature 'delimiter "if" @font-lock-preprocessor-face
'((["," ":" ";"]) @font-lock-delimiter-face) (identifier) @font-lock-variable-use-face)
(elif_directive
:language 'c-sharp "elif" @font-lock-preprocessor-face
:feature 'error (identifier) @font-lock-variable-use-face)
'((ERROR) @font-lock-warning-face) (else_directive) @font-lock-preprocessor-face
(endif_directive) @font-lock-preprocessor-face
:language 'c-sharp (define_directive
:override t "define" @font-lock-preprocessor-face
:feature 'comment (identifier) @font-lock-variable-use-face)
'((comment) @font-lock-comment-face) (nullable_directive) @font-lock-preprocessor-face
(pragma_directive) @font-lock-preprocessor-face
:language 'c-sharp (region_directive) @font-lock-preprocessor-face
:override t (endregion_directive) @font-lock-preprocessor-face
:feature 'keyword (region_directive
`([,@csharp-ts-mode--keywords] @font-lock-keyword-face (preproc_message) @font-lock-variable-use-face)
(modifier) @font-lock-keyword-face (endregion_directive
,@(if (csharp-ts-mode--test-this-expression) (preproc_message) @font-lock-variable-use-face))
'((this_expression) @font-lock-keyword-face) '((preproc_if
'("this" @font-lock-keyword-face)) "#if" @font-lock-preprocessor-face
(identifier) @font-lock-variable-use-face)
;; avoid fontifying indentifiers with a keyword-values as identifiers. (preproc_elif
((identifier) @font-lock-keyword-face "#elif" @font-lock-preprocessor-face
(:match ,(concat "\\`" (regexp-opt csharp-ts-mode--keywords t) "\\'") @font-lock-keyword-face))) (identifier) @font-lock-variable-use-face)
(preproc_else) @font-lock-preprocessor-face
:language 'c-sharp "#endif" @font-lock-preprocessor-face
:override t (preproc_define
:feature 'attribute "#define" @font-lock-preprocessor-face
`((attribute_list (preproc_arg) @font-lock-variable-use-face)
"[" @csharp-ts-mode-attribute-face (preproc_nullable) @font-lock-preprocessor-face
(attribute name: (identifier) @csharp-ts-mode-attribute-face) (preproc_pragma) @font-lock-preprocessor-face
"]" @csharp-ts-mode-attribute-face)) (preproc_region) @font-lock-preprocessor-face
(preproc_endregion) @font-lock-preprocessor-face
:language 'c-sharp (preproc_region
:override t (preproc_arg) @font-lock-variable-use-face)
:feature 'escape-sequence (preproc_endregion
'((escape_sequence) @font-lock-escape-face) (preproc_arg) @font-lock-variable-use-face)))))
:language 'c-sharp
:override t
:feature 'literal
`((integer_literal) @font-lock-number-face
(real_literal) @font-lock-number-face
(null_literal) @font-lock-constant-face
(boolean_literal) @font-lock-constant-face)
:language 'c-sharp
:feature 'string
`([(string_literal)
(verbatim_string_literal)
,@ (when (csharp-ts-mode--test-string-content)
'((string_content)
"\""))
,@(if (csharp-ts-mode--test-interpolated-string-text)
'((interpolated_string_text)
(interpolated_verbatim_string_text)
(character_literal)
"\""
"$\""
"@$\""
"$@\"")
'((interpolation_start)
(interpolation_quote)))]
@font-lock-string-face)
:language 'c-sharp
:feature 'type
`((predefined_type) @font-lock-type-face
(implicit_type) @font-lock-type-face
(nullable_type) @font-lock-type-face
(type_parameter
(identifier) @font-lock-type-face)
(type_argument_list
(identifier) @font-lock-type-face)
(type_argument_list
(generic_name
(identifier) @font-lock-type-face))
(base_list
(generic_name
(identifier) @font-lock-type-face))
(array_type
(identifier) @font-lock-type-face)
(qualified_name
name: (generic_name (identifier) @font-lock-type-face))
(cast_expression (identifier) @font-lock-type-face)
(cast_expression (generic_name (identifier) @font-lock-type-face))
["operator"] @font-lock-type-face
(type_parameter_constraints_clause
(identifier) @font-lock-type-face)
,@(if (csharp-ts-mode--test-type-constraint)
'((type_constraint type: (identifier) @font-lock-type-face)
(type_constraint type: (generic_name (identifier) @font-lock-type-face)))
'((type_parameter_constraint (type type: (identifier) @font-lock-type-face))
(type_parameter_constraint (type type: (generic_name (identifier) @font-lock-type-face)))))
,@(when (csharp-ts-mode--test-type-of-expression)
'((type_of_expression (identifier) @font-lock-type-face)))
,@(when (csharp-ts-mode--test-typeof-expression)
'((typeof_expression (identifier) @font-lock-type-face)))
(object_creation_expression
type: (identifier) @font-lock-type-face)
(object_creation_expression
type: (generic_name (identifier) @font-lock-type-face))
(as_expression right: (identifier) @font-lock-type-face)
(as_expression right: (generic_name (identifier) @font-lock-type-face)))
:language 'c-sharp
:feature 'definition
`((qualified_name (identifier) @font-lock-type-face)
(using_directive (identifier) @font-lock-type-face)
,@(when (csharp-ts-mode--test-name-equals)
'((using_directive (name_equals
(identifier) @font-lock-type-face))))
(enum_declaration (identifier) @font-lock-type-face)
(enum_member_declaration (identifier) @font-lock-variable-name-face)
(field_declaration (variable_declaration (variable_declarator
name: (identifier) @font-lock-variable-name-face)))
(interface_declaration (identifier) @font-lock-type-face)
(struct_declaration (identifier) @font-lock-type-face)
(record_declaration (identifier) @font-lock-type-face)
(namespace_declaration (identifier) @font-lock-type-face)
(base_list (identifier) @font-lock-type-face)
(property_declaration
type: (nullable_type) @font-lock-type-face
name: (identifier) @font-lock-variable-name-face)
(property_declaration
type: (predefined_type) @font-lock-type-face
name: (identifier) @font-lock-variable-name-face)
(property_declaration
type: (identifier) @font-lock-type-face
name: (identifier) @font-lock-variable-name-face)
(class_declaration (identifier) @font-lock-type-face)
(constructor_declaration name: (_) @font-lock-type-face)
;; Handle different releases of tree-sitter-c-sharp.
;; Check if keyword void_keyword is available, then return the correct rule."
,@(condition-case nil
(progn (treesit-query-capture 'csharp '((void_keyword) @capture))
`((method_declaration ,csharp-ts-mode--type-field [(identifier) (void_keyword)] @font-lock-type-face)))
(error
`((method_declaration ,csharp-ts-mode--type-field [(identifier) (predefined_type)] @font-lock-type-face))))
(method_declaration ,csharp-ts-mode--type-field (generic_name (identifier) @font-lock-type-face))
(method_declaration name: (_) @font-lock-function-name-face)
;; only fontify known expression-types, to avoid the need to use :override
;; for lambda-expressions in 'function below.
(variable_declarator
name: (identifier) @font-lock-variable-name-face
[(object_creation_expression)
(integer_literal)
(string_literal)
(binary_expression)
(invocation_expression)
(await_expression)
(member_access_expression)
(conditional_expression)])
(catch_declaration
((identifier) @font-lock-type-face))
(catch_declaration
((identifier) @font-lock-type-face
(identifier) @font-lock-variable-name-face))
(variable_declaration (identifier) @font-lock-type-face)
(variable_declaration (qualified_name
name: (generic_name (identifier) @font-lock-type-face)))
(variable_declaration (generic_name (identifier) @font-lock-type-face))
(parameter type: (identifier) @font-lock-type-face)
(parameter type: (generic_name (identifier) @font-lock-type-face))
(parameter name: (identifier) @font-lock-variable-name-face)
(lambda_expression (identifier) @font-lock-variable-name-face)
(lambda_expression
parameters: (implicit_parameter) @font-lock-variable-name-face)
(declaration_expression type: (identifier) @font-lock-type-face)
(declaration_expression name: (identifier) @font-lock-variable-name-face))
:language 'c-sharp
:feature 'function
'((invocation_expression
function: (identifier) @font-lock-function-call-face)
((invocation_expression
function: (member_access_expression
expression: (identifier) @font-lock-variable-use-face))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
(argument (identifier) @font-lock-variable-use-face)
((argument (member_access_expression
expression: (identifier) @font-lock-variable-use-face))
(:match "^[a-z][A-Za-z0-9]+" @font-lock-variable-use-face))
(argument (member_access_expression
name: (identifier) @font-lock-property-use-face))
;; only highlight as function if variable contains lambda expression
(variable_declarator
name: (identifier) @font-lock-function-name-face
(lambda_expression)))
:language 'c-sharp
:feature 'directives
:override t
(if (csharp-ts-mode--test-if-directive)
'((if_directive
"if" @font-lock-preprocessor-face
(identifier) @font-lock-variable-use-face)
(elif_directive
"elif" @font-lock-preprocessor-face
(identifier) @font-lock-variable-use-face)
(else_directive) @font-lock-preprocessor-face
(endif_directive) @font-lock-preprocessor-face
(define_directive
"define" @font-lock-preprocessor-face
(identifier) @font-lock-variable-use-face)
(nullable_directive) @font-lock-preprocessor-face
(pragma_directive) @font-lock-preprocessor-face
(region_directive) @font-lock-preprocessor-face
(endregion_directive) @font-lock-preprocessor-face
(region_directive
(preproc_message) @font-lock-variable-use-face)
(endregion_directive
(preproc_message) @font-lock-variable-use-face))
'((preproc_if
"#if" @font-lock-preprocessor-face
(identifier) @font-lock-variable-use-face)
(preproc_elif
"#elif" @font-lock-preprocessor-face
(identifier) @font-lock-variable-use-face)
(preproc_else) @font-lock-preprocessor-face
"#endif" @font-lock-preprocessor-face
(preproc_define
"#define" @font-lock-preprocessor-face
(preproc_arg) @font-lock-variable-use-face)
(preproc_nullable) @font-lock-preprocessor-face
(preproc_pragma) @font-lock-preprocessor-face
(preproc_region) @font-lock-preprocessor-face
(preproc_endregion) @font-lock-preprocessor-face
(preproc_region
(preproc_arg) @font-lock-variable-use-face)
(preproc_endregion
(preproc_arg) @font-lock-variable-use-face)))))))
;;;###autoload ;;;###autoload
(add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-mode)) (add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-mode))

View file

@ -3513,72 +3513,64 @@ characters of the current line."
node parent bol args) node parent bol args)
js-indent-level))) js-indent-level)))
(defvar js--treesit-indent-rules-cached nil
"Cached tree-sitter indent rules for `js-ts-mode'.")
(defun js--treesit-indent-rules () (defun js--treesit-indent-rules ()
"Return tree-sitter indent rules for `js-ts-mode'. "Return tree-sitter indent rules for `js-ts-mode'."
`((javascript
((parent-is "program") parent-bol 0)
((node-is "}") standalone-parent 0)
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)
((node-is ">") parent-bol 0)
((and (parent-is "comment") c-ts-common-looking-at-star)
c-ts-common-comment-start-after-first-star -1)
((parent-is "comment") prev-adaptive-prefix 0)
((n-p-gp "identifier" "ternary_expression" "parenthesized_expression")
parent 0)
((parent-is "ternary_expression") parent-bol js-indent-level)
((parent-is "sequence_expression") parent 0)
((parent-is "member_expression") js--treesit-member-chained-expression-helper 0)
((parent-is "named_imports") parent-bol js-indent-level)
((parent-is "statement_block") standalone-parent js-indent-level)
((parent-is "variable_declarator") parent 0)
((parent-is "arguments") parent-bol js-indent-level)
((parent-is "array") parent-bol js-indent-level)
((parent-is "formal_parameters") parent-bol js-indent-level)
((parent-is "template_string") no-indent) ; Don't indent the string contents.
((parent-is "template_substitution") parent-bol js-indent-level)
((parent-is "object_pattern") parent-bol js-indent-level)
((parent-is "object") parent-bol js-indent-level)
((parent-is "pair") parent-bol js-indent-level)
((parent-is "arrow_function") js--treesit-arrow-function-helper 0)
((parent-is "parenthesized_expression") parent-bol js-indent-level)
((parent-is "binary_expression") parent-bol js-indent-level)
((parent-is "assignment_expression") parent-bol js-indent-level)
((parent-is "class_body") parent-bol js-indent-level)
;; "{" on the newline, should stay here.
((node-is "statement_block") parent-bol 0)
((parent-is "switch_statement") parent-bol 0)
((parent-is "switch_body") js--treesit-switch-body-helper 0)
((parent-is ,(rx "switch_" (or "case" "default"))) parent-bol js-indent-level)
((match "while" "do_statement") parent-bol 0)
((match "else" "if_statement") parent-bol 0)
((parent-is ,(rx (or (seq (or "if" "for" "for_in" "while" "do") "_statement")
"else_clause")))
parent-bol js-indent-level)
Tree-sitter indent rules are evaluated the first time this function is ;; JSX
called. Subsequent calls return the first evaluated value." ,@(js-jsx--treesit-indent-compatibility-bb1f97b)
(or js--treesit-indent-rules-cached ((node-is "jsx_closing_element") parent 0)
(setq js--treesit-indent-rules-cached ((match "jsx_element" "statement") parent js-indent-level)
`((javascript ((parent-is "jsx_element") parent js-indent-level)
((parent-is "program") parent-bol 0) ((parent-is "jsx_text") parent-bol js-indent-level)
((node-is "}") standalone-parent 0) ((parent-is "jsx_opening_element") parent js-indent-level)
((node-is ")") parent-bol 0) ((parent-is "jsx_expression") parent-bol js-indent-level)
((node-is "]") parent-bol 0) ((match "/" "jsx_self_closing_element") parent 0)
((node-is ">") parent-bol 0) ((parent-is "jsx_self_closing_element") parent js-indent-level)
((and (parent-is "comment") c-ts-common-looking-at-star) ;; FIXME(Theo): This no-node catch-all should be removed. When is it needed?
c-ts-common-comment-start-after-first-star -1) (no-node parent-bol 0))
((parent-is "comment") prev-adaptive-prefix 0) (jsdoc
((n-p-gp "identifier" "ternary_expression" "parenthesized_expression") ((and (parent-is "document") c-ts-common-looking-at-star)
parent 0) c-ts-common-comment-start-after-first-star -1))))
((parent-is "ternary_expression") parent-bol js-indent-level)
((parent-is "sequence_expression") parent 0)
((parent-is "member_expression") js--treesit-member-chained-expression-helper 0)
((parent-is "named_imports") parent-bol js-indent-level)
((parent-is "statement_block") standalone-parent js-indent-level)
((parent-is "variable_declarator") parent 0)
((parent-is "arguments") parent-bol js-indent-level)
((parent-is "array") parent-bol js-indent-level)
((parent-is "formal_parameters") parent-bol js-indent-level)
((parent-is "template_string") no-indent) ; Don't indent the string contents.
((parent-is "template_substitution") parent-bol js-indent-level)
((parent-is "object_pattern") parent-bol js-indent-level)
((parent-is "object") parent-bol js-indent-level)
((parent-is "pair") parent-bol js-indent-level)
((parent-is "arrow_function") js--treesit-arrow-function-helper 0)
((parent-is "parenthesized_expression") parent-bol js-indent-level)
((parent-is "binary_expression") parent-bol js-indent-level)
((parent-is "assignment_expression") parent-bol js-indent-level)
((parent-is "class_body") parent-bol js-indent-level)
;; "{" on the newline, should stay here.
((node-is "statement_block") parent-bol 0)
((parent-is "switch_statement") parent-bol 0)
((parent-is "switch_body") js--treesit-switch-body-helper 0)
((parent-is ,(rx "switch_" (or "case" "default"))) parent-bol js-indent-level)
((match "while" "do_statement") parent-bol 0)
((match "else" "if_statement") parent-bol 0)
((parent-is ,(rx (or (seq (or "if" "for" "for_in" "while" "do") "_statement")
"else_clause")))
parent-bol js-indent-level)
;; JSX
,@(js-jsx--treesit-indent-compatibility-bb1f97b)
((node-is "jsx_closing_element") parent 0)
((match "jsx_element" "statement") parent js-indent-level)
((parent-is "jsx_element") parent js-indent-level)
((parent-is "jsx_text") parent-bol js-indent-level)
((parent-is "jsx_opening_element") parent js-indent-level)
((parent-is "jsx_expression") parent-bol js-indent-level)
((match "/" "jsx_self_closing_element") parent 0)
((parent-is "jsx_self_closing_element") parent js-indent-level)
;; FIXME(Theo): This no-node catch-all should be removed. When is it needed?
(no-node parent-bol 0))
(jsdoc
((and (parent-is "document") c-ts-common-looking-at-star)
c-ts-common-comment-start-after-first-star -1))))))
(defvar js--treesit-keywords (defvar js--treesit-keywords
'("as" "async" "await" "break" "case" "catch" "class" "const" "continue" '("as" "async" "await" "break" "case" "catch" "class" "const" "continue"
@ -3595,162 +3587,154 @@ called. Subsequent calls return the first evaluated value."
"&&" "||" "!") "&&" "||" "!")
"JavaScript operators for tree-sitter font-locking.") "JavaScript operators for tree-sitter font-locking.")
(defvar js--treesit-font-lock-settings-cached nil
"Cached tree-sitter font-lock settings for `js-ts-mode'.")
(defun js--treesit-font-lock-settings () (defun js--treesit-font-lock-settings ()
"Return tree-sitter font-lock settings for `js-ts-mode'. "Return tree-sitter font-lock settings for `js-ts-mode'."
(treesit-font-lock-rules
Tree-sitter font-lock settings are evaluated the first time this :language 'javascript
function is called. Subsequent calls return the first evaluated value." :feature 'comment
(or js--treesit-font-lock-settings-cached '([(comment) (hash_bang_line)] @font-lock-comment-face)
(setq js--treesit-font-lock-settings-cached
(treesit-font-lock-rules
:language 'javascript :language 'javascript
:feature 'comment :feature 'constant
'([(comment) (hash_bang_line)] @font-lock-comment-face) '(((identifier) @font-lock-constant-face
(:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
:language 'javascript [(true) (false) (null)] @font-lock-constant-face)
:feature 'constant
'(((identifier) @font-lock-constant-face
(:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
[(true) (false) (null)] @font-lock-constant-face) :language 'javascript
:feature 'keyword
`([,@js--treesit-keywords] @font-lock-keyword-face
[(this) (super)] @font-lock-keyword-face)
:language 'javascript :language 'javascript
:feature 'keyword :feature 'string
`([,@js--treesit-keywords] @font-lock-keyword-face '((regex pattern: (regex_pattern)) @font-lock-regexp-face
[(this) (super)] @font-lock-keyword-face) (string) @font-lock-string-face)
:language 'javascript :language 'javascript
:feature 'string :feature 'string-interpolation
'((regex pattern: (regex_pattern)) @font-lock-regexp-face :override t
(string) @font-lock-string-face) '((template_string) @js--fontify-template-string
(template_substitution ["${" "}"] @font-lock-misc-punctuation-face))
:language 'javascript :language 'javascript
:feature 'string-interpolation :feature 'definition
:override t `(,@(js--treesit-font-lock-compatibility-definition-feature)
'((template_string) @js--fontify-template-string
(template_substitution ["${" "}"] @font-lock-misc-punctuation-face))
:language 'javascript (class
:feature 'definition name: (identifier) @font-lock-type-face)
`(,@(js--treesit-font-lock-compatibility-definition-feature)
(class (class_declaration
name: (identifier) @font-lock-type-face) name: (identifier) @font-lock-type-face)
(class_declaration (function_declaration
name: (identifier) @font-lock-type-face) name: (identifier) @font-lock-function-name-face)
(function_declaration (method_definition
name: (identifier) @font-lock-function-name-face) name: (property_identifier) @font-lock-function-name-face)
(method_definition (formal_parameters
name: (property_identifier) @font-lock-function-name-face) [(identifier) @font-lock-variable-name-face
(array_pattern (identifier) @font-lock-variable-name-face)
(object_pattern (shorthand_property_identifier_pattern) @font-lock-variable-name-face)])
(formal_parameters (variable_declarator
[(identifier) @font-lock-variable-name-face name: (identifier) @font-lock-variable-name-face)
(array_pattern (identifier) @font-lock-variable-name-face)
(object_pattern (shorthand_property_identifier_pattern) @font-lock-variable-name-face)])
(variable_declarator (variable_declarator
name: (identifier) @font-lock-variable-name-face) name: [(array_pattern (identifier) @font-lock-variable-name-face)
(object_pattern
(shorthand_property_identifier_pattern) @font-lock-variable-name-face)])
(variable_declarator ;; full module imports
name: [(array_pattern (identifier) @font-lock-variable-name-face) (import_clause (identifier) @font-lock-variable-name-face)
(object_pattern ;; named imports with aliasing
(shorthand_property_identifier_pattern) @font-lock-variable-name-face)]) (import_clause (named_imports (import_specifier
alias: (identifier) @font-lock-variable-name-face)))
;; named imports without aliasing
(import_clause (named_imports (import_specifier
!alias
name: (identifier) @font-lock-variable-name-face)))
;; full module imports ;; full namespace import (* as alias)
(import_clause (identifier) @font-lock-variable-name-face) (import_clause (namespace_import (identifier) @font-lock-variable-name-face)))
;; named imports with aliasing
(import_clause (named_imports (import_specifier
alias: (identifier) @font-lock-variable-name-face)))
;; named imports without aliasing
(import_clause (named_imports (import_specifier
!alias
name: (identifier) @font-lock-variable-name-face)))
;; full namespace import (* as alias) :language 'javascript
(import_clause (namespace_import (identifier) @font-lock-variable-name-face))) :feature 'assignment
'((assignment_expression
left: (_) @js--treesit-fontify-assignment-lhs))
:language 'javascript :language 'javascript
:feature 'assignment :feature 'function
'((assignment_expression '((call_expression
left: (_) @js--treesit-fontify-assignment-lhs)) function: [(identifier) @font-lock-function-call-face
(member_expression
property:
(property_identifier) @font-lock-function-call-face)]))
:language 'javascript :language 'javascript
:feature 'function :feature 'jsx
'((call_expression '((jsx_opening_element name: (_) @font-lock-function-call-face)
function: [(identifier) @font-lock-function-call-face (jsx_closing_element name: (_) @font-lock-function-call-face)
(member_expression (jsx_self_closing_element name: (_) @font-lock-function-call-face)
property: (jsx_attribute (property_identifier) @font-lock-constant-face))
(property_identifier) @font-lock-function-call-face)]))
:language 'javascript :language 'javascript
:feature 'jsx :feature 'property
'((jsx_opening_element name: (_) @font-lock-function-call-face) '(((property_identifier) @font-lock-property-use-face)
(jsx_closing_element name: (_) @font-lock-function-call-face) (pair value: (identifier) @font-lock-variable-use-face)
(jsx_self_closing_element name: (_) @font-lock-function-call-face) ((shorthand_property_identifier) @font-lock-property-use-face))
(jsx_attribute (property_identifier) @font-lock-constant-face))
:language 'javascript :language 'javascript
:feature 'property :feature 'number
'(((property_identifier) @font-lock-property-use-face) '((number) @font-lock-number-face
(pair value: (identifier) @font-lock-variable-use-face) ((identifier) @font-lock-number-face
((shorthand_property_identifier) @font-lock-property-use-face)) (:match "\\`\\(?:NaN\\|Infinity\\)\\'" @font-lock-number-face)))
:language 'javascript :language 'javascript
:feature 'number :feature 'operator
'((number) @font-lock-number-face `([,@js--treesit-operators] @font-lock-operator-face
((identifier) @font-lock-number-face (ternary_expression ["?" ":"] @font-lock-operator-face))
(:match "\\`\\(?:NaN\\|Infinity\\)\\'" @font-lock-number-face)))
:language 'javascript :language 'javascript
:feature 'operator :feature 'bracket
`([,@js--treesit-operators] @font-lock-operator-face '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
(ternary_expression ["?" ":"] @font-lock-operator-face))
:language 'javascript :language 'javascript
:feature 'bracket :feature 'delimiter
'((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) '((["," "." ";" ":"]) @font-lock-delimiter-face)
:language 'javascript :language 'javascript
:feature 'delimiter :feature 'escape-sequence
'((["," "." ";" ":"]) @font-lock-delimiter-face) :override t
'((escape_sequence) @font-lock-escape-face)
:language 'javascript ;; "document" should be first, to avoid overlap.
:feature 'escape-sequence :language 'jsdoc
:override t :override t
'((escape_sequence) @font-lock-escape-face) :feature 'document
'((document) @font-lock-doc-face)
;; "document" should be first, to avoid overlap. :language 'jsdoc
:language 'jsdoc :override t
:override t :feature 'keyword
:feature 'document '((tag_name) @font-lock-doc-markup-face)
'((document) @font-lock-doc-face)
:language 'jsdoc :language 'jsdoc
:override t :override t
:feature 'keyword :feature 'bracket
'((tag_name) @font-lock-doc-markup-face) '((["{" "}"]) @font-lock-bracket-face)
:language 'jsdoc :language 'jsdoc
:override t :override t
:feature 'bracket :feature 'property
'((["{" "}"]) @font-lock-bracket-face) '((type) @font-lock-type-face)
:language 'jsdoc :language 'jsdoc
:override t :override t
:feature 'property :feature 'definition
'((type) @font-lock-type-face) '((identifier) @font-lock-variable-name-face)))
:language 'jsdoc
:override t
:feature 'definition
'((identifier) @font-lock-variable-name-face)))))
(defun js--fontify-template-string (node override start end &rest _) (defun js--fontify-template-string (node override start end &rest _)
"Fontify template string but not substitution inside it. "Fontify template string but not substitution inside it.

View file

@ -955,244 +955,228 @@ characters of the current line."
("::" . ?∷)) ("::" . ?∷))
"Value for `prettify-symbols-alist' in `php-ts-mode'.") "Value for `prettify-symbols-alist' in `php-ts-mode'.")
(defvar php-ts-mode--font-lock-settings-cached nil
"Cached tree-sitter font-lock settings for `php-ts-mode'.")
(defun php-ts-mode--font-lock-settings () (defun php-ts-mode--font-lock-settings ()
"Return tree-sitter font-lock settings for `php-ts-mode'. "Return tree-sitter font-lock settings for `php-ts-mode'."
(treesit-font-lock-rules
Tree-sitter font-lock settings are evaluated the first time this :language 'php
function is called. Subsequent calls return the first evaluated value." :feature 'keyword
(or php-ts-mode--font-lock-settings-cached :override t
(setq php-ts-mode--font-lock-settings-cached `([,@(php-ts-mode--keywords)] @font-lock-keyword-face
(treesit-font-lock-rules ,@(when (php-ts-mode--test-visibility-modifier-operation-p)
'((visibility_modifier (operation) @font-lock-builtin-face)))
(var_modifier) @font-lock-builtin-face)
:language 'php :language 'php
:feature 'keyword :feature 'comment
:override t :override t
`([,@(php-ts-mode--keywords)] @font-lock-keyword-face '((comment) @font-lock-comment-face)
,@(when (php-ts-mode--test-visibility-modifier-operation-p)
'((visibility_modifier (operation) @font-lock-builtin-face)))
(var_modifier) @font-lock-builtin-face)
:language 'php :language 'php
:feature 'comment :feature 'constant
:override t `((boolean) @font-lock-constant-face
'((comment) @font-lock-comment-face) (null) @font-lock-constant-face
;; predefined constant or built in constant (part of PHP core)
((name) @font-lock-builtin-face
(:match ,(rx-to-string
`(: bos (or ,@php-ts-mode--predefined-constant) eos))
@font-lock-builtin-face))
;; user defined constant
((name) @font-lock-constant-face
(:match "\\`_*[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face))
(const_declaration
(const_element (name) @font-lock-constant-face))
;; declare directive
(declare_directive ["strict_types" "encoding" "ticks"] @font-lock-constant-face))
:language 'php :language 'php
:feature 'constant :feature 'name
`((boolean) @font-lock-constant-face '((goto_statement (name) @font-lock-constant-face)
(null) @font-lock-constant-face (named_label_statement (name) @font-lock-constant-face))
;; predefined constant or built in constant (part of PHP core)
((name) @font-lock-builtin-face
(:match ,(rx-to-string
`(: bos (or ,@php-ts-mode--predefined-constant) eos))
@font-lock-builtin-face))
;; user defined constant
((name) @font-lock-constant-face
(:match "\\`_*[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face))
(const_declaration
(const_element (name) @font-lock-constant-face))
;; declare directive
(declare_directive ["strict_types" "encoding" "ticks"] @font-lock-constant-face))
:language 'php :language 'php
:feature 'name :feature 'delimiter
'((goto_statement (name) @font-lock-constant-face) `((["," ":" ";" "\\"]) @font-lock-delimiter-face)
(named_label_statement (name) @font-lock-constant-face))
:language 'php :language 'php
:feature 'delimiter :feature 'operator
`((["," ":" ";" "\\"]) @font-lock-delimiter-face) `((error_suppression_expression "@" @font-lock-keyword-face)
[,@(php-ts-mode--operators)] @font-lock-operator-face)
:language 'php :language 'php
:feature 'operator :feature 'variable-name
`((error_suppression_expression "@" @font-lock-keyword-face) :override t
[,@(php-ts-mode--operators)] @font-lock-operator-face) '(((name) @font-lock-keyword-face (:equal "this" @font-lock-keyword-face))
(variable_name (name) @font-lock-variable-name-face)
(relative_scope ["parent" "self" "static"] @font-lock-builtin-face)
(relative_scope) @font-lock-constant-face
(dynamic_variable_name (name) @font-lock-variable-name-face)
(member_access_expression
name: (_) @font-lock-variable-name-face)
(scoped_property_access_expression
scope: (name) @font-lock-constant-face)
(nullsafe_member_access_expression (name) @font-lock-variable-name-face)
(error_suppression_expression (name) @font-lock-property-name-face))
:language 'php :language 'php
:feature 'variable-name :feature 'string
:override t `(("\"") @font-lock-string-face
'(((name) @font-lock-keyword-face (:equal "this" @font-lock-keyword-face)) (encapsed_string) @font-lock-string-face
(variable_name (name) @font-lock-variable-name-face) (string_content) @font-lock-string-face
(relative_scope ["parent" "self" "static"] @font-lock-builtin-face) (string) @font-lock-string-face)
(relative_scope) @font-lock-constant-face
(dynamic_variable_name (name) @font-lock-variable-name-face)
(member_access_expression
name: (_) @font-lock-variable-name-face)
(scoped_property_access_expression
scope: (name) @font-lock-constant-face)
(nullsafe_member_access_expression (name) @font-lock-variable-name-face)
(error_suppression_expression (name) @font-lock-property-name-face))
:language 'php :language 'php
:feature 'string :feature 'literal
`(("\"") @font-lock-string-face '((integer) @font-lock-number-face
(encapsed_string) @font-lock-string-face (float) @font-lock-number-face
(string_content) @font-lock-string-face (heredoc identifier: (heredoc_start) @font-lock-constant-face)
(string) @font-lock-string-face) (heredoc_body (string_content) @font-lock-string-face)
(heredoc end_tag: (heredoc_end) @font-lock-constant-face)
(nowdoc identifier: (heredoc_start) @font-lock-constant-face)
(nowdoc_body (nowdoc_string) @font-lock-string-face)
(nowdoc end_tag: (heredoc_end) @font-lock-constant-face)
(shell_command_expression) @font-lock-string-face)
:language 'php :language 'php
:feature 'literal :feature 'type
'((integer) @font-lock-number-face :override t
(float) @font-lock-number-face '((union_type "|" @font-lock-operator-face)
(heredoc identifier: (heredoc_start) @font-lock-constant-face) (union_type) @font-lock-type-face
(heredoc_body (string_content) @font-lock-string-face) (bottom_type) @font-lock-type-face
(heredoc end_tag: (heredoc_end) @font-lock-constant-face) (primitive_type) @font-lock-type-face
(nowdoc identifier: (heredoc_start) @font-lock-constant-face) ((primitive_type) @font-lock-keyword-face
(nowdoc_body (nowdoc_string) @font-lock-string-face) (:equal "callable" @font-lock-keyword-face))
(nowdoc end_tag: (heredoc_end) @font-lock-constant-face) (cast_type) @font-lock-type-face
(shell_command_expression) @font-lock-string-face) (named_type) @font-lock-type-face
(optional_type) @font-lock-type-face)
:language 'php :language 'php
:feature 'type :feature 'definition
:override t :override t
'((union_type "|" @font-lock-operator-face) `((php_tag) @font-lock-preprocessor-face
(union_type) @font-lock-type-face ,@(if (php-ts-mode--test-php-end-tag-p)
(bottom_type) @font-lock-type-face '((php_end_tag) @font-lock-preprocessor-face)
(primitive_type) @font-lock-type-face '(("?>") @font-lock-preprocessor-face))
((primitive_type) @font-lock-keyword-face ;; Highlights identifiers in declarations.
(:equal "callable" @font-lock-keyword-face)) (class_declaration
(cast_type) @font-lock-type-face name: (_) @font-lock-type-face)
(named_type) @font-lock-type-face (class_interface_clause (name) @font-lock-type-face)
(optional_type) @font-lock-type-face) (interface_declaration
name: (_) @font-lock-type-face)
(trait_declaration
name: (_) @font-lock-type-face)
(enum_declaration
name: (_) @font-lock-type-face)
(function_definition
name: (_) @font-lock-function-name-face)
,@(when (php-ts-mode--test-property-hook-p)
'((property_hook (name) @font-lock-function-name-face)))
(method_declaration
name: (_) @font-lock-function-name-face)
(method_declaration
name: (name) @font-lock-builtin-face
(:match ,(rx-to-string
`(: bos (or ,@php-ts-mode--class-magic-methods) eos))
@font-lock-builtin-face))
("=>") @font-lock-keyword-face
(object_creation_expression
(name) @font-lock-type-face)
,@(when (php-ts-mode--test-namespace-name-as-prefix-p)
'((namespace_name_as_prefix "\\" @font-lock-delimiter-face)
(namespace_name_as_prefix
(namespace_name (name)) @font-lock-type-face)))
,@(if (php-ts-mode--test-namespace-aliasing-clause-p)
'((namespace_aliasing_clause (name) @font-lock-type-face))
'((namespace_use_clause alias: (name) @font-lock-type-face)))
,@(when (not (php-ts-mode--test-namespace-use-group-clause-p))
'((namespace_use_group
(namespace_use_clause (name) @font-lock-type-face))))
(namespace_use_clause (name) @font-lock-type-face)
(namespace_name "\\" @font-lock-delimiter-face)
(namespace_name (name) @font-lock-type-face)
(use_declaration (name) @font-lock-property-use-face)
(use_instead_of_clause (name) @font-lock-type-face)
(binary_expression
operator: "instanceof"
right: (name) @font-lock-type-face))
:language 'php :language 'php
:feature 'definition :feature 'function-scope
:override t :override t
`((php_tag) @font-lock-preprocessor-face '((scoped_call_expression
,@(if (php-ts-mode--test-php-end-tag-p) scope: (name) @font-lock-constant-face)
'((php_end_tag) @font-lock-preprocessor-face) (class_constant_access_expression (name) @font-lock-constant-face))
'(("?>") @font-lock-preprocessor-face))
;; Highlights identifiers in declarations.
(class_declaration
name: (_) @font-lock-type-face)
(class_interface_clause (name) @font-lock-type-face)
(interface_declaration
name: (_) @font-lock-type-face)
(trait_declaration
name: (_) @font-lock-type-face)
(enum_declaration
name: (_) @font-lock-type-face)
(function_definition
name: (_) @font-lock-function-name-face)
,@(when (php-ts-mode--test-property-hook-p)
'((property_hook (name) @font-lock-function-name-face)))
(method_declaration
name: (_) @font-lock-function-name-face)
(method_declaration
name: (name) @font-lock-builtin-face
(:match ,(rx-to-string
`(: bos (or ,@php-ts-mode--class-magic-methods) eos))
@font-lock-builtin-face))
("=>") @font-lock-keyword-face
(object_creation_expression
(name) @font-lock-type-face)
,@(when (php-ts-mode--test-namespace-name-as-prefix-p)
'((namespace_name_as_prefix "\\" @font-lock-delimiter-face)
(namespace_name_as_prefix
(namespace_name (name)) @font-lock-type-face)))
,@(if (php-ts-mode--test-namespace-aliasing-clause-p)
'((namespace_aliasing_clause (name) @font-lock-type-face))
'((namespace_use_clause alias: (name) @font-lock-type-face)))
,@(when (not (php-ts-mode--test-namespace-use-group-clause-p))
'((namespace_use_group
(namespace_use_clause (name) @font-lock-type-face))))
(namespace_use_clause (name) @font-lock-type-face)
(namespace_name "\\" @font-lock-delimiter-face)
(namespace_name (name) @font-lock-type-face)
(use_declaration (name) @font-lock-property-use-face)
(use_instead_of_clause (name) @font-lock-type-face)
(binary_expression
operator: "instanceof"
right: (name) @font-lock-type-face))
:language 'php :language 'php
:feature 'function-scope :feature 'function-call
:override t :override t
'((scoped_call_expression '((function_call_expression
scope: (name) @font-lock-constant-face) function: (name) @font-lock-function-call-face)
(class_constant_access_expression (name) @font-lock-constant-face)) (scoped_call_expression
name: (name) @font-lock-function-call-face)
(member_call_expression
name: (name) @font-lock-function-call-face)
(nullsafe_member_call_expression
name: (_) @font-lock-function-call-face))
:language 'php :language 'php
:feature 'function-call :feature 'argument
:override t '((argument
'((function_call_expression name: (_) @font-lock-constant-face))
function: (name) @font-lock-function-call-face)
(scoped_call_expression
name: (name) @font-lock-function-call-face)
(member_call_expression
name: (name) @font-lock-function-call-face)
(nullsafe_member_call_expression
name: (_) @font-lock-function-call-face))
:language 'php :language 'php
:feature 'argument :feature 'escape-sequence
'((argument :override t
name: (_) @font-lock-constant-face)) '((string (escape_sequence) @font-lock-escape-face)
(encapsed_string (escape_sequence) @font-lock-escape-face)
(heredoc_body (escape_sequence) @font-lock-escape-face))
:language 'php :language 'php
:feature 'escape-sequence :feature 'base-clause
:override t :override t
'((string (escape_sequence) @font-lock-escape-face) `((base_clause (name) @font-lock-type-face)
(encapsed_string (escape_sequence) @font-lock-escape-face) (use_as_clause (name) @font-lock-property-use-face)
(heredoc_body (escape_sequence) @font-lock-escape-face)) ,@(when (not (php-ts-mode--test-namespace-name-as-prefix-p))
'((qualified_name prefix: "\\" @font-lock-delimiter-face)))
(qualified_name (name) @font-lock-constant-face)
,@(when (php-ts-mode--test-relative-name-p)
'((relative_name (name) @font-lock-constant-face))))
:language 'php :language 'php
:feature 'base-clause :feature 'property
:override t '((enum_case
`((base_clause (name) @font-lock-type-face) name: (_) @font-lock-type-face))
(use_as_clause (name) @font-lock-property-use-face)
,@(when (not (php-ts-mode--test-namespace-name-as-prefix-p))
'((qualified_name prefix: "\\" @font-lock-delimiter-face)))
(qualified_name (name) @font-lock-constant-face)
,@(when (php-ts-mode--test-relative-name-p)
'((relative_name (name) @font-lock-constant-face))))
:language 'php :language 'php
:feature 'property :feature 'attribute
'((enum_case '((((attribute (_) @attribute_name) @font-lock-preprocessor-face)
name: (_) @font-lock-type-face)) (:equal "Deprecated" @attribute_name))
(attribute_group (attribute (name) @font-lock-constant-face)))
:language 'php :language 'php
:feature 'attribute :feature 'bracket
'((((attribute (_) @attribute_name) @font-lock-preprocessor-face) '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
(:equal "Deprecated" @attribute_name))
(attribute_group (attribute (name) @font-lock-constant-face)))
:language 'php :language 'php
:feature 'bracket :feature 'error
'((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) :override t
'((ERROR) @php-ts-mode--fontify-error)))
:language 'php
:feature 'error
:override t
'((ERROR) @php-ts-mode--fontify-error)))))
;;; Font-lock helpers ;;; Font-lock helpers
(defvar php-ts-mode--custom-html-font-lock-settings-cached nil
"Cached tree-sitter font-lock settings for HTML when embedded in PHP.")
(defun php-ts-mode--custom-html-font-lock-settings () (defun php-ts-mode--custom-html-font-lock-settings ()
"Tree-sitter Font-lock settings for HTML when embedded in PHP. "Tree-sitter Font-lock settings for HTML when embedded in PHP.
Like `mhtml-ts-mode--font-lock-settings' but adapted for `php-ts-mode'. Like `mhtml-ts-mode--font-lock-settings' but adapted for `php-ts-mode'."
(treesit-replace-font-lock-feature-settings
Tree-sitter font-lock settings are evaluated the first time this (treesit-font-lock-rules
function is called. Subsequent calls return the first evaluated value." :language 'html
(or php-ts-mode--custom-html-font-lock-settings-cached :override t
(setq php-ts-mode--custom-html-font-lock-settings-cached :feature 'comment
(treesit-replace-font-lock-feature-settings '((comment) @font-lock-comment-face
(treesit-font-lock-rules ;; handle shebang path and others type of comment
:language 'html (document (text) @font-lock-comment-face)))
:override t (mhtml-ts-mode--treesit-font-lock-settings)))
:feature 'comment
'((comment) @font-lock-comment-face
;; handle shebang path and others type of comment
(document (text) @font-lock-comment-face)))
(mhtml-ts-mode--treesit-font-lock-settings)))))
(defvar php-ts-mode--phpdoc-font-lock-settings (defvar php-ts-mode--phpdoc-font-lock-settings
(treesit-font-lock-rules (treesit-font-lock-rules

View file

@ -259,28 +259,20 @@ NODE and PARENT are ignored."
css--treesit-font-lock-feature-list)) css--treesit-font-lock-feature-list))
"Settings for `treesit-font-lock-feature-list'.") "Settings for `treesit-font-lock-feature-list'.")
(defvar mhtml-ts-mode--treesit-font-lock-settings-cached nil
"Cached tree-sitter font-lock settings for `mhtml-ts-mode'.")
(defun mhtml-ts-mode--treesit-font-lock-settings () (defun mhtml-ts-mode--treesit-font-lock-settings ()
"Return tree-sitter font-lock settings for `mhtml-ts-mode'. "Return tree-sitter font-lock settings for `mhtml-ts-mode'."
(append html-ts-mode--font-lock-settings
Tree-sitter font-lock settings are evaluated the first time this (js--treesit-font-lock-settings)
function is called. Subsequent calls return the first evaluated value." ;; Let's replace a css rule with a new one that adds
(or mhtml-ts-mode--treesit-font-lock-settings-cached ;; color to the css value.
(setq mhtml-ts-mode--treesit-font-lock-settings-cached (treesit-replace-font-lock-feature-settings
(append html-ts-mode--font-lock-settings (treesit-font-lock-rules
(js--treesit-font-lock-settings) :language 'css
;; Let's replace a css rule with a new one that adds :override t
;; color to the css value. :feature 'variable
(treesit-replace-font-lock-feature-settings '((plain_value) @mhtml-ts-mode--colorize-css-value
(treesit-font-lock-rules (color_value) @mhtml-ts-mode--colorize-css-value))
:language 'css css--treesit-settings)))
:override t
:feature 'variable
'((plain_value) @mhtml-ts-mode--colorize-css-value
(color_value) @mhtml-ts-mode--colorize-css-value))
css--treesit-settings)))))
(defvar mhtml-ts-mode--treesit-thing-settings (defvar mhtml-ts-mode--treesit-thing-settings
;; In addition to putting together the various definitions, we need to ;; In addition to putting together the various definitions, we need to
@ -300,34 +292,26 @@ function is called. Subsequent calls return the first evaluated value."
`((defun ,css--treesit-defun-type-regexp)))) `((defun ,css--treesit-defun-type-regexp))))
"Settings for `treesit-thing-settings'.") "Settings for `treesit-thing-settings'.")
(defvar mhtml-ts-mode--treesit-indent-rules-cached nil
"Cached tree-sitter indent rules for `mhtml-ts-mode'.")
(defun mhtml-ts-mode--treesit-indent-rules () (defun mhtml-ts-mode--treesit-indent-rules ()
"Return tree-sitter indent rules for `mhtml-ts-mode'. "Return tree-sitter indent rules for `mhtml-ts-mode'."
(treesit--indent-rules-optimize
Tree-sitter indent rules are evaluated the first time this function (append html-ts-mode--indent-rules
is called. Subsequent calls return the first evaluated value." ;; Extended rules for js and css, to indent
(or mhtml-ts-mode--treesit-indent-rules-cached ;; appropriately when injected into html
(setq mhtml-ts-mode--treesit-indent-rules-cached (treesit-simple-indent-modify-rules
(treesit--indent-rules-optimize 'javascript
(append html-ts-mode--indent-rules `((javascript ((parent-is "program")
;; Extended rules for js and css, to indent mhtml-ts-mode--js-css-tag-bol
;; appropriately when injected into html mhtml-ts-mode--js-css-indent-offset)))
(treesit-simple-indent-modify-rules (js--treesit-indent-rules)
'javascript :replace)
`((javascript ((parent-is "program") (treesit-simple-indent-modify-rules
mhtml-ts-mode--js-css-tag-bol 'css
mhtml-ts-mode--js-css-indent-offset))) `((css ((parent-is "stylesheet")
(js--treesit-indent-rules) mhtml-ts-mode--js-css-tag-bol
:replace) mhtml-ts-mode--js-css-indent-offset)))
(treesit-simple-indent-modify-rules css--treesit-indent-rules
'css :prepend))))
`((css ((parent-is "stylesheet")
mhtml-ts-mode--js-css-tag-bol
mhtml-ts-mode--js-css-indent-offset)))
css--treesit-indent-rules
:prepend))))))
(defvar mhtml-ts-mode--treesit-aggregated-simple-imenu-settings (defvar mhtml-ts-mode--treesit-aggregated-simple-imenu-settings
`((html ,@html-ts-mode--treesit-simple-imenu-settings) `((html ,@html-ts-mode--treesit-simple-imenu-settings)