2022-11-25 21:04:18 +01:00
|
|
|
;;; typescript-ts-mode.el --- tree sitter support for TypeScript -*- lexical-binding: t; -*-
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2023-01-01 05:31:12 -05:00
|
|
|
;; Copyright (C) 2022-2023 Free Software Foundation, Inc.
|
2022-10-11 10:27:55 +02:00
|
|
|
|
|
|
|
;; Author : Theodor Thornhill <theo@thornhill.no>
|
|
|
|
;; Maintainer : Theodor Thornhill <theo@thornhill.no>
|
|
|
|
;; Created : October 2022
|
|
|
|
;; Keywords : typescript tsx languages tree-sitter
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2022-12-08 23:56:24 +01:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2022-10-11 10:27:55 +02:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
2022-12-08 23:56:24 +01:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2022-10-11 10:27:55 +02:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2022-12-08 23:56:24 +01:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2022-11-29 21:39:38 +01:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
|
2022-10-11 23:49:04 -07:00
|
|
|
;;; Code:
|
|
|
|
|
2022-10-11 10:27:55 +02:00
|
|
|
(require 'treesit)
|
|
|
|
(require 'js)
|
2022-11-27 14:15:57 -08:00
|
|
|
(eval-when-compile (require 'rx))
|
2023-01-21 12:24:55 +01:00
|
|
|
(require 'c-ts-common) ; For comment indent and filling.
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2022-11-24 21:24:29 +02:00
|
|
|
(declare-function treesit-parser-create "treesit.c")
|
|
|
|
|
2022-11-25 21:04:18 +01:00
|
|
|
(defcustom typescript-ts-mode-indent-offset 2
|
|
|
|
"Number of spaces for each indentation step in `typescript-ts-mode'."
|
2022-11-14 08:03:11 +01:00
|
|
|
:version "29.1"
|
2022-10-11 10:27:55 +02:00
|
|
|
:type 'integer
|
|
|
|
:safe 'integerp
|
|
|
|
:group 'typescript)
|
|
|
|
|
2022-11-25 21:04:18 +01:00
|
|
|
(defvar typescript-ts-mode--syntax-table
|
2022-10-11 10:27:55 +02:00
|
|
|
(let ((table (make-syntax-table)))
|
|
|
|
;; Taken from the cc-langs version
|
|
|
|
(modify-syntax-entry ?_ "_" table)
|
|
|
|
(modify-syntax-entry ?\\ "\\" table)
|
|
|
|
(modify-syntax-entry ?+ "." table)
|
|
|
|
(modify-syntax-entry ?- "." table)
|
|
|
|
(modify-syntax-entry ?= "." table)
|
|
|
|
(modify-syntax-entry ?% "." table)
|
|
|
|
(modify-syntax-entry ?< "." table)
|
|
|
|
(modify-syntax-entry ?> "." table)
|
|
|
|
(modify-syntax-entry ?& "." table)
|
|
|
|
(modify-syntax-entry ?| "." table)
|
2022-12-05 13:37:58 +01:00
|
|
|
(modify-syntax-entry ?\' "\"" table)
|
2022-10-11 10:27:55 +02:00
|
|
|
(modify-syntax-entry ?\240 "." table)
|
2022-12-05 13:37:58 +01:00
|
|
|
(modify-syntax-entry ?/ ". 124b" table)
|
|
|
|
(modify-syntax-entry ?* ". 23" table)
|
|
|
|
(modify-syntax-entry ?\n "> b" table)
|
|
|
|
(modify-syntax-entry ?\^m "> b" table)
|
|
|
|
(modify-syntax-entry ?$ "_" table)
|
|
|
|
(modify-syntax-entry ?` "\"" table)
|
2022-10-11 10:27:55 +02:00
|
|
|
table)
|
2022-11-25 21:04:18 +01:00
|
|
|
"Syntax table for `typescript-ts-mode'.")
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
(defun typescript-ts-mode--indent-rules (language)
|
|
|
|
"Rules used for indentation.
|
|
|
|
Argument LANGUAGE is either `typescript' or `tsx'."
|
|
|
|
`((,language
|
2023-01-20 22:37:47 +01:00
|
|
|
((parent-is "program") point-min 0)
|
2022-10-11 10:27:55 +02:00
|
|
|
((node-is "}") parent-bol 0)
|
|
|
|
((node-is ")") parent-bol 0)
|
|
|
|
((node-is "]") parent-bol 0)
|
|
|
|
((node-is ">") parent-bol 0)
|
2023-01-21 12:24:55 +01:00
|
|
|
((and (parent-is "comment") c-ts-common-looking-at-star)
|
|
|
|
c-ts-common-comment-start-after-first-star -1)
|
2022-12-25 11:21:50 -08:00
|
|
|
((parent-is "comment") prev-adaptive-prefix 0)
|
2022-11-25 21:04:18 +01:00
|
|
|
((parent-is "ternary_expression") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "member_expression") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "named_imports") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "statement_block") parent-bol typescript-ts-mode-indent-offset)
|
2023-02-20 13:38:55 +01:00
|
|
|
((parent-is "switch_case") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "switch_default") parent-bol typescript-ts-mode-indent-offset)
|
2022-11-25 21:04:18 +01:00
|
|
|
((parent-is "type_arguments") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "variable_declarator") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "arguments") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "array") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "formal_parameters") parent-bol typescript-ts-mode-indent-offset)
|
2023-02-14 20:53:55 +01:00
|
|
|
((parent-is "template_string") no-indent) ; Don't indent the string contents.
|
2022-11-25 21:04:18 +01:00
|
|
|
((parent-is "template_substitution") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "object_pattern") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "object") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "object_type") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "enum_body") parent-bol typescript-ts-mode-indent-offset)
|
2022-11-29 16:12:18 +01:00
|
|
|
((parent-is "class_body") parent-bol typescript-ts-mode-indent-offset)
|
2022-11-25 21:04:18 +01:00
|
|
|
((parent-is "arrow_function") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "parenthesized_expression") parent-bol typescript-ts-mode-indent-offset)
|
2022-12-14 21:23:33 +01:00
|
|
|
((parent-is "binary_expression") parent-bol typescript-ts-mode-indent-offset)
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
,@(when (eq language 'tsx)
|
2023-01-15 21:31:16 +01:00
|
|
|
`(((match "<" "jsx_fragment") parent 0)
|
|
|
|
((parent-is "jsx_fragment") parent typescript-ts-mode-indent-offset)
|
2022-11-29 21:39:38 +01:00
|
|
|
((node-is "jsx_closing_element") parent 0)
|
2023-02-18 23:10:13 +01:00
|
|
|
((match "jsx_element" "statement") parent typescript-ts-mode-indent-offset)
|
2023-01-15 21:31:16 +01:00
|
|
|
((parent-is "jsx_element") parent typescript-ts-mode-indent-offset)
|
2023-02-18 23:10:13 +01:00
|
|
|
((parent-is "jsx_text") parent-bol typescript-ts-mode-indent-offset)
|
2023-01-15 21:31:16 +01:00
|
|
|
((parent-is "jsx_opening_element") parent typescript-ts-mode-indent-offset)
|
|
|
|
((parent-is "jsx_expression") parent-bol typescript-ts-mode-indent-offset)
|
|
|
|
((match "/" "jsx_self_closing_element") parent 0)
|
|
|
|
((parent-is "jsx_self_closing_element") parent typescript-ts-mode-indent-offset)))
|
2023-02-18 23:10:13 +01:00
|
|
|
;; FIXME(Theo): This no-node catch-all should be removed. When is it needed?
|
2022-11-29 21:39:38 +01:00
|
|
|
(no-node parent-bol 0))))
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2022-11-25 21:04:18 +01:00
|
|
|
(defvar typescript-ts-mode--keywords
|
2022-10-17 12:49:19 +02:00
|
|
|
'("!" "abstract" "as" "async" "await" "break"
|
|
|
|
"case" "catch" "class" "const" "continue" "debugger"
|
|
|
|
"declare" "default" "delete" "do" "else" "enum"
|
|
|
|
"export" "extends" "finally" "for" "from" "function"
|
|
|
|
"get" "if" "implements" "import" "in" "instanceof" "interface"
|
|
|
|
"keyof" "let" "namespace" "new" "of" "private" "protected"
|
|
|
|
"public" "readonly" "return" "set" "static" "switch"
|
|
|
|
"target" "throw" "try" "type" "typeof" "var" "void"
|
|
|
|
"while" "with" "yield")
|
|
|
|
"TypeScript keywords for tree-sitter font-locking.")
|
|
|
|
|
2022-11-25 21:04:18 +01:00
|
|
|
(defvar typescript-ts-mode--operators
|
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces. Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.
2022-11-19 22:30:13 -05:00
|
|
|
'("=" "+=" "-=" "*=" "/=" "%=" "**=" "<<=" ">>=" ">>>=" "&=" "^="
|
|
|
|
"|=" "&&=" "||=" "??=" "==" "!=" "===" "!==" ">" ">=" "<" "<=" "+"
|
|
|
|
"-" "*" "/" "%" "++" "--" "**" "&" "|" "^" "~" "<<" ">>" ">>>"
|
|
|
|
"&&" "||" "!" "?.")
|
|
|
|
"TypeScript operators for tree-sitter font-locking.")
|
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
(defun typescript-ts-mode--font-lock-settings (language)
|
|
|
|
"Tree-sitter font-lock settings.
|
|
|
|
Argument LANGUAGE is either `typescript' or `tsx'."
|
2022-10-11 10:27:55 +02:00
|
|
|
(treesit-font-lock-rules
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'comment
|
2022-11-15 02:22:41 -08:00
|
|
|
`((comment) @font-lock-comment-face)
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'constant
|
|
|
|
`(((identifier) @font-lock-constant-face
|
2022-10-11 10:27:55 +02:00
|
|
|
(:match "^[A-Z_][A-Z_\\d]*$" @font-lock-constant-face))
|
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces. Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.
2022-11-19 22:30:13 -05:00
|
|
|
[(true) (false) (null)] @font-lock-constant-face)
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'keyword
|
2022-11-25 21:04:18 +01:00
|
|
|
`([,@typescript-ts-mode--keywords] @font-lock-keyword-face
|
2022-10-28 21:23:19 +02:00
|
|
|
[(this) (super)] @font-lock-keyword-face)
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'string
|
2023-01-06 19:56:20 +02:00
|
|
|
`((regex pattern: (regex_pattern)) @font-lock-regexp-face
|
2022-10-17 12:49:19 +02:00
|
|
|
(string) @font-lock-string-face
|
2022-10-19 16:44:04 -07:00
|
|
|
(template_string) @js--fontify-template-string
|
2023-01-06 16:17:50 +02:00
|
|
|
(template_substitution ["${" "}"] @font-lock-misc-punctuation-face))
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2023-01-25 10:38:09 +01:00
|
|
|
:override t ;; for functions assigned to variables
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'declaration
|
|
|
|
`((function
|
2022-10-11 10:27:55 +02:00
|
|
|
name: (identifier) @font-lock-function-name-face)
|
|
|
|
|
|
|
|
(function_declaration
|
|
|
|
name: (identifier) @font-lock-function-name-face)
|
|
|
|
|
|
|
|
(method_definition
|
|
|
|
name: (property_identifier) @font-lock-function-name-face)
|
2023-01-02 20:56:41 +01:00
|
|
|
(method_signature
|
|
|
|
name: (property_identifier) @font-lock-function-name-face)
|
2022-11-28 16:05:27 +01:00
|
|
|
(required_parameter (identifier) @font-lock-variable-name-face)
|
|
|
|
(optional_parameter (identifier) @font-lock-variable-name-face)
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2023-01-25 10:38:09 +01:00
|
|
|
(variable_declarator
|
|
|
|
name: (identifier) @font-lock-function-name-face
|
|
|
|
value: [(function) (arrow_function)])
|
|
|
|
|
2022-10-17 12:49:19 +02:00
|
|
|
(variable_declarator
|
|
|
|
name: (identifier) @font-lock-variable-name-face)
|
|
|
|
|
|
|
|
(enum_declaration (identifier) @font-lock-type-face)
|
|
|
|
|
2022-11-28 16:05:27 +01:00
|
|
|
(extends_clause value: (identifier) @font-lock-type-face)
|
|
|
|
;; extends React.Component<T>
|
|
|
|
(extends_clause value: (member_expression
|
|
|
|
object: (identifier) @font-lock-type-face
|
|
|
|
property: (property_identifier) @font-lock-type-face))
|
|
|
|
|
2022-10-28 21:23:19 +02:00
|
|
|
(arrow_function
|
|
|
|
parameter: (identifier) @font-lock-variable-name-face)
|
|
|
|
|
|
|
|
(variable_declarator
|
|
|
|
name: (array_pattern
|
|
|
|
(identifier)
|
|
|
|
(identifier) @font-lock-function-name-face)
|
2023-01-04 09:13:23 +01:00
|
|
|
value: (array (number) (function)))
|
|
|
|
|
|
|
|
(catch_clause
|
2023-01-09 11:17:53 +01:00
|
|
|
parameter: (identifier) @font-lock-variable-name-face)
|
|
|
|
|
2023-01-26 19:54:27 +01:00
|
|
|
;; full module imports
|
2023-01-09 11:17:53 +01:00
|
|
|
(import_clause (identifier) @font-lock-variable-name-face)
|
2023-01-26 19:54:27 +01:00
|
|
|
;; 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)
|
|
|
|
(import_clause (namespace_import (identifier) @font-lock-variable-name-face)))
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'identifier
|
|
|
|
`((nested_type_identifier
|
|
|
|
module: (identifier) @font-lock-type-face)
|
|
|
|
|
|
|
|
(type_identifier) @font-lock-type-face
|
|
|
|
|
|
|
|
(predefined_type) @font-lock-type-face
|
|
|
|
|
|
|
|
(new_expression
|
|
|
|
constructor: (identifier) @font-lock-type-face)
|
|
|
|
|
2022-10-17 12:49:19 +02:00
|
|
|
(enum_body (property_identifier) @font-lock-type-face)
|
|
|
|
|
|
|
|
(enum_assignment name: (property_identifier) @font-lock-type-face)
|
|
|
|
|
2023-01-02 20:56:41 +01:00
|
|
|
(variable_declarator
|
|
|
|
name: (identifier) @font-lock-variable-name-face)
|
2022-10-17 12:49:19 +02:00
|
|
|
|
|
|
|
(for_in_statement
|
|
|
|
left: (identifier) @font-lock-variable-name-face)
|
|
|
|
|
|
|
|
(arrow_function
|
2022-10-28 21:23:19 +02:00
|
|
|
parameters:
|
|
|
|
[(_ (identifier) @font-lock-variable-name-face)
|
|
|
|
(_ (_ (identifier) @font-lock-variable-name-face))
|
2023-01-04 09:13:23 +01:00
|
|
|
(_ (_ (_ (identifier) @font-lock-variable-name-face)))]))
|
2022-12-07 09:27:42 +01:00
|
|
|
|
|
|
|
:language language
|
|
|
|
:feature 'property
|
|
|
|
`((property_signature
|
2023-02-25 03:15:46 +02:00
|
|
|
name: (property_identifier) @font-lock-property-name-face)
|
2022-12-07 09:27:42 +01:00
|
|
|
(public_field_definition
|
2023-02-25 03:15:46 +02:00
|
|
|
name: (property_identifier) @font-lock-property-name-face)
|
2022-12-07 09:27:42 +01:00
|
|
|
|
2023-02-25 03:15:46 +02:00
|
|
|
(pair key: (property_identifier) @font-lock-property-ref-face)
|
2022-12-07 09:27:42 +01:00
|
|
|
|
2023-02-25 03:15:46 +02:00
|
|
|
((shorthand_property_identifier) @font-lock-property-ref-face))
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'expression
|
|
|
|
'((assignment_expression
|
2022-10-11 10:27:55 +02:00
|
|
|
left: [(identifier) @font-lock-function-name-face
|
|
|
|
(member_expression
|
|
|
|
property: (property_identifier) @font-lock-function-name-face)]
|
2023-01-02 20:56:41 +01:00
|
|
|
right: [(function) (arrow_function)]))
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2023-01-02 20:56:41 +01:00
|
|
|
:language language
|
|
|
|
:feature 'function
|
|
|
|
'((call_expression
|
2022-10-11 10:27:55 +02:00
|
|
|
function:
|
2023-02-25 03:15:46 +02:00
|
|
|
[(identifier) @font-lock-function-call-face
|
2022-10-11 10:27:55 +02:00
|
|
|
(member_expression
|
2023-02-25 03:15:46 +02:00
|
|
|
property: (property_identifier) @font-lock-function-call-face)]))
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'pattern
|
|
|
|
`((pair_pattern
|
2023-02-25 03:54:31 +02:00
|
|
|
key: (property_identifier) @font-lock-property-ref-face
|
|
|
|
value: [(identifier) @font-lock-variable-name-face
|
|
|
|
(assignment_pattern left: (identifier) @font-lock-variable-name-face)])
|
2023-02-25 03:15:46 +02:00
|
|
|
|
|
|
|
(array_pattern (identifier) @font-lock-variable-name-face)
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2023-02-25 03:15:46 +02:00
|
|
|
((shorthand_property_identifier_pattern) @font-lock-variable-name-face))
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-28 21:23:19 +02:00
|
|
|
:feature 'jsx
|
|
|
|
`((jsx_opening_element
|
2022-10-11 10:27:55 +02:00
|
|
|
[(nested_identifier (identifier)) (identifier)]
|
2023-02-25 03:15:46 +02:00
|
|
|
@font-lock-function-call-face)
|
2022-10-11 10:27:55 +02:00
|
|
|
|
|
|
|
(jsx_closing_element
|
|
|
|
[(nested_identifier (identifier)) (identifier)]
|
2023-02-25 03:15:46 +02:00
|
|
|
@font-lock-function-call-face)
|
2022-10-11 10:27:55 +02:00
|
|
|
|
|
|
|
(jsx_self_closing_element
|
|
|
|
[(nested_identifier (identifier)) (identifier)]
|
2023-02-25 03:15:46 +02:00
|
|
|
@font-lock-function-call-face)
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2022-11-21 13:12:03 +01:00
|
|
|
(jsx_attribute (property_identifier) @font-lock-constant-face))
|
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces. Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.
2022-11-19 22:30:13 -05:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces. Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.
2022-11-19 22:30:13 -05:00
|
|
|
:feature 'number
|
|
|
|
`((number) @font-lock-number-face
|
|
|
|
((identifier) @font-lock-number-face
|
|
|
|
(:match "^\\(:?NaN\\|Infinity\\)$" @font-lock-number-face)))
|
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces. Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.
2022-11-19 22:30:13 -05:00
|
|
|
:feature 'operator
|
2022-11-25 21:04:18 +01:00
|
|
|
`([,@typescript-ts-mode--operators] @font-lock-operator-face
|
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces. Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.
2022-11-19 22:30:13 -05:00
|
|
|
(ternary_expression ["?" ":"] @font-lock-operator-face))
|
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-11-21 13:12:03 +01:00
|
|
|
:feature 'bracket
|
|
|
|
'((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
|
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-11-21 13:12:03 +01:00
|
|
|
:feature 'delimiter
|
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces. Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.
2022-11-19 22:30:13 -05:00
|
|
|
'((["," "." ";" ":"]) @font-lock-delimiter-face)
|
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces. Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.
2022-11-19 22:30:13 -05:00
|
|
|
:feature 'escape-sequence
|
|
|
|
:override t
|
2022-12-17 20:07:59 +01:00
|
|
|
'((escape_sequence) @font-lock-escape-face)))
|
2022-10-11 10:27:55 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2022-11-29 21:39:38 +01:00
|
|
|
(define-derived-mode typescript-ts-base-mode prog-mode "TypeScript"
|
|
|
|
"Major mode for editing TypeScript."
|
|
|
|
:group 'typescript
|
|
|
|
:syntax-table typescript-ts-mode--syntax-table
|
|
|
|
|
|
|
|
;; Comments.
|
2023-01-21 12:24:55 +01:00
|
|
|
(c-ts-common-comment-setup)
|
2022-11-29 21:39:38 +01:00
|
|
|
|
|
|
|
;; Electric
|
|
|
|
(setq-local electric-indent-chars
|
2023-02-18 23:10:13 +01:00
|
|
|
(append "{}():;,<>/" electric-indent-chars))
|
|
|
|
(setq-local electric-layout-rules
|
|
|
|
'((?\; . after) (?\{ . after) (?\} . before)))
|
2022-11-29 21:39:38 +01:00
|
|
|
;; Navigation.
|
|
|
|
(setq-local treesit-defun-type-regexp
|
|
|
|
(regexp-opt '("class_declaration"
|
|
|
|
"method_definition"
|
|
|
|
"function_declaration"
|
|
|
|
"lexical_declaration")))
|
2022-12-27 20:57:12 -08:00
|
|
|
(setq-local treesit-defun-name-function #'js--treesit-defun-name)
|
|
|
|
|
|
|
|
;; Imenu (same as in `js-ts-mode').
|
|
|
|
(setq-local treesit-simple-imenu-settings
|
|
|
|
`(("Function" "\\`function_declaration\\'" nil nil)
|
|
|
|
("Variable" "\\`lexical_declaration\\'"
|
|
|
|
js--treesit-valid-imenu-entry nil)
|
|
|
|
("Class" ,(rx bos (or "class_declaration"
|
|
|
|
"method_definition")
|
|
|
|
eos)
|
|
|
|
nil nil))))
|
2022-11-29 21:39:38 +01:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(define-derived-mode typescript-ts-mode typescript-ts-base-mode "TypeScript"
|
|
|
|
"Major mode for editing TypeScript."
|
|
|
|
:group 'typescript
|
|
|
|
:syntax-table typescript-ts-mode--syntax-table
|
|
|
|
|
|
|
|
(when (treesit-ready-p 'typescript)
|
|
|
|
(treesit-parser-create 'typescript)
|
|
|
|
|
|
|
|
;; Indent.
|
|
|
|
(setq-local treesit-simple-indent-rules
|
|
|
|
(typescript-ts-mode--indent-rules 'typescript))
|
|
|
|
|
|
|
|
;; Font-lock.
|
|
|
|
(setq-local treesit-font-lock-settings
|
|
|
|
(typescript-ts-mode--font-lock-settings 'typescript))
|
|
|
|
(setq-local treesit-font-lock-feature-list
|
2023-01-02 20:42:52 +02:00
|
|
|
'((comment declaration)
|
|
|
|
(keyword string escape-sequence)
|
2022-11-29 21:39:38 +01:00
|
|
|
(constant expression identifier number pattern property)
|
2023-01-02 20:56:41 +01:00
|
|
|
(function bracket delimiter)))
|
2022-11-29 21:39:38 +01:00
|
|
|
|
|
|
|
(treesit-major-mode-setup)))
|
|
|
|
|
2023-01-20 10:28:26 +02:00
|
|
|
(if (treesit-ready-p 'typescript)
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode)))
|
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
;;;###autoload
|
|
|
|
(define-derived-mode tsx-ts-mode typescript-ts-base-mode "TypeScript[TSX]"
|
2022-10-11 10:27:55 +02:00
|
|
|
"Major mode for editing TypeScript."
|
|
|
|
:group 'typescript
|
2022-11-25 21:04:18 +01:00
|
|
|
:syntax-table typescript-ts-mode--syntax-table
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2022-11-26 15:32:57 -08:00
|
|
|
(when (treesit-ready-p 'tsx)
|
2022-10-27 21:05:02 -07:00
|
|
|
(treesit-parser-create 'tsx)
|
2022-11-14 08:03:11 +01:00
|
|
|
|
2022-10-25 13:54:12 -07:00
|
|
|
;; Comments.
|
|
|
|
(setq-local comment-start "// ")
|
|
|
|
(setq-local comment-end "")
|
2022-12-02 17:03:21 -08:00
|
|
|
(setq-local comment-start-skip (rx (or (seq "/" (+ "/"))
|
|
|
|
(seq "/" (+ "*")))
|
|
|
|
(* (syntax whitespace))))
|
2022-11-27 14:15:57 -08:00
|
|
|
(setq-local comment-end-skip
|
|
|
|
(rx (* (syntax whitespace))
|
|
|
|
(group (or (syntax comment-end)
|
|
|
|
(seq (+ "*") "/")))))
|
2022-11-14 08:03:11 +01:00
|
|
|
|
2022-10-25 13:54:12 -07:00
|
|
|
;; Indent.
|
2022-11-29 21:39:38 +01:00
|
|
|
(setq-local treesit-simple-indent-rules
|
|
|
|
(typescript-ts-mode--indent-rules 'tsx))
|
2022-11-14 08:03:11 +01:00
|
|
|
|
2022-10-25 13:54:12 -07:00
|
|
|
;; Font-lock.
|
2022-11-29 21:39:38 +01:00
|
|
|
(setq-local treesit-font-lock-settings
|
|
|
|
(typescript-ts-mode--font-lock-settings 'tsx))
|
2022-10-28 21:23:19 +02:00
|
|
|
(setq-local treesit-font-lock-feature-list
|
2023-01-02 20:42:52 +02:00
|
|
|
'((comment declaration)
|
|
|
|
(keyword string escape-sequence)
|
2022-11-29 21:39:38 +01:00
|
|
|
(constant expression identifier jsx number pattern property)
|
2023-01-02 20:56:41 +01:00
|
|
|
(function bracket delimiter)))
|
2022-11-14 08:03:11 +01:00
|
|
|
|
2022-11-26 15:32:57 -08:00
|
|
|
(treesit-major-mode-setup)))
|
2022-11-14 08:03:11 +01:00
|
|
|
|
2023-01-20 10:28:26 +02:00
|
|
|
(if (treesit-ready-p 'tsx)
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode)))
|
|
|
|
|
2022-11-25 21:04:18 +01:00
|
|
|
(provide 'typescript-ts-mode)
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2022-11-25 21:04:18 +01:00
|
|
|
;;; typescript-ts-mode.el ends here
|