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
|
|
|
|
|
|
|
;; Copyright (C) 2022 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
;; 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))
|
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
|
2022-10-27 21:05:02 -07:00
|
|
|
((parent-is "program") parent-bol 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)
|
2022-11-19 17:59:14 -08:00
|
|
|
((and (parent-is "comment") comment-end) comment-start -1)
|
|
|
|
((parent-is "comment") comment-start-skip 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)
|
|
|
|
((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)
|
|
|
|
((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-10-11 10:27:55 +02:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
,@(when (eq language 'tsx)
|
|
|
|
`(((parent-is "jsx_opening_element") parent typescript-ts-mode-indent-offset)
|
|
|
|
((node-is "jsx_closing_element") parent 0)
|
|
|
|
((parent-is "jsx_element") parent typescript-ts-mode-indent-offset)
|
|
|
|
((node-is "/") parent 0)
|
|
|
|
((parent-is "jsx_self_closing_element") parent typescript-ts-mode-indent-offset)))
|
|
|
|
(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-11 10:27:55 +02:00
|
|
|
:override t
|
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
|
|
|
:override t
|
|
|
|
: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
|
|
|
:override t
|
|
|
|
: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
|
|
|
:override t
|
|
|
|
:feature 'string
|
|
|
|
`((regex pattern: (regex_pattern)) @font-lock-string-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
|
2022-10-28 21:23:19 +02:00
|
|
|
(template_substitution ["${" "}"] @font-lock-builtin-face))
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-17 12:49:19 +02:00
|
|
|
:override t
|
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)
|
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
|
|
|
|
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: (identifier) @font-lock-function-name-face
|
|
|
|
value: [(function) (arrow_function)])
|
|
|
|
|
|
|
|
(variable_declarator
|
|
|
|
name: (array_pattern
|
|
|
|
(identifier)
|
|
|
|
(identifier) @font-lock-function-name-face)
|
|
|
|
value: (array (number) (function))))
|
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
|
|
|
:override t
|
|
|
|
: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)
|
|
|
|
|
|
|
|
(assignment_expression
|
|
|
|
left: [(identifier) @font-lock-variable-name-face
|
|
|
|
(member_expression
|
|
|
|
property: (property_identifier) @font-lock-variable-name-face)])
|
|
|
|
|
|
|
|
(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))
|
2022-12-05 09:31:58 +01:00
|
|
|
(_ (_ (_ (identifier) @font-lock-variable-name-face)))])
|
|
|
|
|
|
|
|
(return_statement (identifier) @font-lock-variable-name-face)
|
|
|
|
|
|
|
|
(binary_expression left: (identifier) @font-lock-variable-name-face)
|
|
|
|
(binary_expression right: (identifier) @font-lock-variable-name-face)
|
|
|
|
|
2022-12-07 09:27:42 +01:00
|
|
|
(arguments (identifier) @font-lock-variable-name-face)
|
|
|
|
|
|
|
|
(parenthesized_expression (identifier) @font-lock-variable-name-face)
|
|
|
|
(parenthesized_expression (_ (identifier)) @font-lock-variable-name-face))
|
|
|
|
|
|
|
|
:language language
|
|
|
|
:override t
|
|
|
|
:feature 'property
|
|
|
|
`((property_signature
|
|
|
|
name: (property_identifier) @font-lock-property-face)
|
|
|
|
(public_field_definition
|
|
|
|
name: (property_identifier) @font-lock-property-face)
|
|
|
|
(member_expression
|
|
|
|
object: (identifier) @font-lock-variable-name-face)
|
|
|
|
(member_expression
|
|
|
|
property: (_) @font-lock-property-face)
|
|
|
|
|
|
|
|
(pair key: (property_identifier) @font-lock-variable-name-face)
|
|
|
|
|
|
|
|
(pair value: (identifier) @font-lock-variable-name-face)
|
|
|
|
|
|
|
|
((shorthand_property_identifier) @font-lock-property-face)
|
|
|
|
|
|
|
|
((shorthand_property_identifier_pattern)
|
|
|
|
@font-lock-property-face))
|
2022-11-03 11:53:49 -07:00
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
:language language
|
2022-10-17 12:49:19 +02:00
|
|
|
:override t
|
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)]
|
|
|
|
right: [(function) (arrow_function)])
|
|
|
|
|
|
|
|
(call_expression
|
|
|
|
function:
|
|
|
|
[(identifier) @font-lock-function-name-face
|
|
|
|
(member_expression
|
2022-10-28 21:23:19 +02:00
|
|
|
property: (property_identifier) @font-lock-function-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
|
|
|
:override t
|
|
|
|
:feature 'pattern
|
|
|
|
`((pair_pattern
|
2022-11-21 13:12:03 +01:00
|
|
|
key: (property_identifier) @font-lock-property-face)
|
2022-10-11 10:27:55 +02:00
|
|
|
|
2022-10-28 21:23:19 +02:00
|
|
|
(array_pattern (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
|
|
|
:override t
|
|
|
|
:feature 'jsx
|
|
|
|
`((jsx_opening_element
|
2022-10-11 10:27:55 +02:00
|
|
|
[(nested_identifier (identifier)) (identifier)]
|
|
|
|
@font-lock-function-name-face)
|
|
|
|
|
|
|
|
(jsx_closing_element
|
|
|
|
[(nested_identifier (identifier)) (identifier)]
|
|
|
|
@font-lock-function-name-face)
|
|
|
|
|
|
|
|
(jsx_self_closing_element
|
|
|
|
[(nested_identifier (identifier)) (identifier)]
|
|
|
|
@font-lock-function-name-face)
|
|
|
|
|
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
|
|
|
|
'((escape_sequence) @font-lock-escape-face)
|
|
|
|
|
2022-12-05 09:31:58 +01:00
|
|
|
|
2022-12-07 09:27:42 +01:00
|
|
|
))
|
2022-10-11 10:27:55 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2022-11-25 21:04:18 +01:00
|
|
|
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode))
|
2022-10-11 10:27:55 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2022-11-29 21:39:38 +01:00
|
|
|
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode))
|
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.
|
|
|
|
(setq-local comment-start "// ")
|
|
|
|
(setq-local comment-end "")
|
|
|
|
(setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
|
|
|
|
(setq-local comment-end-skip
|
|
|
|
(rx (* (syntax whitespace))
|
|
|
|
(group (or (syntax comment-end)
|
|
|
|
(seq (+ "*") "/")))))
|
|
|
|
|
2022-12-09 22:36:03 +01:00
|
|
|
(setq-local treesit-defun-prefer-top-level t)
|
|
|
|
|
2022-11-29 21:39:38 +01:00
|
|
|
;; Electric
|
|
|
|
(setq-local electric-indent-chars
|
|
|
|
(append "{}():;," electric-indent-chars))
|
|
|
|
|
|
|
|
;; Navigation.
|
|
|
|
(setq-local treesit-defun-type-regexp
|
|
|
|
(regexp-opt '("class_declaration"
|
|
|
|
"method_definition"
|
|
|
|
"function_declaration"
|
|
|
|
"lexical_declaration")))
|
|
|
|
;; Imenu.
|
|
|
|
(setq-local imenu-create-index-function #'js--treesit-imenu)
|
|
|
|
|
|
|
|
;; Which-func (use imenu).
|
|
|
|
(setq-local which-func-functions nil))
|
|
|
|
|
|
|
|
;;;###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
|
2022-12-08 16:17:49 +01:00
|
|
|
'((comment declaration keyword string escape-sequence)
|
2022-11-29 21:39:38 +01:00
|
|
|
(constant expression identifier number pattern property)
|
|
|
|
(bracket delimiter)))
|
|
|
|
|
|
|
|
(treesit-major-mode-setup)))
|
|
|
|
|
|
|
|
;;;###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
|
2022-12-08 16:17:49 +01:00
|
|
|
'((comment declaration keyword string escape-sequence)
|
2022-11-29 21:39:38 +01:00
|
|
|
(constant expression identifier jsx number pattern property)
|
|
|
|
(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
|
|
|
|
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
|