aboutsummaryrefslogtreecommitdiff
path: root/runtime/queries/_typescript/highlights.scm
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/queries/_typescript/highlights.scm')
-rw-r--r--runtime/queries/_typescript/highlights.scm139
1 files changed, 139 insertions, 0 deletions
diff --git a/runtime/queries/_typescript/highlights.scm b/runtime/queries/_typescript/highlights.scm
new file mode 100644
index 00000000..02f3aab7
--- /dev/null
+++ b/runtime/queries/_typescript/highlights.scm
@@ -0,0 +1,139 @@
+; Namespaces
+; ----------
+
+(internal_module
+ [((identifier) @namespace) ((nested_identifier (identifier) @namespace))])
+
+(ambient_declaration "global" @namespace)
+
+; Parameters
+; ----------
+; Javascript and Typescript Treesitter grammars deviate when defining the
+; tree structure for parameters, so we need to address them in each specific
+; language instead of ecma.
+
+; (p: t)
+; (p: t = 1)
+(required_parameter
+ (identifier) @variable.parameter)
+
+; (...p: t)
+(required_parameter
+ (rest_pattern
+ (identifier) @variable.parameter))
+
+; ({ p }: { p: t })
+(required_parameter
+ (object_pattern
+ (shorthand_property_identifier_pattern) @variable.parameter))
+
+; ({ a: p }: { a: t })
+(required_parameter
+ (object_pattern
+ (pair_pattern
+ value: (identifier) @variable.parameter)))
+
+; ([ p ]: t[])
+(required_parameter
+ (array_pattern
+ (identifier) @variable.parameter))
+
+; (p?: t)
+; (p?: t = 1) // Invalid but still posible to hihglight.
+(optional_parameter
+ (identifier) @variable.parameter)
+
+; (...p?: t) // Invalid but still posible to hihglight.
+(optional_parameter
+ (rest_pattern
+ (identifier) @variable.parameter))
+
+; ({ p }: { p?: t})
+(optional_parameter
+ (object_pattern
+ (shorthand_property_identifier_pattern) @variable.parameter))
+
+; ({ a: p }: { a?: t })
+(optional_parameter
+ (object_pattern
+ (pair_pattern
+ value: (identifier) @variable.parameter)))
+
+; ([ p ]?: t[]) // Invalid but still posible to hihglight.
+(optional_parameter
+ (array_pattern
+ (identifier) @variable.parameter))
+
+; Punctuation
+; -----------
+
+[
+ ":"
+] @punctuation.delimiter
+
+(optional_parameter "?" @punctuation.special)
+(property_signature "?" @punctuation.special)
+
+(conditional_type ["?" ":"] @operator)
+
+; Keywords
+; --------
+
+[
+ "abstract"
+ "declare"
+ "export"
+ "infer"
+ "implements"
+ "keyof"
+ "namespace"
+ "override"
+] @keyword
+
+[
+ "type"
+ "interface"
+ "enum"
+] @keyword.storage.type
+
+[
+ "public"
+ "private"
+ "protected"
+ "readonly"
+] @keyword.storage.modifier
+
+; Types
+; -----
+
+(type_identifier) @type
+(predefined_type) @type.builtin
+
+; Type arguments and parameters
+; -----------------------------
+
+(type_arguments
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)
+
+(type_parameters
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)
+
+; Literals
+; --------
+
+[
+ (template_literal_type)
+] @string
+
+; Tokens
+; ------
+
+(template_type
+ "${" @punctuation.special
+ "}" @punctuation.special) @embedded