Run rustfmt with respect to Cargo.toml edition

This commit is contained in:
Vincent Rouillé 2019-12-04 23:05:01 +01:00
parent 1fe0b8c03f
commit b437dca4bd
No known key found for this signature in database
GPG key ID: FCA513373403B851
4 changed files with 78 additions and 0 deletions

View file

@ -555,12 +555,18 @@ pub fn handle_formatting(
let _p = profile("handle_formatting");
let file_id = params.text_document.try_conv_with(&world)?;
let file = world.analysis().file_text(file_id)?;
let crate_ids = world.analysis().crate_for(file_id)?;
let file_line_index = world.analysis().file_line_index(file_id)?;
let end_position = TextUnit::of_str(&file).conv_with(&file_line_index);
use std::process;
let mut rustfmt = process::Command::new("rustfmt");
if let Some(&crate_id) = crate_ids.first() {
// Assume all crates are in the same edition
let edition = world.analysis().crate_edition(crate_id)?;
rustfmt.args(&["--edition", &edition.to_string()]);
}
rustfmt.stdin(process::Stdio::piped()).stdout(process::Stdio::piped());
if let Ok(path) = params.text_document.uri.to_file_path() {