From a2b0bdcc24a64061364aaa017bf6caef1810da7c Mon Sep 17 00:00:00 2001 From: Ilya Titkov Date: Mon, 17 Feb 2020 11:44:58 +0300 Subject: Add arguments to rustfmt --- crates/ra_lsp_server/src/config.rs | 3 +++ crates/ra_lsp_server/src/main_loop.rs | 1 + crates/ra_lsp_server/src/main_loop/handlers.rs | 1 + crates/ra_lsp_server/src/world.rs | 1 + editors/code/package.json | 18 ++++++++++++++++-- editors/code/src/client.ts | 1 + editors/code/src/config.ts | 3 ++- 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs index 2d7948d74..3314269ec 100644 --- a/crates/ra_lsp_server/src/config.rs +++ b/crates/ra_lsp_server/src/config.rs @@ -44,6 +44,8 @@ pub struct ServerConfig { /// Fine grained feature flags to disable specific features. pub feature_flags: FxHashMap, + pub rustfmt_args: Vec, + /// Cargo feature configurations. pub cargo_features: CargoFeatures, } @@ -63,6 +65,7 @@ impl Default for ServerConfig { with_sysroot: true, feature_flags: FxHashMap::default(), cargo_features: Default::default(), + rustfmt_args: Vec::new(), } } } diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index ceff82fda..1e70cea13 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -178,6 +178,7 @@ pub fn main_loop( command: config.cargo_watch_command, all_targets: config.cargo_watch_all_targets, }, + rustfmt_args: config.rustfmt_args, } }; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 2e598fdcd..1da2d1814 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -590,6 +590,7 @@ pub fn handle_formatting( let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); let mut rustfmt = process::Command::new("rustfmt"); + rustfmt.args(&world.options.rustfmt_args); if let Some(&crate_id) = crate_ids.first() { // Assume all crates are in the same edition let edition = world.analysis().crate_edition(crate_id)?; diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 1ee02b47c..d993c5fc4 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -34,6 +34,7 @@ pub struct Options { pub supports_location_link: bool, pub line_folding_only: bool, pub max_inlay_hint_length: Option, + pub rustfmt_args: Vec, pub cargo_watch: CheckOptions, } diff --git a/editors/code/package.json b/editors/code/package.json index ed1cae2ab..46acbfe76 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -188,6 +188,14 @@ "default": [], "description": "Paths to exclude from analysis" }, + "rust-analyzer.rustfmtArgs": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "Additional arguments to rustfmt" + }, "rust-analyzer.useClientWatching": { "type": "boolean", "default": true, @@ -233,7 +241,10 @@ "description": "Trace requests to the ra_lsp_server" }, "rust-analyzer.lruCapacity": { - "type": [ "null", "integer" ], + "type": [ + "null", + "integer" + ], "default": null, "minimum": 0, "exclusiveMinimum": true, @@ -245,7 +256,10 @@ "description": "Display additional type and parameter information in the editor" }, "rust-analyzer.maxInlayHintLength": { - "type": [ "null", "integer" ], + "type": [ + "null", + "integer" + ], "default": 20, "minimum": 0, "exclusiveMinimum": true, diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index efef820ab..11894973c 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -42,6 +42,7 @@ export async function createClient(config: Config): Promise; } - + get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; } + get cargoWatchOptions(): CargoWatchOptions { return { enable: this.cfg.get("cargo-watch.enable") as boolean, -- cgit v1.2.3