mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Run rustfmt with respect to Cargo.toml edition
This commit is contained in:
parent
1fe0b8c03f
commit
b437dca4bd
4 changed files with 78 additions and 0 deletions
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue