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

Library generator removes all comments on Cargo.toml #35

Open
abbudao opened this issue Dec 5, 2023 · 7 comments
Open

Library generator removes all comments on Cargo.toml #35

abbudao opened this issue Dec 5, 2023 · 7 comments

Comments

@abbudao
Copy link

abbudao commented Dec 5, 2023

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 LongTengDao/j-toml#19 ?

@Cammisuli
Copy link
Owner

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
Copy link

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
Copy link
Author

abbudao commented Dec 10, 2023

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
Copy link
Collaborator

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

@JamesHenry
Copy link
Collaborator

JamesHenry commented Feb 21, 2024

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
Copy link
Contributor

The quote changes are really deal breaker.

@kaankoken
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants