on master help sign in
Find workspace from document path (#3553)
7c9809eath3
helix-lsp/src/client.rs+5−1
@@ -49,6 +49,7 @@ impl Client {
49 root_markers: &[String],
49 root_markers: &[String],
50 id: usize,
50 id: usize,
51 req_timeout: u64,
51 req_timeout: u64,
52+ doc_path: Option<&std::path::PathBuf>,
52 ) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
53 ) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
53 // Resolve path to the binary
54 // Resolve path to the binary
54 let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
55 let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
@@ -72,7 +73,10 @@ impl Client {
72 let (server_rx, server_tx, initialize_notify) =
73 let (server_rx, server_tx, initialize_notify) =
73 Transport::start(reader, writer, stderr, id);
74 Transport::start(reader, writer, stderr, id);
74
75
75− let root_path = find_root(None, root_markers);
76+ let root_path = find_root(
77+ doc_path.and_then(|x| x.parent().and_then(|x| x.to_str())),
78+ root_markers,
79+ );
76
80
77 let root_uri = lsp::Url::from_file_path(root_path.clone()).ok();
81 let root_uri = lsp::Url::from_file_path(root_path.clone()).ok();
78
82
helix-lsp/src/lib.rs+12−3
@@ -353,6 +353,7 @@ impl Registry {
353 pub fn restart(
353 pub fn restart(
354 &mut self,
354 &mut self,
355 language_config: &LanguageConfiguration,
355 language_config: &LanguageConfiguration,
356+ doc_path: Option<&std::path::PathBuf>,
356 ) -> Result<Option<Arc<Client>>> {
357 ) -> Result<Option<Arc<Client>>> {
357 let config = match &language_config.language_server {
358 let config = match &language_config.language_server {
358 Some(config) => config,
359 Some(config) => config,
@@ -367,7 +368,8 @@ impl Registry {
367 // initialize a new client
368 // initialize a new client
368 let id = self.counter.fetch_add(1, Ordering::Relaxed);
369 let id = self.counter.fetch_add(1, Ordering::Relaxed);
369
370
370− let NewClientResult(client, incoming) = start_client(id, language_config, config)?;
371+ let NewClientResult(client, incoming) =
372+ start_client(id, language_config, config, doc_path)?;
371 self.incoming.push(UnboundedReceiverStream::new(incoming));
373 self.incoming.push(UnboundedReceiverStream::new(incoming));
372
374
373 let (_, old_client) = entry.insert((id, client.clone()));
375 let (_, old_client) = entry.insert((id, client.clone()));
@@ -381,7 +383,11 @@ impl Registry {
381 }
383 }
382 }
384 }
383
385
386+ pub fn get(
387+ &mut self,
384− pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Option<Arc<Client>>> {
388+ language_config: &LanguageConfiguration,
389+ doc_path: Option<&std::path::PathBuf>,
390+ ) -> Result<Option<Arc<Client>>> {
385 let config = match &language_config.language_server {
391 let config = match &language_config.language_server {
386 Some(config) => config,
392 Some(config) => config,
387 None => return Ok(None),
393 None => return Ok(None),
@@ -393,7 +399,8 @@ impl Registry {
393 // initialize a new client
399 // initialize a new client
394 let id = self.counter.fetch_add(1, Ordering::Relaxed);
400 let id = self.counter.fetch_add(1, Ordering::Relaxed);
395
401
396− let NewClientResult(client, incoming) = start_client(id, language_config, config)?;
402+ let NewClientResult(client, incoming) =
403+ start_client(id, language_config, config, doc_path)?;
397 self.incoming.push(UnboundedReceiverStream::new(incoming));
404 self.incoming.push(UnboundedReceiverStream::new(incoming));
398
405
399 entry.insert((id, client.clone()));
406 entry.insert((id, client.clone()));
@@ -493,6 +500,7 @@ fn start_client(
493 id: usize,
500 id: usize,
494 config: &LanguageConfiguration,
501 config: &LanguageConfiguration,
495 ls_config: &LanguageServerConfiguration,
502 ls_config: &LanguageServerConfiguration,
503+ doc_path: Option<&std::path::PathBuf>,
496) -> Result<NewClientResult> {
504) -> Result<NewClientResult> {
497 let (client, incoming, initialize_notify) = Client::start(
505 let (client, incoming, initialize_notify) = Client::start(
498 &ls_config.command,
506 &ls_config.command,
@@ -501,6 +509,7 @@ fn start_client(
501 &config.roots,
509 &config.roots,
502 id,
510 id,
503 ls_config.timeout,
511 ls_config.timeout,
512+ doc_path,
504 )?;
513 )?;
505
514
506 let client = Arc::new(client);
515 let client = Arc::new(client);
helix-term/src/commands/typed.rs+1−1
@@ -1000,7 +1000,7 @@ fn lsp_restart(
1000 .context("LSP not defined for the current document")?;
1000 .context("LSP not defined for the current document")?;
1001
1001
1002 let scope = config.scope.clone();
1002 let scope = config.scope.clone();
1003− cx.editor.language_servers.restart(config)?;
1003+ cx.editor.language_servers.restart(config, doc.path())?;
1004
1004
1005 // This collect is needed because refresh_language_server would need to re-borrow editor.
1005 // This collect is needed because refresh_language_server would need to re-borrow editor.
1006 let document_ids_to_refresh: Vec<DocumentId> = cx
1006 let document_ids_to_refresh: Vec<DocumentId> = cx
helix-view/src/editor.rs+1−1
@@ -868,7 +868,7 @@ impl Editor {
868
868
869 // try to find a language server based on the language name
869 // try to find a language server based on the language name
870 let language_server = doc.language.as_ref().and_then(|language| {
870 let language_server = doc.language.as_ref().and_then(|language| {
871− ls.get(language)
871+ ls.get(language, doc.path())
872 .map_err(|e| {
872 .map_err(|e| {
873 log::error!(
873 log::error!(
874 "Failed to initialize the LSP for `{}` {{ {} }}",
874 "Failed to initialize the LSP for `{}` {{ {} }}",