From f92a25a856d572c7bd4b8e597a3f86ce211e81d5 Mon Sep 17 00:00:00 2001 From: farwyler Date: Sun, 5 Jun 2022 12:50:57 +0200 Subject: 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--- helix-lsp/src/client.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'helix-lsp/src') 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::::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, -- cgit v1.2.3-70-g09d2