Enhance and fix inheritance for javascript and typescript support (#296)

* update javascript and typescript

* create an ecma directory and use existing javascript matchup.scm there
* inherit from ecma and jsx in the javascript query
* inherit from ecma in the typescript query
* inherit from typescript and jsx in the tsx query
* this structure makes it more inline with how existing queries in nvim-treesitter work
* allows jsx to be used in js files

* add additional matchup for typescript

* allow type argument and parameters to be matched up such that `function foo(): Promise<any>` matches up the `<` and `>` characters
This commit is contained in:
Vadim Kazakov
2023-06-29 18:22:54 -06:00
committed by GitHub
parent 3a17944bfa
commit a5ca7ef398
5 changed files with 46 additions and 39 deletions

View File

@@ -0,0 +1,35 @@
; inherits: quote
; functions
[
(arrow_function "=>" @open.function)
(function "function" @open.function)
(function_declaration "function" @open.function)
] @scope.function
(return_statement "return" @mid.function.1)
; switch case
(switch_statement "switch" @open.switch) @scope.switch
(switch_case "case" @mid.switch.1)
(switch_default "default" @mid.switch.2)
; 'else' and 'else if'
(else_clause
"else" @_start (if_statement "if" @_end)?
(#make-range! "mid.if.1" @_start @_end))
; if
((if_statement
"if" @open.if) @scope.if
(#not-has-parent? @scope.if else_clause))
; try
(try_statement "try" @open.try) @scope.try
(catch_clause "catch" @mid.try.1)
(finally_clause "finally" @mid.try.2)
; template strings
(template_string
"`" @open.tmpl_str
"`" @close.tmpl_str) @scope.tmpl_str

View File

@@ -1,35 +1 @@
; inherits: quote
; functions
[
(arrow_function "=>" @open.function)
(function "function" @open.function)
(function_declaration "function" @open.function)
] @scope.function
(return_statement "return" @mid.function.1)
; switch case
(switch_statement "switch" @open.switch) @scope.switch
(switch_case "case" @mid.switch.1)
(switch_default "default" @mid.switch.2)
; 'else' and 'else if'
(else_clause
"else" @_start (if_statement "if" @_end)?
(#make-range! "mid.if.1" @_start @_end))
; if
((if_statement
"if" @open.if) @scope.if
(#not-has-parent? @scope.if else_clause))
; try
(try_statement "try" @open.try) @scope.try
(catch_clause "catch" @mid.try.1)
(finally_clause "finally" @mid.try.2)
; template strings
(template_string
"`" @open.tmpl_str
"`" @close.tmpl_str) @scope.tmpl_str
; inherits: ecma,jsx

View File

@@ -1,5 +1,3 @@
; inherits: javascript
(jsx_element) @scope.tag
(jsx_opening_element (identifier) @open.tag)
(jsx_closing_element

View File

@@ -1 +1 @@
; inherits: jsx
; inherits: typescript,jsx

View File

@@ -1 +1,9 @@
; inherits: javascript
; inherits: ecma
(type_arguments) @scope.typeargs
(type_arguments) "<" @open.typeargs
(type_arguments) ">" @close.typeargs
(type_parameters) @scope.typeparams
(type_parameters) "<" @open.typeparams
(type_parameters) ">" @close.typeparams