Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dart indent #3419

Merged
merged 2 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve dart indent
  • Loading branch information
seb-bl committed Aug 13, 2022
commit 4b5f2d8510af96d7058814dc291a41ff726eafef
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "dart"
source = { git = "https://github.com/UserNobody14/tree-sitter-dart", rev = "6a25376685d1d47968c2cef06d4db8d84a70025e" }
source = { git = "https://github.com/UserNobody14/tree-sitter-dart", rev = "2d7f66651c9319c1a0e4dda226cc2628fbb66528" }

[[language]]
name = "scala"
Expand Down
103 changes: 94 additions & 9 deletions runtime/queries/dart/indents.scm
Original file line number Diff line number Diff line change
@@ -1,20 +1,105 @@
; things surrounded by ({[]})
[
(class_body)
(function_body)
(function_expression_body)
(declaration)
(initializers)
(template_substitution)
(list_literal)
(set_or_map_literal)
; (inferred_parameters) ; this one is not actually used
(parenthesized_expression)
(arguments)
(index_selector)
(block)
(assertion_arguments)
(switch_block)
(if_statement)
(catch_parameters)
(for_loop_parts)
(configuration_uri_condition)
(enum_body)
(class_body)
(extension_body)
; (constructor_body) ; this one is not actually used
(parameter_type_list)
(optional_positional_parameter_types)
(named_parameter_types)
(formal_parameter_list)
(formal_parameter)
(list_literal)
; (positional_parameters) ; this one is not actually used
(optional_formal_parameters)
] @indent

; dimensions is not actuallly used

; control flow statement which accept one line as body

(for_statement
body: _ @indent
(#not-kind-eq? @indent block)
(#set! "scope" "all")
)

(while_statement
body: _ @indent
(#not-kind-eq? @indent block)
(#set! "scope" "all")
)

(do_statement
body: _ @indent
(#not-kind-eq? @indent block)
(#set! "scope" "all")
)

(if_statement
consequence: _ @indent
(#not-kind-eq? @indent block)
(#set! "scope" "all")
)
(if_statement
alternative: _ @indent
(#not-kind-eq? @indent if_statement)
(#not-kind-eq? @indent block)
(#set! "scope" "all")
)
(if_statement
"else" @else
alternative: (if_statement) @indent
(#not-same-line? @indent @else)
(#set! "scope" "all")
)

(if_element
consequence: _ @indent
(#set! "scope" "all")
)
(if_element
alternative: _ @indent
(#not-kind-eq? @indent if_element)
(#set! "scope" "all")
)
(if_element
"else" @else
alternative: (if_element) @indent
(#not-same-line? @indent @else)
(#set! "scope" "all")
)

(for_element
body: _ @indent
(#set! "scope" "all")
)

; simple statements
[
(local_variable_declaration)
(break_statement)
(continue_statement)
(return_statement)
(arguments)
(yield_statement)
(yield_each_statement)
(expression_statement)
] @indent

[
"}"
"]"
")"
] @outdent