rust: Fix looking up rust-analyzer
in $PATH
by default (#17926)
This is a follow-up to https://github.com/zed-industries/zed/pull/17885, which is reverted and fixed in this PR. This PR actually enables the behavior by default. Release Notes: - Changed `rust-analyzer` support to lookup `rust-analyzer` binaries by default in `$PATH`. That changes the default value to something users requested.
This commit is contained in:
parent
7d97855ed7
commit
d56e3d99b4
1 changed files with 45 additions and 35 deletions
|
@ -38,46 +38,56 @@ impl LspAdapter for RustLspAdapter {
|
|||
delegate: &dyn LspAdapterDelegate,
|
||||
cx: &AsyncAppContext,
|
||||
) -> Option<LanguageServerBinary> {
|
||||
let configured_binary = cx.update(|cx| {
|
||||
language_server_settings(delegate, Self::SERVER_NAME, cx).and_then(|s| s.binary.clone())
|
||||
});
|
||||
let configured_binary = cx
|
||||
.update(|cx| {
|
||||
language_server_settings(delegate, Self::SERVER_NAME, cx)
|
||||
.and_then(|s| s.binary.clone())
|
||||
})
|
||||
.ok()?;
|
||||
|
||||
match configured_binary {
|
||||
Ok(Some(BinarySettings {
|
||||
path,
|
||||
let (path, env, arguments) = match configured_binary {
|
||||
// If nothing is configured, or path_lookup explicitly enabled,
|
||||
// we lookup the binary in the path.
|
||||
None
|
||||
| Some(BinarySettings {
|
||||
path: None,
|
||||
path_lookup: Some(true),
|
||||
..
|
||||
})
|
||||
| Some(BinarySettings {
|
||||
path: None,
|
||||
path_lookup: None,
|
||||
..
|
||||
}) => {
|
||||
let path = delegate.which(Self::SERVER_NAME.as_ref()).await;
|
||||
let env = delegate.shell_env().await;
|
||||
(path, Some(env), None)
|
||||
}
|
||||
// Otherwise, we use the configured binary.
|
||||
Some(BinarySettings {
|
||||
path: Some(path),
|
||||
arguments,
|
||||
path_lookup,
|
||||
})) => {
|
||||
let (path, env) = match (path, path_lookup) {
|
||||
(Some(path), lookup) => {
|
||||
if lookup.is_some() {
|
||||
log::warn!(
|
||||
"Both `path` and `path_lookup` are set, ignoring `path_lookup`"
|
||||
);
|
||||
}) => {
|
||||
if path_lookup.is_some() {
|
||||
log::warn!("Both `path` and `path_lookup` are set, ignoring `path_lookup`");
|
||||
}
|
||||
(Some(path.into()), None)
|
||||
(Some(path.into()), None, arguments)
|
||||
}
|
||||
(None, Some(true)) | (None, None) => {
|
||||
// Try to lookup rust-analyzer in PATH by default.
|
||||
let path = delegate.which(Self::SERVER_NAME.as_ref()).await?;
|
||||
let env = delegate.shell_env().await;
|
||||
(Some(path), Some(env))
|
||||
}
|
||||
(None, Some(false)) => (None, None),
|
||||
|
||||
_ => (None, None, None),
|
||||
};
|
||||
|
||||
path.map(|path| LanguageServerBinary {
|
||||
path,
|
||||
env,
|
||||
arguments: arguments
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.map(|arg| arg.into())
|
||||
.collect(),
|
||||
env,
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
&self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue