From 7c9bc1c3b510dd0e8966b1df969f57990b2c6f6e Mon Sep 17 00:00:00 2001 From: ath3 Date: Fri, 26 Aug 2022 17:35:05 +0200 Subject: [PATCH] Find workspace from document path --- helix-lsp/src/client.rs | 6 +++++- helix-lsp/src/lib.rs | 7 ++++++- helix-view/src/editor.rs | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 9ae8f20e55070..a23d3e6f0545d 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -49,6 +49,7 @@ impl Client { root_markers: &[String], id: usize, req_timeout: u64, + doc_path: Option<&std::path::PathBuf>, ) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc)> { // Resolve path to the binary let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?; @@ -72,7 +73,10 @@ impl Client { let (server_rx, server_tx, initialize_notify) = Transport::start(reader, writer, stderr, id); - let root_path = find_root(None, root_markers); + let root_path = find_root( + doc_path.and_then(|x| x.parent().and_then(|x| x.to_str())), + root_markers, + ); let root_uri = root_path .clone() diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 79d9609e1c5f7..2b1fa4687f0e4 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -320,7 +320,11 @@ impl Registry { .map(|(_, client)| client.as_ref()) } - pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result> { + pub fn get( + &mut self, + language_config: &LanguageConfiguration, + doc_path: Option<&std::path::PathBuf>, + ) -> Result> { let config = match &language_config.language_server { Some(config) => config, None => return Err(Error::LspNotDefined), @@ -338,6 +342,7 @@ impl Registry { &language_config.roots, id, config.timeout, + doc_path, )?; self.incoming.push(UnboundedReceiverStream::new(incoming)); let client = Arc::new(client); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 520a425c18ac7..ae8590684b698 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -808,7 +808,7 @@ impl Editor { // try to find a language server based on the language name let language_server = doc.language.as_ref().and_then(|language| { - ls.get(language) + ls.get(language, doc.path()) .map_err(|e| { log::error!( "Failed to initialize the LSP for `{}` {{ {} }}",