aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseb-bl2022-08-24 02:35:57 +0000
committerGitHub2022-08-24 02:35:57 +0000
commitccae718a67f39542281125610764b733d90b26f8 (patch)
tree143d2512c28c93aaf327d01eec21aad18dfb6058
parent6b912b864195e0781b186e50b91050ed5c9b0e3d (diff)
Improve dart indent (#3419)
-rw-r--r--languages.toml2
-rw-r--r--runtime/queries/dart/indents.scm98
2 files changed, 90 insertions, 10 deletions
diff --git a/languages.toml b/languages.toml
index 2b56e332..cf834d35 100644
--- a/languages.toml
+++ b/languages.toml
@@ -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"
diff --git a/runtime/queries/dart/indents.scm b/runtime/queries/dart/indents.scm
index 14c6a375..cdb96ae8 100644
--- a/runtime/queries/dart/indents.scm
+++ b/runtime/queries/dart/indents.scm
@@ -1,16 +1,95 @@
+; things surrounded by ({[]})
[
- (class_body)
- (function_body)
- (function_expression_body)
- (declaration)
- (initializers)
+ (template_substitution)
+ (list_literal)
+ (set_or_map_literal)
+ (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)
+ (parameter_type_list)
+ (optional_positional_parameter_types)
+ (named_parameter_types)
(formal_parameter_list)
- (formal_parameter)
- (list_literal)
+ (optional_formal_parameters)
+] @indent
+
+; 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
[
@@ -18,3 +97,4 @@
"]"
")"
] @outdent
+