mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Improve C, Rust & Python indent queries & add @align captures.
This commit is contained in:
parent
eab0d4fa4b
commit
36a59e4482
@ -5,7 +5,6 @@
|
||||
(enumerator_list)
|
||||
(parameter_list)
|
||||
(init_declarator)
|
||||
(case_statement)
|
||||
(expression_statement)
|
||||
] @indent
|
||||
|
||||
@ -13,6 +12,7 @@
|
||||
"case"
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
||||
|
||||
(if_statement
|
||||
@ -32,3 +32,7 @@
|
||||
(_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
|
||||
(parameter_list
|
||||
. (parameter_declaration) @anchor
|
||||
(#set! "scope" "tail")) @align
|
||||
|
@ -73,3 +73,12 @@
|
||||
(else_clause
|
||||
"else" @outdent)
|
||||
|
||||
(parameters
|
||||
.
|
||||
(identifier) @anchor
|
||||
(#set! "scope" "tail")) @align
|
||||
(argument_list
|
||||
.
|
||||
(_) @anchor
|
||||
(#set! "scope" "tail")) @align
|
||||
|
||||
|
@ -14,9 +14,11 @@
|
||||
(call_expression)
|
||||
(binary_expression)
|
||||
(field_expression)
|
||||
(await_expression)
|
||||
(tuple_expression)
|
||||
(array_expression)
|
||||
(where_clause)
|
||||
(type_cast_expression)
|
||||
|
||||
(token_tree)
|
||||
(macro_definition)
|
||||
@ -48,10 +50,16 @@
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
(let_declaration
|
||||
"let" @expr-start
|
||||
value: (_) @indent
|
||||
alternative: (_)? @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
(let_condition
|
||||
.
|
||||
(_) @expr-start
|
||||
value: (_) @indent
|
||||
alternative: (_)? @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
@ -69,6 +77,22 @@
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
(field_pattern
|
||||
.
|
||||
(_) @expr-start
|
||||
pattern: (_) @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
; Indent type aliases that span multiple lines, similar to
|
||||
; regular assignment expressions
|
||||
(type_item
|
||||
.
|
||||
(_) @expr-start
|
||||
type: (_) @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
|
||||
; Some field expressions where the left part is a multiline expression are not
|
||||
; indented by cargo fmt.
|
||||
@ -77,5 +101,48 @@
|
||||
(field_expression
|
||||
value: (_) @val
|
||||
"." @outdent
|
||||
(#match? @val "(\\A[^\\n\\r]+\\([\\t ]*(\\n|\\r).*)|(\\A[^\\n\\r]*\\{[\\t ]*(\\n|\\r))")
|
||||
; Check whether the first line ends with `(`, `{` or `[` (up to whitespace).
|
||||
(#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
|
||||
)
|
||||
; Same as above, but with an additional `call_expression`. This is required since otherwise
|
||||
; the arguments of the function call won't be outdented.
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
value: (_) @val
|
||||
"." @outdent
|
||||
(#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
|
||||
)
|
||||
arguments: (_) @outdent
|
||||
)
|
||||
|
||||
|
||||
; Indent if guards in patterns.
|
||||
; Since the tree-sitter grammar doesn't create a node for the if expression,
|
||||
; it's not possible to do this correctly in all cases. Indenting the tail of the
|
||||
; whole pattern whenever it contains an `if` only fails if the `if` appears after
|
||||
; the second line of the pattern (which should only rarely be the case)
|
||||
(match_pattern
|
||||
.
|
||||
(_) @expr-start
|
||||
"if" @pattern-guard
|
||||
(#not-same-line? @expr-start @pattern-guard)
|
||||
) @indent
|
||||
|
||||
; Align closure parameters if they span more than one line
|
||||
(closure_parameters
|
||||
"|"
|
||||
.
|
||||
(_) @anchor
|
||||
(_) @expr-end
|
||||
.
|
||||
(#not-same-line? @anchor @expr-end)
|
||||
) @align
|
||||
|
||||
(for_expression
|
||||
"in" @in
|
||||
.
|
||||
(_) @indent
|
||||
(#not-same-line? @in @indent)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user