mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-28 18:31:37 +03:00
Merge pull request #2342 from zed-industries/trust-npm-version-management
Trust NPM instead of managing dirs for different Node server versions
This commit is contained in:
commit
59fb4b3d29
@ -1,4 +1,4 @@
|
|||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
|
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
|
||||||
@ -8,7 +8,6 @@ use smol::fs;
|
|||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{any::Any, path::PathBuf, sync::Arc};
|
use std::{any::Any, path::PathBuf, sync::Arc};
|
||||||
use util::fs::remove_matching;
|
|
||||||
use util::http::HttpClient;
|
use util::http::HttpClient;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
@ -53,21 +52,15 @@ impl LspAdapter for HtmlLspAdapter {
|
|||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
let version = version.downcast::<String>().unwrap();
|
let version = version.downcast::<String>().unwrap();
|
||||||
let version_dir = container_dir.join(version.as_str());
|
let server_path = container_dir.join(Self::SERVER_PATH);
|
||||||
fs::create_dir_all(&version_dir)
|
|
||||||
.await
|
|
||||||
.context("failed to create version directory")?;
|
|
||||||
let server_path = version_dir.join(Self::SERVER_PATH);
|
|
||||||
|
|
||||||
if fs::metadata(&server_path).await.is_err() {
|
if fs::metadata(&server_path).await.is_err() {
|
||||||
self.node
|
self.node
|
||||||
.npm_install_packages(
|
.npm_install_packages(
|
||||||
[("vscode-langservers-extracted", version.as_str())],
|
[("vscode-langservers-extracted", version.as_str())],
|
||||||
&version_dir,
|
&container_dir,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
remove_matching(container_dir.as_path(), |entry| entry != version_dir).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(LanguageServerBinary {
|
Ok(LanguageServerBinary {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use futures::{future::BoxFuture, FutureExt, StreamExt};
|
use futures::{future::BoxFuture, FutureExt, StreamExt};
|
||||||
@ -16,7 +16,7 @@ use std::{
|
|||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use theme::ThemeRegistry;
|
use theme::ThemeRegistry;
|
||||||
use util::{fs::remove_matching, http::HttpClient};
|
use util::http::HttpClient;
|
||||||
use util::{paths, ResultExt, StaffMode};
|
use util::{paths, ResultExt, StaffMode};
|
||||||
|
|
||||||
const SERVER_PATH: &'static str =
|
const SERVER_PATH: &'static str =
|
||||||
@ -70,21 +70,15 @@ impl LspAdapter for JsonLspAdapter {
|
|||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
let version = version.downcast::<String>().unwrap();
|
let version = version.downcast::<String>().unwrap();
|
||||||
let version_dir = container_dir.join(version.as_str());
|
let server_path = container_dir.join(SERVER_PATH);
|
||||||
fs::create_dir_all(&version_dir)
|
|
||||||
.await
|
|
||||||
.context("failed to create version directory")?;
|
|
||||||
let server_path = version_dir.join(SERVER_PATH);
|
|
||||||
|
|
||||||
if fs::metadata(&server_path).await.is_err() {
|
if fs::metadata(&server_path).await.is_err() {
|
||||||
self.node
|
self.node
|
||||||
.npm_install_packages(
|
.npm_install_packages(
|
||||||
[("vscode-json-languageserver", version.as_str())],
|
[("vscode-json-languageserver", version.as_str())],
|
||||||
&version_dir,
|
&container_dir,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
remove_matching(&container_dir, |entry| entry != version_dir).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(LanguageServerBinary {
|
Ok(LanguageServerBinary {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
|
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
|
||||||
@ -10,7 +10,6 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use util::fs::remove_matching;
|
|
||||||
use util::http::HttpClient;
|
use util::http::HttpClient;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
@ -50,18 +49,12 @@ impl LspAdapter for PythonLspAdapter {
|
|||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
let version = version.downcast::<String>().unwrap();
|
let version = version.downcast::<String>().unwrap();
|
||||||
let version_dir = container_dir.join(version.as_str());
|
let server_path = container_dir.join(Self::SERVER_PATH);
|
||||||
fs::create_dir_all(&version_dir)
|
|
||||||
.await
|
|
||||||
.context("failed to create version directory")?;
|
|
||||||
let server_path = version_dir.join(Self::SERVER_PATH);
|
|
||||||
|
|
||||||
if fs::metadata(&server_path).await.is_err() {
|
if fs::metadata(&server_path).await.is_err() {
|
||||||
self.node
|
self.node
|
||||||
.npm_install_packages([("pyright", version.as_str())], &version_dir)
|
.npm_install_packages([("pyright", version.as_str())], &container_dir)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
remove_matching(&container_dir, |entry| entry != version_dir).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(LanguageServerBinary {
|
Ok(LanguageServerBinary {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
|
use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
|
||||||
@ -12,7 +12,6 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use util::fs::remove_matching;
|
|
||||||
use util::http::HttpClient;
|
use util::http::HttpClient;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
@ -69,14 +68,7 @@ impl LspAdapter for TypeScriptLspAdapter {
|
|||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
let versions = versions.downcast::<Versions>().unwrap();
|
let versions = versions.downcast::<Versions>().unwrap();
|
||||||
let version_dir = container_dir.join(&format!(
|
let server_path = container_dir.join(Self::NEW_SERVER_PATH);
|
||||||
"typescript-{}:server-{}",
|
|
||||||
versions.typescript_version, versions.server_version
|
|
||||||
));
|
|
||||||
fs::create_dir_all(&version_dir)
|
|
||||||
.await
|
|
||||||
.context("failed to create version directory")?;
|
|
||||||
let server_path = version_dir.join(Self::NEW_SERVER_PATH);
|
|
||||||
|
|
||||||
if fs::metadata(&server_path).await.is_err() {
|
if fs::metadata(&server_path).await.is_err() {
|
||||||
self.node
|
self.node
|
||||||
@ -88,11 +80,9 @@ impl LspAdapter for TypeScriptLspAdapter {
|
|||||||
versions.server_version.as_str(),
|
versions.server_version.as_str(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
&version_dir,
|
&container_dir,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
remove_matching(&container_dir, |entry| entry != version_dir).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(LanguageServerBinary {
|
Ok(LanguageServerBinary {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::{future::BoxFuture, FutureExt, StreamExt};
|
use futures::{future::BoxFuture, FutureExt, StreamExt};
|
||||||
use gpui::MutableAppContext;
|
use gpui::MutableAppContext;
|
||||||
@ -14,8 +14,8 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
use util::http::HttpClient;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use util::{fs::remove_matching, http::HttpClient};
|
|
||||||
|
|
||||||
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||||
vec![server_path.into(), "--stdio".into()]
|
vec![server_path.into(), "--stdio".into()]
|
||||||
@ -57,18 +57,12 @@ impl LspAdapter for YamlLspAdapter {
|
|||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
let version = version.downcast::<String>().unwrap();
|
let version = version.downcast::<String>().unwrap();
|
||||||
let version_dir = container_dir.join(version.as_str());
|
let server_path = container_dir.join(Self::SERVER_PATH);
|
||||||
fs::create_dir_all(&version_dir)
|
|
||||||
.await
|
|
||||||
.context("failed to create version directory")?;
|
|
||||||
let server_path = version_dir.join(Self::SERVER_PATH);
|
|
||||||
|
|
||||||
if fs::metadata(&server_path).await.is_err() {
|
if fs::metadata(&server_path).await.is_err() {
|
||||||
self.node
|
self.node
|
||||||
.npm_install_packages([("yaml-language-server", version.as_str())], &version_dir)
|
.npm_install_packages([("yaml-language-server", version.as_str())], &container_dir)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
remove_matching(&container_dir, |entry| entry != version_dir).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(LanguageServerBinary {
|
Ok(LanguageServerBinary {
|
||||||
|
Loading…
Reference in New Issue
Block a user