Generalize rustfmt config
This commit is contained in:
@@ -38,7 +38,7 @@ use crate::{
|
|||||||
subscriptions::Subscriptions,
|
subscriptions::Subscriptions,
|
||||||
},
|
},
|
||||||
req,
|
req,
|
||||||
world::{Config, WorldSnapshot, WorldState},
|
world::{Config, RustfmtConfig, WorldSnapshot, WorldState},
|
||||||
Result, ServerConfig,
|
Result, ServerConfig,
|
||||||
};
|
};
|
||||||
use req::ConfigurationParams;
|
use req::ConfigurationParams;
|
||||||
@@ -110,7 +110,7 @@ fn get_config(
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
rustfmt_args: config.rustfmt_args.clone(),
|
rustfmt: RustfmtConfig::Rustfmt { extra_args: config.rustfmt_args.clone() },
|
||||||
vscode_lldb: config.vscode_lldb,
|
vscode_lldb: config.vscode_lldb,
|
||||||
proc_macro_srv: None, // FIXME: get this from config
|
proc_macro_srv: None, // FIXME: get this from config
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ use crate::{
|
|||||||
from_json,
|
from_json,
|
||||||
req::{self, Decoration, InlayHint, InlayHintsParams},
|
req::{self, Decoration, InlayHint, InlayHintsParams},
|
||||||
semantic_tokens::SemanticTokensBuilder,
|
semantic_tokens::SemanticTokensBuilder,
|
||||||
world::WorldSnapshot,
|
world::{RustfmtConfig, WorldSnapshot},
|
||||||
LspError, Result,
|
LspError, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -610,13 +610,24 @@ pub fn handle_formatting(
|
|||||||
let file_line_index = world.analysis().file_line_index(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);
|
let end_position = TextUnit::of_str(&file).conv_with(&file_line_index);
|
||||||
|
|
||||||
let mut rustfmt = process::Command::new("rustfmt");
|
let mut rustfmt = match &world.config.rustfmt {
|
||||||
rustfmt.args(&world.config.rustfmt_args);
|
RustfmtConfig::Rustfmt { extra_args } => {
|
||||||
|
let mut cmd = process::Command::new("rustfmt");
|
||||||
|
cmd.args(extra_args);
|
||||||
if let Some(&crate_id) = crate_ids.first() {
|
if let Some(&crate_id) = crate_ids.first() {
|
||||||
// Assume all crates are in the same edition
|
// Assume all crates are in the same edition
|
||||||
let edition = world.analysis().crate_edition(crate_id)?;
|
let edition = world.analysis().crate_edition(crate_id)?;
|
||||||
rustfmt.args(&["--edition", &edition.to_string()]);
|
cmd.arg("--edition");
|
||||||
|
cmd.arg(edition.to_string());
|
||||||
}
|
}
|
||||||
|
cmd
|
||||||
|
}
|
||||||
|
RustfmtConfig::CustomCommand { command, args } => {
|
||||||
|
let mut cmd = process::Command::new(command);
|
||||||
|
cmd.args(args);
|
||||||
|
cmd
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if let Ok(path) = params.text_document.uri.to_file_path() {
|
if let Ok(path) = params.text_document.uri.to_file_path() {
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
|
|||||||
@@ -57,12 +57,30 @@ pub struct Config {
|
|||||||
pub supports_location_link: bool,
|
pub supports_location_link: bool,
|
||||||
pub line_folding_only: bool,
|
pub line_folding_only: bool,
|
||||||
pub inlay_hints: InlayHintsConfig,
|
pub inlay_hints: InlayHintsConfig,
|
||||||
pub rustfmt_args: Vec<String>,
|
pub rustfmt: RustfmtConfig,
|
||||||
pub check: Option<FlycheckConfig>,
|
pub check: Option<FlycheckConfig>,
|
||||||
pub vscode_lldb: bool,
|
pub vscode_lldb: bool,
|
||||||
pub proc_macro_srv: Option<String>,
|
pub proc_macro_srv: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum RustfmtConfig {
|
||||||
|
Rustfmt {
|
||||||
|
extra_args: Vec<String>,
|
||||||
|
},
|
||||||
|
#[allow(unused)]
|
||||||
|
CustomCommand {
|
||||||
|
command: String,
|
||||||
|
args: Vec<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for RustfmtConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
RustfmtConfig::Rustfmt { extra_args: Vec::new() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// `WorldState` is the primary mutable state of the language server
|
/// `WorldState` is the primary mutable state of the language server
|
||||||
///
|
///
|
||||||
/// The most interesting components are `vfs`, which stores a consistent
|
/// The most interesting components are `vfs`, which stores a consistent
|
||||||
|
|||||||
Reference in New Issue
Block a user