-
Notifications
You must be signed in to change notification settings - Fork 898
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
Support EmitMode::ModifiedLines with stdin input #3424
Support EmitMode::ModifiedLines with stdin input #3424
Conversation
CI fails on clippy failure, which in turn is blocked on Manishearth/compiletest-rs#160 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. The implementation looks good, though the new test is failing on Windows, possibly due to \n
and \r\n
things. Would you mind fixing it?
src/rustfmt_diff.rs
Outdated
fn from(mismatches: Vec<Mismatch>) -> ModifiedLines { | ||
let chunks = mismatches.into_iter().map(|mismatch| { | ||
let lines = || mismatch.lines.iter(); | ||
let num_removed = lines() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you using a closure here? Is this for some kind of optimization? Just curious...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the closure here is redundant; I'd personally just do all of that as chained expressions but such a conceptually simple things blows to ~10 lines 😢 So I just tried to split this into two to appease Rustfmt; I'll try with the version without a closure.
This moves `Modified{Chunks,Lines}` from `src/formatting.rs` to `src/rustfmt_diff.rs` and reexports it in `src/lib.rs`. With this, a conversion from `Vec<Mismatch>` to `ModifiedLines` was implemented and now this implements complementary `Display` and `FromStr`, which simplified the previously used `output_modified` function and which allows to parse the raw data emitted with `EmitMode::ModifiedLines`.
42aa5a1
to
fbfda61
Compare
CI failed on ICE in futures-rs:
|
@Xanewok looks like there's a PR out already: rust-lang/rust#58888 |
LGTM, thanks for the update! |
Thank you! Do you think you could publish a point release with this or do you prefer to accumulate more changes for the release, first? |
Return only modified lines in formatting responses Ticks few boxes in #3. (that's an early issue!) Closes #334. This is currently based on rust-lang/rustfmt#3424 and so currently blocked until it merges. Configures Rustfmt to use `EmitMode::ModifiedLines` and parses the response - this should work with both statically-linked and externally provided Rustfmt. @alexheretic do you think you could take a look and double-check?
Main motivation is to handle the case where we have an input from stdin and we're mostly interested in a diff rather than whole file and trying to come up with this information ourselves. The
EmitMode::ModifiedLines
should still support writing to a specifiedWrite
sink - we mostly lacked the information on what was the input text so we ask that the passedsource_map
.Currently works with https://github.com/Xanewok/rls/tree/rustfmt-modified-lines branch on the RLS side.
related #1173 (although this still has to go through (de)serialization)