Support EmitMode::ModifiedLines with stdin input#3424
Support EmitMode::ModifiedLines with stdin input#3424topecongiro merged 5 commits intorust-lang:masterfrom
Conversation
|
CI fails on clippy failure, which in turn is blocked on Manishearth/compiletest-rs#160 |
topecongiro
left a comment
There was a problem hiding this comment.
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.
Why are you using a closure here? Is this for some kind of optimization? Just curious...
There was a problem hiding this comment.
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::ModifiedLinesshould still support writing to a specifiedWritesink - 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)