mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Find workspace from document path (#3553)
This commit is contained in:
parent
66bbba9024
commit
7c9809eeb2
@ -49,6 +49,7 @@ pub fn start(
|
||||
root_markers: &[String],
|
||||
id: usize,
|
||||
req_timeout: u64,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> {
|
||||
// Resolve path to the binary
|
||||
let cmd = which::which(cmd).map_err(|err| anyhow::anyhow!(err))?;
|
||||
@ -72,7 +73,10 @@ pub fn start(
|
||||
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 = lsp::Url::from_file_path(root_path.clone()).ok();
|
||||
|
||||
|
@ -353,6 +353,7 @@ pub fn get_by_id(&self, id: usize) -> Option<&Client> {
|
||||
pub fn restart(
|
||||
&mut self,
|
||||
language_config: &LanguageConfiguration,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
) -> Result<Option<Arc<Client>>> {
|
||||
let config = match &language_config.language_server {
|
||||
Some(config) => config,
|
||||
@ -367,7 +368,8 @@ pub fn restart(
|
||||
// initialize a new client
|
||||
let id = self.counter.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
let NewClientResult(client, incoming) = start_client(id, language_config, config)?;
|
||||
let NewClientResult(client, incoming) =
|
||||
start_client(id, language_config, config, doc_path)?;
|
||||
self.incoming.push(UnboundedReceiverStream::new(incoming));
|
||||
|
||||
let (_, old_client) = entry.insert((id, client.clone()));
|
||||
@ -381,7 +383,11 @@ pub fn restart(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Option<Arc<Client>>> {
|
||||
pub fn get(
|
||||
&mut self,
|
||||
language_config: &LanguageConfiguration,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
) -> Result<Option<Arc<Client>>> {
|
||||
let config = match &language_config.language_server {
|
||||
Some(config) => config,
|
||||
None => return Ok(None),
|
||||
@ -393,7 +399,8 @@ pub fn get(&mut self, language_config: &LanguageConfiguration) -> Result<Option<
|
||||
// initialize a new client
|
||||
let id = self.counter.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
let NewClientResult(client, incoming) = start_client(id, language_config, config)?;
|
||||
let NewClientResult(client, incoming) =
|
||||
start_client(id, language_config, config, doc_path)?;
|
||||
self.incoming.push(UnboundedReceiverStream::new(incoming));
|
||||
|
||||
entry.insert((id, client.clone()));
|
||||
@ -493,6 +500,7 @@ fn start_client(
|
||||
id: usize,
|
||||
config: &LanguageConfiguration,
|
||||
ls_config: &LanguageServerConfiguration,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
) -> Result<NewClientResult> {
|
||||
let (client, incoming, initialize_notify) = Client::start(
|
||||
&ls_config.command,
|
||||
@ -501,6 +509,7 @@ fn start_client(
|
||||
&config.roots,
|
||||
id,
|
||||
ls_config.timeout,
|
||||
doc_path,
|
||||
)?;
|
||||
|
||||
let client = Arc::new(client);
|
||||
|
@ -1000,7 +1000,7 @@ fn lsp_restart(
|
||||
.context("LSP not defined for the current document")?;
|
||||
|
||||
let scope = config.scope.clone();
|
||||
cx.editor.language_servers.restart(config)?;
|
||||
cx.editor.language_servers.restart(config, doc.path())?;
|
||||
|
||||
// This collect is needed because refresh_language_server would need to re-borrow editor.
|
||||
let document_ids_to_refresh: Vec<DocumentId> = cx
|
||||
|
@ -868,7 +868,7 @@ fn launch_language_server(ls: &mut helix_lsp::Registry, doc: &mut Document) -> O
|
||||
|
||||
// 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 `{}` {{ {} }}",
|
||||
|
Loading…
Reference in New Issue
Block a user