on master help sign in
Added option to provide a custom config file to the lsp. (#460)

* Added option to provide a custom config file to the lsp. * Simplified lsp loading routine with anyhow * Moved config to language.toml * Fixed test case * Cargo fmt * Revert now-useless changes * Renamed custom_config to config Co-authored-by: Cor <prive@corpeters.nl>

commit0aa43902cab5dbcddb72ddf5d3b825ef874dc620 authorCor Peters <luctius@users.noreply.github.com> dateSun 18 Jul 2021, 09:56 (5 years ago) parent6cba62b
5 files changed+26−2
helix-core/src/indent.rs+1 helix-core/src/syntax.rs+1 helix-lsp/src/client.rs+8−1 helix-lsp/src/lib.rs+6−1 languages.toml+10
helix-core/src/indent.rs+1
@@ -262,6 +262,7 @@ where
262262 file_types: vec!["rs".to_string()],
263263 language_id: "Rust".to_string(),
264264 highlight_config: OnceCell::new(),
265+ config: None,
265266 //
266267 roots: vec![],
267268 auto_format: false,
helix-core/src/syntax.rs+1
@@ -35,6 +35,7 @@ pub struct LanguageConfiguration {
3535 pub scope: String, // source.rust
3636 pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
3737 pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
38+ pub config: Option<String>,
3839
3940 #[serde(default)]
4041 pub auto_format: bool,
helix-lsp/src/client.rs+8−1
@@ -24,12 +24,14 @@ pub struct Client {
2424 request_counter: AtomicU64,
2525 capabilities: Option<lsp::ServerCapabilities>,
2626 offset_encoding: OffsetEncoding,
27+ config: Option<Value>,
2728}
2829
2930impl Client {
3031 pub fn start(
3132 cmd: &str,
3233 args: &[String],
34+ config: Option<Value>,
3335 id: usize,
3436 ) -> Result<(Self, UnboundedReceiver<(usize, Call)>)> {
3537 let process = Command::new(cmd)
@@ -57,6 +59,7 @@ impl Client {
5759 request_counter: AtomicU64::new(0),
5860 capabilities: None,
5961 offset_encoding: OffsetEncoding::Utf8,
62+ config,
6063 };
6164
6265 // TODO: async client.initialize()
@@ -214,13 +217,17 @@ impl Client {
214217 // TODO: delay any requests that are triggered prior to initialize
215218 let root = find_root(None).and_then(|root| lsp::Url::from_file_path(root).ok());
216219
220+ if self.config.is_some() {
221+ log::info!("Using custom LSP config: {}", self.config.as_ref().unwrap());
222+ }
223+
217224 #[allow(deprecated)]
218225 let params = lsp::InitializeParams {
219226 process_id: Some(std::process::id()),
220227 // root_path is obsolete, use root_uri
221228 root_path: None,
222229 root_uri: root,
223− initialization_options: None,
230+ initialization_options: self.config.clone(),
224231 capabilities: lsp::ClientCapabilities {
225232 text_document: Some(lsp::TextDocumentClientCapabilities {
226233 completion: Some(lsp::CompletionClientCapabilities {
helix-lsp/src/lib.rs+6−1
@@ -312,7 +312,12 @@ impl Registry {
312312 Entry::Vacant(entry) => {
313313 // initialize a new client
314314 let id = self.counter.fetch_add(1, Ordering::Relaxed);
315− let (mut client, incoming) = Client::start(&config.command, &config.args, id)?;
315+ let (mut client, incoming) = Client::start(
316+ &config.command,
317+ &config.args,
318+ serde_json::from_str(language_config.config.as_deref().unwrap_or("")).ok(),
319+ id,
320+ )?;
316321 // TODO: run this async without blocking
317322 futures_executor::block_on(client.initialize())?;
318323 s_incoming.push(UnboundedReceiverStream::new(incoming));
languages.toml+10
@@ -5,6 +5,16 @@ injection-regex = "rust"
55file-types = ["rs"]
66roots = []
77auto-format = true
8+config = """
9+{
10+ "cargo": {
11+ "loadOutDirsFromCheck": true
12+ },
13+ "procMacro": {
14+ "enable": false
15+ }
16+}
17+"""
818
919language-server = { command = "rust-analyzer" }
1020indent = { tab-width = 4, unit = " " }