summaryrefslogtreecommitdiff
path: root/helix-lsp
diff options
context:
space:
mode:
authorfarwyler2022-06-05 10:50:57 +0000
committerGitHub2022-06-05 10:50:57 +0000
commitf92a25a856d572c7bd4b8e597a3f86ce211e81d5 (patch)
treef6f63b8ab2c6af7d47f64b9bd8a90bd9950ed3e3 /helix-lsp
parentb2bd87df81756d4925bf1f4da6962b9dd83a807c (diff)
Passing extra formatting options to LSPs (#2635)
* allows passing extra formatting options to LSPs - adds optional field 'format' to [[language]] sections in 'languages.toml' - passes specified options the LSPs via FormattingOptions * cleaner conversion of formatting properties * move formatting options inside lsp::Client * cleans up formatting properties merge
Diffstat (limited to 'helix-lsp')
-rw-r--r--helix-lsp/src/client.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index 08201b3f..7f556ca6 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -7,7 +7,9 @@ use anyhow::anyhow;
use helix_core::{find_root, ChangeSet, Rope};
use jsonrpc_core as jsonrpc;
use lsp_types as lsp;
+use serde::Deserialize;
use serde_json::Value;
+use std::collections::HashMap;
use std::future::Future;
use std::process::Stdio;
use std::sync::{
@@ -693,6 +695,24 @@ impl Client {
};
// TODO: return err::unavailable so we can fall back to tree sitter formatting
+ // merge FormattingOptions with 'config.format'
+ 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 {
text_document,
options,