diff options
author | Aleksey Kladov <[email protected]> | 2020-04-01 12:31:12 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-01 13:26:08 +0100 |
commit | 6ac966899853f03ab572ccd2cee8bf5b2a66aaea (patch) | |
tree | 552a089fafbb7e6de0f9e0f325329e537f36ea98 /crates/rust-analyzer/src/main_loop/handlers.rs | |
parent | 67351a011bbaf63617c7fc96884129e9fc39e411 (diff) |
Generalize rustfmt config
Diffstat (limited to 'crates/rust-analyzer/src/main_loop/handlers.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index d5cb5d137..80d96f89e 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -39,7 +39,7 @@ use crate::{ | |||
39 | from_json, | 39 | from_json, |
40 | req::{self, Decoration, InlayHint, InlayHintsParams}, | 40 | req::{self, Decoration, InlayHint, InlayHintsParams}, |
41 | semantic_tokens::SemanticTokensBuilder, | 41 | semantic_tokens::SemanticTokensBuilder, |
42 | world::WorldSnapshot, | 42 | world::{RustfmtConfig, WorldSnapshot}, |
43 | LspError, Result, | 43 | LspError, Result, |
44 | }; | 44 | }; |
45 | 45 | ||
@@ -610,13 +610,24 @@ pub fn handle_formatting( | |||
610 | let file_line_index = world.analysis().file_line_index(file_id)?; | 610 | let file_line_index = world.analysis().file_line_index(file_id)?; |
611 | let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); | 611 | let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); |
612 | 612 | ||
613 | let mut rustfmt = process::Command::new("rustfmt"); | 613 | let mut rustfmt = match &world.config.rustfmt { |
614 | rustfmt.args(&world.config.rustfmt_args); | 614 | RustfmtConfig::Rustfmt { extra_args } => { |
615 | if let Some(&crate_id) = crate_ids.first() { | 615 | let mut cmd = process::Command::new("rustfmt"); |
616 | // Assume all crates are in the same edition | 616 | cmd.args(extra_args); |
617 | let edition = world.analysis().crate_edition(crate_id)?; | 617 | if let Some(&crate_id) = crate_ids.first() { |
618 | rustfmt.args(&["--edition", &edition.to_string()]); | 618 | // Assume all crates are in the same edition |
619 | } | 619 | let edition = world.analysis().crate_edition(crate_id)?; |
620 | cmd.arg("--edition"); | ||
621 | cmd.arg(edition.to_string()); | ||
622 | } | ||
623 | cmd | ||
624 | } | ||
625 | RustfmtConfig::CustomCommand { command, args } => { | ||
626 | let mut cmd = process::Command::new(command); | ||
627 | cmd.args(args); | ||
628 | cmd | ||
629 | } | ||
630 | }; | ||
620 | 631 | ||
621 | if let Ok(path) = params.text_document.uri.to_file_path() { | 632 | if let Ok(path) = params.text_document.uri.to_file_path() { |
622 | if let Some(parent) = path.parent() { | 633 | if let Some(parent) = path.parent() { |