diff --git a/CHANGELOG.md b/CHANGELOG.md index 96d29ba6..8f54a83a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,8 +51,8 @@ This name should be decided amongst the team before the release. - [#760](https://github.com/tweag/topiary/pull/760) Introduce optional `query_name` predicate, to help with query logging and debugging. ### Fixed -- [#720](https://github.com/tweag/topiary/pull/720) [#722](https://github.com/tweag/topiary/pull/722) [#723](https://github.com/tweag/topiary/pull/723) [#724](https://github.com/tweag/topiary/pull/724) [#735](https://github.com/tweag/topiary/pull/735) -[#738](https://github.com/tweag/topiary/pull/738) [#739](https://github.com/tweag/topiary/pull/739) [#745](https://github.com/tweag/topiary/pull/745) [#755](https://github.com/tweag/topiary/pull/755) [#759](https://github.com/tweag/topiary/pull/759) Various OCaml improvements +- [#720](https://github.com/tweag/topiary/pull/720) [#722](https://github.com/tweag/topiary/pull/722) [#723](https://github.com/tweag/topiary/pull/723) [#724](https://github.com/tweag/topiary/pull/724) [#735](https://github.com/tweag/topiary/pull/735) [#738](https://github.com/tweag/topiary/pull/738) [#739](https://github.com/tweag/topiary/pull/739) [#745](https://github.com/tweag/topiary/pull/745) [#755](https://github.com/tweag/topiary/pull/755) [#759](https://github.com/tweag/topiary/pull/759) Various OCaml improvements +- [#762](https://github.com/tweag/topiary/pull/762) Various Rust improvements - [#744](https://github.com/tweag/topiary/pull/744) Nickel: fix the indentation of `in` for annotated multiline let-bindings - [#761](https://github.com/tweag/topiary/pull/761) No longer use error code 1 for unspecified errors diff --git a/topiary-cli/tests/samples/expected/rust.rs b/topiary-cli/tests/samples/expected/rust.rs index 90bb719c..3f449888 100644 --- a/topiary-cli/tests/samples/expected/rust.rs +++ b/topiary-cli/tests/samples/expected/rust.rs @@ -86,3 +86,26 @@ enum Mode6 { mode unchanged */ Either, } + +// Inline with let stmt +fn inline_let() { let hi = 1; } + +// While loop spacing +while i == true { + let i = 42; +} + +// Scoped blocks +{ + let i = 42; +} +{ + let i = 43; +} + +// Empty block inside of impl function +impl MyTrait for MyStruct { + fn foo() { + // ... logic ... + } +} diff --git a/topiary-cli/tests/samples/input/rust.rs b/topiary-cli/tests/samples/input/rust.rs index b62ab6ca..3ef36584 100644 --- a/topiary-cli/tests/samples/input/rust.rs +++ b/topiary-cli/tests/samples/input/rust.rs @@ -86,3 +86,27 @@ enum Mode6 { mode unchanged */ Either, } + +// Inline with let stmt +fn inline_let() { let hi = 1; } + +// While loop spacing +while i == true { + let i = 42; +} + + +// Scoped blocks +{ + let i = 42; +} +{ + let i = 43; +} + +// Empty block inside of impl function +impl MyTrait for MyStruct { + fn foo() { + // ... logic ... + } +} diff --git a/topiary-queries/queries/rust.scm b/topiary-queries/queries/rust.scm index 8ce0eb27..5d205ec8 100644 --- a/topiary-queries/queries/rust.scm +++ b/topiary-queries/queries/rust.scm @@ -1,7 +1,11 @@ ; Sometimes we want to indicate that certain parts of our source text should ; not be formatted, but taken as is. We use the leaf capture name to inform the ; tool of this. -(string_literal) @leaf +[ + (block_comment) + (line_comment) + (string_literal) +] @leaf ; Allow blank line before [ @@ -37,6 +41,7 @@ "type" "unsafe" (visibility_modifier) + "while" "=" "==" "-" @@ -73,6 +78,7 @@ (attribute_item) (enum_item) (extern_crate_declaration) + (expression_statement) (function_item) (impl_item) (let_declaration) @@ -80,7 +86,7 @@ (struct_item) (type_item) (use_declaration) - ] @append_hardline + ] @append_spaced_softline . [ (block_comment) @@ -92,6 +98,13 @@ (block_comment) @multi_line_indent_all +; Allow line break after block comments +( + (block_comment) + . + _ @prepend_input_softline +) + ; Append softlines, unless followed by comments. ( [ @@ -161,7 +174,6 @@ (block . "{" @append_spaced_softline @append_indent_start - _ "}" @prepend_spaced_softline @prepend_indent_end . ) @@ -176,8 +188,20 @@ "{" @prepend_space ) +(declaration_list + . + "{" @append_empty_softline @append_indent_start + "}" @prepend_empty_softline @prepend_indent_end + . +) + ; PhantomData<&'a ()> (_ (lifetime) @append_space [(array_type) (generic_type) (primitive_type) (unit_type)] ) + +; Never put a space before a comma +( + "," @prepend_antispace +)