rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.19k stars 1.59k forks source link

Meta feature tracking: Language server support for `Cargo.toml` file #15741

Open tgross35 opened 1 year ago

tgross35 commented 1 year ago

This issue is an attempt to put all information regarding potential Cargo.toml support in one place.

Blockers

There is no TOML support in RA, and needs a format-preserving parser. toml-edit is maintained along with toml and probably the best choice.

Potential features

See also the label https://github.com/rust-lang/rust-analyzer/labels/S-needs-toml

obsgolem commented 1 year ago

My issue https://github.com/rust-lang/rust-analyzer/issues/10117 needs the needs-toml label.

tgross35 commented 1 year ago

My issue #10117 needs the needs-toml label.

Thanks for the link, I added it to the list

alibektas commented 11 months ago

I want to point out that I am indirectly working on this issue. I am trying to implement a .rust-analyzer.toml (#13529) file support. I hope to end up with an integrated TOML parser in ra although it is not my primary concern ( RATOML's first prototype won't be needing a TOML parser, ser-de should be enough for now). I would be happy if contributors to this issue could reach out to me so that we can talk about its implementation.

At the very least I will be making some changes to the core DBs of ra to distinguish .rs files from .tomls ( strictly speaking, from .rust-analyzer.toml files and cargo.toml files, each of which needing special care here and there).

tgross35 commented 11 months ago

@alibektas that sounds very cool!

I think that toml-edit is more or less a drop in for toml and works with the same structs with Serde. The difference is that the untyped representation (toml_edit::Document, a strict superset of toml::Value) has support for format preservation. Maybe it makes sense to prototype with toml-edit instead of the usual toml just so its use can be expanded in the future?

Not that I expect RA would be editing .rust-analyzer.toml ever, but it could make sense for any framework that will eventually be shared with Cargo.toml

alibektas commented 11 months ago

:wave:

There are couple of things that I first need to look into before giving you an answer.

1) Will RA maintainers be OK with toml-edit being included in RA? The impression that I got thus far is that we are very conservative when it comes to using external crates. ( This I will be asking Veykril next week )

2) How well will toml-edit be compatible with RA's incremental computation principles? ( This is a concern that goes beyond the prototyping phase. )

For the prototype your proposition seems to be the way to go, but this is just me speaking without having really looked at toml-edit in depth. I will get back to you with a more detailed answer possibly next week, but let me at least say that I agree toml-edit being better in this regard than toml.

Veykril commented 11 months ago

Fwiw, we most likely want to end up with a toml parser thats built on top of rowan, which kind of exist https://docs.rs/taplo/latest/taplo/ so we probably want to strip that down / adjust to our needs.

alibektas commented 11 months ago

@tgross35 :wave: I think Veykril's reply answers the greater part of your question, but I think it comes down to determining how long it will take us to integrate the said taplo crate to RA.

wyatt-herkamp commented 10 months ago

This is a feature I would really like to see. I was debating building a separate plugin to some of the features listed.

 Is this a feature that RA will accept into its code base? 

if So I would be interesting in starting to add it to RA?

Veykril commented 10 months ago

Definitely something we want to have, its just a lot of work and requires some other things to be done first, like creating / integrating a rowan based syntax library for toml -> https://github.com/rust-lang/rust-analyzer/pull/15908