diff options
Diffstat (limited to 'runtime/queries/_typescript')
-rw-r--r-- | runtime/queries/_typescript/highlights.scm | 139 | ||||
-rw-r--r-- | runtime/queries/_typescript/indents.scm | 5 | ||||
-rw-r--r-- | runtime/queries/_typescript/locals.scm | 16 | ||||
-rw-r--r-- | runtime/queries/_typescript/tags.scm | 23 | ||||
-rw-r--r-- | runtime/queries/_typescript/textobjects.scm | 6 |
5 files changed, 189 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 diff --git a/runtime/queries/_typescript/indents.scm b/runtime/queries/_typescript/indents.scm new file mode 100644 index 00000000..90dbc85b --- /dev/null +++ b/runtime/queries/_typescript/indents.scm @@ -0,0 +1,5 @@ +[ + (enum_declaration) + (interface_declaration) + (object_type) +] @indent diff --git a/runtime/queries/_typescript/locals.scm b/runtime/queries/_typescript/locals.scm new file mode 100644 index 00000000..fe13f21d --- /dev/null +++ b/runtime/queries/_typescript/locals.scm @@ -0,0 +1,16 @@ +; Definitions +;------------ + +; 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. + +; (i: t) +; (i: t = 1) +(required_parameter + (identifier) @local.definition) + +; (i?: t) +; (i?: t = 1) // Invalid but still posible to hihglight. +(optional_parameter + (identifier) @local.definition) diff --git a/runtime/queries/_typescript/tags.scm b/runtime/queries/_typescript/tags.scm new file mode 100644 index 00000000..ccae934e --- /dev/null +++ b/runtime/queries/_typescript/tags.scm @@ -0,0 +1,23 @@ +(function_signature + name: (identifier) @name) @definition.function + +(method_signature + name: (property_identifier) @name) @definition.method + +(abstract_method_signature + name: (property_identifier) @name) @definition.method + +(abstract_class_declaration + name: (type_identifier) @name) @definition.class + +(module + name: (identifier) @name) @definition.module + +(interface_declaration + name: (type_identifier) @name) @definition.interface + +(type_annotation + (type_identifier) @name) @reference.type + +(new_expression + constructor: (identifier) @name) @reference.class diff --git a/runtime/queries/_typescript/textobjects.scm b/runtime/queries/_typescript/textobjects.scm new file mode 100644 index 00000000..c248aead --- /dev/null +++ b/runtime/queries/_typescript/textobjects.scm @@ -0,0 +1,6 @@ +[ + (interface_declaration + body:(_) @class.inside) + (type_alias_declaration + value: (_) @class.inside) +] @class.around |