Cammisuli / monodon

34 stars 17 forks source link

Library generator removes all comments on Cargo.toml #35

Open abbudao opened 9 months ago

abbudao commented 9 months ago

Hey @Cammisuli, how is it going? I just found out that the generator for new libraries is removing all comments on Cargo.toml. This is a bit bothersome because I find it very useful when running a monorepo to explain some dependencies and group them, for instance:

[workspace.dependencies]
# log/tracing
tracing = "0.1"
tracing-subscriber = "0.3"

# datetime
chrono = { version = "0.4", features = ["serde"] }

# database
sqlx = { version = "0.7", features = [ "runtime-tokio", "postgres", "macros", "chrono" ] }

# testing
approx = "0.5"
ntest = "0.9"
axum-test= "13.1.1"

This has been extremely helpful for new Rust developers who still need to learn the ecosystem.

To reproduce, paste the above dependencies on root Cargo.toml with comments and run a generator: yarn nx g @monodon/rust:lib my-lib

I need to dig more, but it's probably related to https://github.com/LongTengDao/j-toml/issues/19 ?

Cammisuli commented 9 months ago

yea, its definitely related to the toml parsing library I'm using. I'm open to changing it if there's a better one that you know of.

LongTengDao commented 9 months ago

To remain all possible comments is really a hard work, and finally I'm coding a full support DOM-like thing to support unlimited use case, which already cost me weeks, a bit crazy fight.

Just wonder, maybe I got complicated thinking, is there any serialize tool in the world can remain full comment, for example in rust environment, even for other format like yaml or json5? Maybe I can be inspired, thank you!

abbudao commented 9 months ago

I am not an expert in this field but preserving comments in Rust tooling is not uncommon. One example is cargo-edit which uses toml_edit under the hood to achieve that. AFAIK only order on dotted keys is not preserved. Sorry, but I'm not familiar with the internals to give you some insights firsthand.

JamesHenry commented 6 months ago

@LongTengDao Thanks a lot, will you also allow for configuring the quotes used when stringifying? That would help reduce diffs

JamesHenry commented 6 months ago

For example right now when implementing a versioning tool for this library I get a large diff because of the comment lost (as already discussed) and also the quotes being different post-serialization:

image

(The only genuine diff here should be the two version fields)

kaankoken commented 1 week ago

The quote changes are really deal breaker.

kaankoken commented 1 week ago

I have created a #59 PR. It should solve the problem