tweag / topiary

https://topiary.tweag.io/
MIT License
575 stars 29 forks source link

Add (and support) a code sample with real world Rust code #35

Open torhovland opened 2 years ago

torhovland commented 2 years ago

Most things should be formatted and indented OK, but we don't have to support every little detail yet.

sdankel commented 1 year ago

I found a few cases where the rust formatter needs improvement:

// 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 ...
    }
}

image

sdankel commented 1 year ago

I'm curious if topiary can remove brackets around a singular import, like rustfmt does. Example:

use std::{
    fmt,
    hash::{Hash},
};

formats to:

use std::{
    fmt,
    hash::Hash,
};

I saw the @delete instruction, but I'm not sure how to make it conditional based on the number of elements inside of the {}. An example for rust would be helpful!

ErinvanderVeen commented 1 year ago

We have capture groups that enable the disabling of a query when it matches. You can use that to check if there are at least two elements in the import list. So, you always @delete but then when you encounter the second (or more) imports you @do_nothing.

ErinvanderVeen commented 1 year ago

Then, a general comment on Rust support.

We (the topiary team) have collectively decided that competing with rustfmt is absolutely insane, and we should probably not try to do so until Topiary is much more mature.

This means we will likely not spend many resources on improving the Rust queries. Having said that, I will create a new issue with your report, and any member of the team is free to tackle the issue when they want. We are also more than happy to answer any questions a future contributor might have. The best place for that is probably our matrix channel: https://matrix.to/#/#topiary:matrix.org