aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-01 12:31:12 +0100
committerAleksey Kladov <[email protected]>2020-04-01 13:26:08 +0100
commit6ac966899853f03ab572ccd2cee8bf5b2a66aaea (patch)
tree552a089fafbb7e6de0f9e0f325329e537f36ea98 /crates
parent67351a011bbaf63617c7fc96884129e9fc39e411 (diff)
Generalize rustfmt config
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs4
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs27
-rw-r--r--crates/rust-analyzer/src/world.rs20
3 files changed, 40 insertions, 11 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index a89ea86ea..753dc7d50 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -38,7 +38,7 @@ use crate::{
38 subscriptions::Subscriptions, 38 subscriptions::Subscriptions,
39 }, 39 },
40 req, 40 req,
41 world::{Config, WorldSnapshot, WorldState}, 41 world::{Config, RustfmtConfig, WorldSnapshot, WorldState},
42 Result, ServerConfig, 42 Result, ServerConfig,
43}; 43};
44use req::ConfigurationParams; 44use req::ConfigurationParams;
@@ -110,7 +110,7 @@ fn get_config(
110 } else { 110 } else {
111 None 111 None
112 }, 112 },
113 rustfmt_args: config.rustfmt_args.clone(), 113 rustfmt: RustfmtConfig::Rustfmt { extra_args: config.rustfmt_args.clone() },
114 vscode_lldb: config.vscode_lldb, 114 vscode_lldb: config.vscode_lldb,
115 proc_macro_srv: None, // FIXME: get this from config 115 proc_macro_srv: None, // FIXME: get this from config
116 } 116 }
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() {
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 2db058eb1..ccdf3710c 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -57,12 +57,30 @@ pub struct Config {
57 pub supports_location_link: bool, 57 pub supports_location_link: bool,
58 pub line_folding_only: bool, 58 pub line_folding_only: bool,
59 pub inlay_hints: InlayHintsConfig, 59 pub inlay_hints: InlayHintsConfig,
60 pub rustfmt_args: Vec<String>, 60 pub rustfmt: RustfmtConfig,
61 pub check: Option<FlycheckConfig>, 61 pub check: Option<FlycheckConfig>,
62 pub vscode_lldb: bool, 62 pub vscode_lldb: bool,
63 pub proc_macro_srv: Option<String>, 63 pub proc_macro_srv: Option<String>,
64} 64}
65 65
66#[derive(Debug, Clone)]
67pub enum RustfmtConfig {
68 Rustfmt {
69 extra_args: Vec<String>,
70 },
71 #[allow(unused)]
72 CustomCommand {
73 command: String,
74 args: Vec<String>,
75 },
76}
77
78impl Default for RustfmtConfig {
79 fn default() -> Self {
80 RustfmtConfig::Rustfmt { extra_args: Vec::new() }
81 }
82}
83
66/// `WorldState` is the primary mutable state of the language server 84/// `WorldState` is the primary mutable state of the language server
67/// 85///
68/// The most interesting components are `vfs`, which stores a consistent 86/// The most interesting components are `vfs`, which stores a consistent