mirror of https://github.com/helix-editor/helix
Merge formatting options and `config.format` in range format request (#13734)
parent
091f19f67c
commit
9dbfb9b4eb
|
@ -176,6 +176,29 @@ impl Client {
|
||||||
self.did_change_workspace(vec![workspace_for_uri(root_uri)], Vec::new())
|
self.did_change_workspace(vec![workspace_for_uri(root_uri)], Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Merge FormattingOptions with 'config.format' and return it
|
||||||
|
fn get_merged_formatting_options(
|
||||||
|
&self,
|
||||||
|
options: lsp::FormattingOptions,
|
||||||
|
) -> lsp::FormattingOptions {
|
||||||
|
let config_format = self
|
||||||
|
.config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|cfg| cfg.get("format"))
|
||||||
|
.and_then(|fmt| HashMap::<String, lsp::FormattingProperty>::deserialize(fmt).ok());
|
||||||
|
|
||||||
|
if let Some(mut properties) = config_format {
|
||||||
|
// passed in options take precedence over 'config.format'
|
||||||
|
properties.extend(options.properties);
|
||||||
|
lsp::FormattingOptions {
|
||||||
|
properties,
|
||||||
|
..options
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
options
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
|
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
|
||||||
pub fn start(
|
pub fn start(
|
||||||
cmd: &str,
|
cmd: &str,
|
||||||
|
@ -1168,23 +1191,7 @@ impl Client {
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// merge FormattingOptions with 'config.format'
|
let options = self.get_merged_formatting_options(options);
|
||||||
let config_format = self
|
|
||||||
.config
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|cfg| cfg.get("format"))
|
|
||||||
.and_then(|fmt| HashMap::<String, lsp::FormattingProperty>::deserialize(fmt).ok());
|
|
||||||
|
|
||||||
let options = if let Some(mut properties) = config_format {
|
|
||||||
// passed in options take precedence over 'config.format'
|
|
||||||
properties.extend(options.properties);
|
|
||||||
lsp::FormattingOptions {
|
|
||||||
properties,
|
|
||||||
..options
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
options
|
|
||||||
};
|
|
||||||
|
|
||||||
let params = lsp::DocumentFormattingParams {
|
let params = lsp::DocumentFormattingParams {
|
||||||
text_document,
|
text_document,
|
||||||
|
@ -1210,6 +1217,8 @@ impl Client {
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let options = self.get_merged_formatting_options(options);
|
||||||
|
|
||||||
let params = lsp::DocumentRangeFormattingParams {
|
let params = lsp::DocumentRangeFormattingParams {
|
||||||
text_document,
|
text_document,
|
||||||
range,
|
range,
|
||||||
|
|
Loading…
Reference in New Issue