mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-17 17:38:01 +00:00
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:
35
after/queries/ecma/matchup.scm
Normal file
35
after/queries/ecma/matchup.scm
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
; inherits: javascript
|
||||
|
||||
(jsx_element) @scope.tag
|
||||
(jsx_opening_element (identifier) @open.tag)
|
||||
(jsx_closing_element
|
||||
|
||||
@@ -1 +1 @@
|
||||
; inherits: jsx
|
||||
; inherits: typescript,jsx
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user