Allow using system node (#18172)
Release Notes: - (Potentially breaking change) Zed will now use the node installed on your $PATH (if it is more recent than v18) instead of downloading its own. You can disable the new behavior with `{"node": {"disable_path_lookup": true}}` in your settings. We do not yet use system/project-local node_modules. --------- Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
e4080ef565
commit
3ba071b993
34 changed files with 614 additions and 391 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -7190,6 +7190,7 @@ dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-tar",
|
"async-tar",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"async-watch",
|
||||||
"async_zip",
|
"async_zip",
|
||||||
"futures 0.3.30",
|
"futures 0.3.30",
|
||||||
"http_client",
|
"http_client",
|
||||||
|
@ -7202,6 +7203,7 @@ dependencies = [
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"util",
|
"util",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
|
"which 6.0.3",
|
||||||
"windows 0.58.0",
|
"windows 0.58.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -14393,6 +14395,7 @@ dependencies = [
|
||||||
"ashpd",
|
"ashpd",
|
||||||
"assets",
|
"assets",
|
||||||
"assistant",
|
"assistant",
|
||||||
|
"async-watch",
|
||||||
"audio",
|
"audio",
|
||||||
"auto_update",
|
"auto_update",
|
||||||
"backtrace",
|
"backtrace",
|
||||||
|
@ -14466,6 +14469,7 @@ dependencies = [
|
||||||
"session",
|
"session",
|
||||||
"settings",
|
"settings",
|
||||||
"settings_ui",
|
"settings_ui",
|
||||||
|
"shellexpand 2.1.2",
|
||||||
"simplelog",
|
"simplelog",
|
||||||
"smol",
|
"smol",
|
||||||
"snippet_provider",
|
"snippet_provider",
|
||||||
|
|
|
@ -771,6 +771,21 @@
|
||||||
"pyrightconfig.json"
|
"pyrightconfig.json"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
/// By default use a recent system version of node, or install our own.
|
||||||
|
/// You can override this to use a version of node that is not in $PATH with:
|
||||||
|
/// {
|
||||||
|
/// "node": {
|
||||||
|
/// "node_path": "/path/to/node"
|
||||||
|
/// "npm_path": "/path/to/npm" (defaults to node_path/../npm)
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// or to ensure Zed always downloads and installs an isolated version of node:
|
||||||
|
/// {
|
||||||
|
/// "node": {
|
||||||
|
/// "disable_path_lookup": true
|
||||||
|
/// }
|
||||||
|
/// NOTE: changing this setting currently requires restarting Zed.
|
||||||
|
"node": {},
|
||||||
// The extensions that Zed should automatically install on startup.
|
// The extensions that Zed should automatically install on startup.
|
||||||
//
|
//
|
||||||
// If you don't want any of these extensions, add this field to your settings
|
// If you don't want any of these extensions, add this field to your settings
|
||||||
|
|
|
@ -21,7 +21,7 @@ use git::GitHostingProviderRegistry;
|
||||||
use gpui::{BackgroundExecutor, Context, Model, Task, TestAppContext, View, VisualTestContext};
|
use gpui::{BackgroundExecutor, Context, Model, Task, TestAppContext, View, VisualTestContext};
|
||||||
use http_client::FakeHttpClient;
|
use http_client::FakeHttpClient;
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use notifications::NotificationStore;
|
use notifications::NotificationStore;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use project::{Project, WorktreeId};
|
use project::{Project, WorktreeId};
|
||||||
|
@ -278,7 +278,7 @@ impl TestServer {
|
||||||
languages: language_registry,
|
languages: language_registry,
|
||||||
fs: fs.clone(),
|
fs: fs.clone(),
|
||||||
build_window_options: |_, _| Default::default(),
|
build_window_options: |_, _| Default::default(),
|
||||||
node_runtime: FakeNodeRuntime::new(),
|
node_runtime: NodeRuntime::unavailable(),
|
||||||
session,
|
session,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ impl TestServer {
|
||||||
languages: language_registry,
|
languages: language_registry,
|
||||||
fs: fs.clone(),
|
fs: fs.clone(),
|
||||||
build_window_options: |_, _| Default::default(),
|
build_window_options: |_, _| Default::default(),
|
||||||
node_runtime: FakeNodeRuntime::new(),
|
node_runtime: NodeRuntime::unavailable(),
|
||||||
session,
|
session,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub fn init(
|
||||||
new_server_id: LanguageServerId,
|
new_server_id: LanguageServerId,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: NodeRuntime,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) {
|
) {
|
||||||
copilot_chat::init(fs, http.clone(), cx);
|
copilot_chat::init(fs, http.clone(), cx);
|
||||||
|
@ -302,7 +302,7 @@ pub struct Completion {
|
||||||
|
|
||||||
pub struct Copilot {
|
pub struct Copilot {
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: NodeRuntime,
|
||||||
server: CopilotServer,
|
server: CopilotServer,
|
||||||
buffers: HashSet<WeakModel<Buffer>>,
|
buffers: HashSet<WeakModel<Buffer>>,
|
||||||
server_id: LanguageServerId,
|
server_id: LanguageServerId,
|
||||||
|
@ -334,7 +334,7 @@ impl Copilot {
|
||||||
fn start(
|
fn start(
|
||||||
new_server_id: LanguageServerId,
|
new_server_id: LanguageServerId,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: NodeRuntime,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
|
@ -392,7 +392,7 @@ impl Copilot {
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn fake(cx: &mut gpui::TestAppContext) -> (Model<Self>, lsp::FakeLanguageServer) {
|
pub fn fake(cx: &mut gpui::TestAppContext) -> (Model<Self>, lsp::FakeLanguageServer) {
|
||||||
use lsp::FakeLanguageServer;
|
use lsp::FakeLanguageServer;
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
|
|
||||||
let (server, fake_server) = FakeLanguageServer::new(
|
let (server, fake_server) = FakeLanguageServer::new(
|
||||||
LanguageServerId(0),
|
LanguageServerId(0),
|
||||||
|
@ -406,7 +406,7 @@ impl Copilot {
|
||||||
cx.to_async(),
|
cx.to_async(),
|
||||||
);
|
);
|
||||||
let http = http_client::FakeHttpClient::create(|_| async { unreachable!() });
|
let http = http_client::FakeHttpClient::create(|_| async { unreachable!() });
|
||||||
let node_runtime = FakeNodeRuntime::new();
|
let node_runtime = NodeRuntime::unavailable();
|
||||||
let this = cx.new_model(|cx| Self {
|
let this = cx.new_model(|cx| Self {
|
||||||
server_id: LanguageServerId(0),
|
server_id: LanguageServerId(0),
|
||||||
http: http.clone(),
|
http: http.clone(),
|
||||||
|
@ -425,7 +425,7 @@ impl Copilot {
|
||||||
async fn start_language_server(
|
async fn start_language_server(
|
||||||
new_server_id: LanguageServerId,
|
new_server_id: LanguageServerId,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: NodeRuntime,
|
||||||
this: WeakModel<Self>,
|
this: WeakModel<Self>,
|
||||||
mut cx: AsyncAppContext,
|
mut cx: AsyncAppContext,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use git::GitHostingProviderRegistry;
|
||||||
use gpui::{AsyncAppContext, BackgroundExecutor, Context, Model};
|
use gpui::{AsyncAppContext, BackgroundExecutor, Context, Model};
|
||||||
use http_client::{HttpClient, Method};
|
use http_client::{HttpClient, Method};
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use open_ai::OpenAiEmbeddingModel;
|
use open_ai::OpenAiEmbeddingModel;
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use semantic_index::{
|
use semantic_index::{
|
||||||
|
@ -292,7 +292,7 @@ async fn run_evaluation(
|
||||||
let user_store = cx
|
let user_store = cx
|
||||||
.new_model(|cx| UserStore::new(client.clone(), cx))
|
.new_model(|cx| UserStore::new(client.clone(), cx))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let node_runtime = Arc::new(FakeNodeRuntime {});
|
let node_runtime = NodeRuntime::unavailable();
|
||||||
|
|
||||||
let evaluations = fs::read(&evaluations_path).expect("failed to read evaluations.json");
|
let evaluations = fs::read(&evaluations_path).expect("failed to read evaluations.json");
|
||||||
let evaluations: Vec<EvaluationProject> = serde_json::from_slice(&evaluations).unwrap();
|
let evaluations: Vec<EvaluationProject> = serde_json::from_slice(&evaluations).unwrap();
|
||||||
|
|
|
@ -177,7 +177,7 @@ actions!(zed, [ReloadExtensions]);
|
||||||
pub fn init(
|
pub fn init(
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: NodeRuntime,
|
||||||
language_registry: Arc<LanguageRegistry>,
|
language_registry: Arc<LanguageRegistry>,
|
||||||
theme_registry: Arc<ThemeRegistry>,
|
theme_registry: Arc<ThemeRegistry>,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
|
@ -228,7 +228,7 @@ impl ExtensionStore {
|
||||||
http_client: Arc<HttpClientWithUrl>,
|
http_client: Arc<HttpClientWithUrl>,
|
||||||
builder_client: Arc<dyn HttpClient>,
|
builder_client: Arc<dyn HttpClient>,
|
||||||
telemetry: Option<Arc<Telemetry>>,
|
telemetry: Option<Arc<Telemetry>>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: NodeRuntime,
|
||||||
language_registry: Arc<LanguageRegistry>,
|
language_registry: Arc<LanguageRegistry>,
|
||||||
theme_registry: Arc<ThemeRegistry>,
|
theme_registry: Arc<ThemeRegistry>,
|
||||||
slash_command_registry: Arc<SlashCommandRegistry>,
|
slash_command_registry: Arc<SlashCommandRegistry>,
|
||||||
|
|
|
@ -15,7 +15,7 @@ use http_client::{FakeHttpClient, Response};
|
||||||
use indexed_docs::IndexedDocsRegistry;
|
use indexed_docs::IndexedDocsRegistry;
|
||||||
use isahc_http_client::IsahcHttpClient;
|
use isahc_http_client::IsahcHttpClient;
|
||||||
use language::{LanguageMatcher, LanguageRegistry, LanguageServerBinaryStatus, LanguageServerName};
|
use language::{LanguageMatcher, LanguageRegistry, LanguageServerBinaryStatus, LanguageServerName};
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use project::{Project, DEFAULT_COMPLETION_CONTEXT};
|
use project::{Project, DEFAULT_COMPLETION_CONTEXT};
|
||||||
use release_channel::AppVersion;
|
use release_channel::AppVersion;
|
||||||
|
@ -264,7 +264,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
|
||||||
let slash_command_registry = SlashCommandRegistry::new();
|
let slash_command_registry = SlashCommandRegistry::new();
|
||||||
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
|
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
|
||||||
let snippet_registry = Arc::new(SnippetRegistry::new());
|
let snippet_registry = Arc::new(SnippetRegistry::new());
|
||||||
let node_runtime = FakeNodeRuntime::new();
|
let node_runtime = NodeRuntime::unavailable();
|
||||||
|
|
||||||
let store = cx.new_model(|cx| {
|
let store = cx.new_model(|cx| {
|
||||||
ExtensionStore::new(
|
ExtensionStore::new(
|
||||||
|
@ -490,7 +490,7 @@ async fn test_extension_store_with_test_extension(cx: &mut TestAppContext) {
|
||||||
let slash_command_registry = SlashCommandRegistry::new();
|
let slash_command_registry = SlashCommandRegistry::new();
|
||||||
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
|
let indexed_docs_registry = Arc::new(IndexedDocsRegistry::new(cx.executor()));
|
||||||
let snippet_registry = Arc::new(SnippetRegistry::new());
|
let snippet_registry = Arc::new(SnippetRegistry::new());
|
||||||
let node_runtime = FakeNodeRuntime::new();
|
let node_runtime = NodeRuntime::unavailable();
|
||||||
|
|
||||||
let mut status_updates = language_registry.language_server_binary_statuses();
|
let mut status_updates = language_registry.language_server_binary_statuses();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub(crate) struct WasmHost {
|
||||||
engine: Engine,
|
engine: Engine,
|
||||||
release_channel: ReleaseChannel,
|
release_channel: ReleaseChannel,
|
||||||
http_client: Arc<dyn HttpClient>,
|
http_client: Arc<dyn HttpClient>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: NodeRuntime,
|
||||||
pub(crate) language_registry: Arc<LanguageRegistry>,
|
pub(crate) language_registry: Arc<LanguageRegistry>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
pub(crate) work_dir: PathBuf,
|
pub(crate) work_dir: PathBuf,
|
||||||
|
@ -80,7 +80,7 @@ impl WasmHost {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
http_client: Arc<dyn HttpClient>,
|
http_client: Arc<dyn HttpClient>,
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
node_runtime: NodeRuntime,
|
||||||
language_registry: Arc<LanguageRegistry>,
|
language_registry: Arc<LanguageRegistry>,
|
||||||
work_dir: PathBuf,
|
work_dir: PathBuf,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub struct DevServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub node_runtime: Arc<dyn NodeRuntime>,
|
pub node_runtime: NodeRuntime,
|
||||||
pub user_store: Model<UserStore>,
|
pub user_store: Model<UserStore>,
|
||||||
pub languages: Arc<LanguageRegistry>,
|
pub languages: Arc<LanguageRegistry>,
|
||||||
pub fs: Arc<dyn Fs>,
|
pub fs: Arc<dyn Fs>,
|
||||||
|
|
|
@ -264,6 +264,35 @@ pub fn read_proxy_from_env() -> Option<Uri> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct BlockedHttpClient;
|
||||||
|
|
||||||
|
impl HttpClient for BlockedHttpClient {
|
||||||
|
fn send(
|
||||||
|
&self,
|
||||||
|
_req: Request<AsyncBody>,
|
||||||
|
) -> BoxFuture<'static, Result<Response<AsyncBody>, anyhow::Error>> {
|
||||||
|
Box::pin(async {
|
||||||
|
Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::PermissionDenied,
|
||||||
|
"BlockedHttpClient disallowed request",
|
||||||
|
)
|
||||||
|
.into())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn proxy(&self) -> Option<&Uri> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_with_redirect_policy(
|
||||||
|
&self,
|
||||||
|
req: Request<AsyncBody>,
|
||||||
|
_: bool,
|
||||||
|
) -> BoxFuture<'static, Result<Response<AsyncBody>, anyhow::Error>> {
|
||||||
|
self.send(req)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "test-support")]
|
#[cfg(feature = "test-support")]
|
||||||
type FakeHttpHandler = Box<
|
type FakeHttpHandler = Box<
|
||||||
dyn Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, anyhow::Error>>
|
dyn Fn(Request<AsyncBody>) -> BoxFuture<'static, Result<Response<AsyncBody>, anyhow::Error>>
|
||||||
|
|
|
@ -564,6 +564,7 @@ async fn try_fetch_server_binary<L: LspAdapter + 'static + Send + Sync + ?Sized>
|
||||||
let name = adapter.name();
|
let name = adapter.name();
|
||||||
log::info!("fetching latest version of language server {:?}", name.0);
|
log::info!("fetching latest version of language server {:?}", name.0);
|
||||||
delegate.update_status(name.clone(), LanguageServerBinaryStatus::CheckingForUpdate);
|
delegate.update_status(name.clone(), LanguageServerBinaryStatus::CheckingForUpdate);
|
||||||
|
|
||||||
let latest_version = adapter
|
let latest_version = adapter
|
||||||
.fetch_latest_server_version(delegate.as_ref())
|
.fetch_latest_server_version(delegate.as_ref())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -22,11 +22,11 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CssLspAdapter {
|
pub struct CssLspAdapter {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CssLspAdapter {
|
impl CssLspAdapter {
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
pub fn new(node: NodeRuntime) -> Self {
|
||||||
CssLspAdapter { node }
|
CssLspAdapter { node }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,14 +81,14 @@ impl LspAdapter for CssLspAdapter {
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
_: &dyn LspAdapterDelegate,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn installation_test_binary(
|
async fn installation_test_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn initialization_options(
|
async fn initialization_options(
|
||||||
|
@ -103,7 +103,7 @@ impl LspAdapter for CssLspAdapter {
|
||||||
|
|
||||||
async fn get_cached_server_binary(
|
async fn get_cached_server_binary(
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
node: &dyn NodeRuntime,
|
node: &NodeRuntime,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
maybe!(async {
|
maybe!(async {
|
||||||
let mut last_version_dir = None;
|
let mut last_version_dir = None;
|
||||||
|
|
|
@ -59,13 +59,13 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct JsonLspAdapter {
|
pub struct JsonLspAdapter {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
workspace_config: OnceLock<Value>,
|
workspace_config: OnceLock<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JsonLspAdapter {
|
impl JsonLspAdapter {
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>, languages: Arc<LanguageRegistry>) -> Self {
|
pub fn new(node: NodeRuntime, languages: Arc<LanguageRegistry>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
node,
|
node,
|
||||||
languages,
|
languages,
|
||||||
|
@ -183,14 +183,14 @@ impl LspAdapter for JsonLspAdapter {
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
_: &dyn LspAdapterDelegate,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn installation_test_binary(
|
async fn installation_test_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn initialization_options(
|
async fn initialization_options(
|
||||||
|
@ -226,7 +226,7 @@ impl LspAdapter for JsonLspAdapter {
|
||||||
|
|
||||||
async fn get_cached_server_binary(
|
async fn get_cached_server_binary(
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
node: &dyn NodeRuntime,
|
node: &NodeRuntime,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
maybe!(async {
|
maybe!(async {
|
||||||
let mut last_version_dir = None;
|
let mut last_version_dir = None;
|
||||||
|
|
|
@ -30,11 +30,7 @@ mod yaml;
|
||||||
#[exclude = "*.rs"]
|
#[exclude = "*.rs"]
|
||||||
struct LanguageDir;
|
struct LanguageDir;
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(languages: Arc<LanguageRegistry>, node_runtime: NodeRuntime, cx: &mut AppContext) {
|
||||||
languages: Arc<LanguageRegistry>,
|
|
||||||
node_runtime: Arc<dyn NodeRuntime>,
|
|
||||||
cx: &mut AppContext,
|
|
||||||
) {
|
|
||||||
languages.register_native_grammars([
|
languages.register_native_grammars([
|
||||||
("bash", tree_sitter_bash::LANGUAGE),
|
("bash", tree_sitter_bash::LANGUAGE),
|
||||||
("c", tree_sitter_c::LANGUAGE),
|
("c", tree_sitter_c::LANGUAGE),
|
||||||
|
|
|
@ -26,13 +26,13 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PythonLspAdapter {
|
pub struct PythonLspAdapter {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PythonLspAdapter {
|
impl PythonLspAdapter {
|
||||||
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("pyright");
|
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("pyright");
|
||||||
|
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
pub fn new(node: NodeRuntime) -> Self {
|
||||||
PythonLspAdapter { node }
|
PythonLspAdapter { node }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,14 +94,14 @@ impl LspAdapter for PythonLspAdapter {
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
_: &dyn LspAdapterDelegate,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn installation_test_binary(
|
async fn installation_test_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_completions(&self, items: &mut [lsp::CompletionItem]) {
|
async fn process_completions(&self, items: &mut [lsp::CompletionItem]) {
|
||||||
|
@ -198,7 +198,7 @@ impl LspAdapter for PythonLspAdapter {
|
||||||
|
|
||||||
async fn get_cached_server_binary(
|
async fn get_cached_server_binary(
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
node: &dyn NodeRuntime,
|
node: &NodeRuntime,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
let server_path = container_dir.join(SERVER_PATH);
|
let server_path = container_dir.join(SERVER_PATH);
|
||||||
if server_path.exists() {
|
if server_path.exists() {
|
||||||
|
|
|
@ -28,14 +28,14 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TailwindLspAdapter {
|
pub struct TailwindLspAdapter {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TailwindLspAdapter {
|
impl TailwindLspAdapter {
|
||||||
const SERVER_NAME: LanguageServerName =
|
const SERVER_NAME: LanguageServerName =
|
||||||
LanguageServerName::new_static("tailwindcss-language-server");
|
LanguageServerName::new_static("tailwindcss-language-server");
|
||||||
|
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
pub fn new(node: NodeRuntime) -> Self {
|
||||||
TailwindLspAdapter { node }
|
TailwindLspAdapter { node }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,14 +122,14 @@ impl LspAdapter for TailwindLspAdapter {
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
_: &dyn LspAdapterDelegate,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn installation_test_binary(
|
async fn installation_test_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn initialization_options(
|
async fn initialization_options(
|
||||||
|
@ -198,7 +198,7 @@ impl LspAdapter for TailwindLspAdapter {
|
||||||
|
|
||||||
async fn get_cached_server_binary(
|
async fn get_cached_server_binary(
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
node: &dyn NodeRuntime,
|
node: &NodeRuntime,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
maybe!(async {
|
maybe!(async {
|
||||||
let mut last_version_dir = None;
|
let mut last_version_dir = None;
|
||||||
|
|
|
@ -65,7 +65,7 @@ fn eslint_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TypeScriptLspAdapter {
|
pub struct TypeScriptLspAdapter {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeScriptLspAdapter {
|
impl TypeScriptLspAdapter {
|
||||||
|
@ -73,7 +73,7 @@ impl TypeScriptLspAdapter {
|
||||||
const NEW_SERVER_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.mjs";
|
const NEW_SERVER_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.mjs";
|
||||||
const SERVER_NAME: LanguageServerName =
|
const SERVER_NAME: LanguageServerName =
|
||||||
LanguageServerName::new_static("typescript-language-server");
|
LanguageServerName::new_static("typescript-language-server");
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
pub fn new(node: NodeRuntime) -> Self {
|
||||||
TypeScriptLspAdapter { node }
|
TypeScriptLspAdapter { node }
|
||||||
}
|
}
|
||||||
async fn tsdk_path(adapter: &Arc<dyn LspAdapterDelegate>) -> &'static str {
|
async fn tsdk_path(adapter: &Arc<dyn LspAdapterDelegate>) -> &'static str {
|
||||||
|
@ -161,14 +161,14 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
_: &dyn LspAdapterDelegate,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_ts_server_binary(container_dir, &*self.node).await
|
get_cached_ts_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn installation_test_binary(
|
async fn installation_test_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_ts_server_binary(container_dir, &*self.node).await
|
get_cached_ts_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
|
fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
|
||||||
|
@ -264,7 +264,7 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||||
|
|
||||||
async fn get_cached_ts_server_binary(
|
async fn get_cached_ts_server_binary(
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
node: &dyn NodeRuntime,
|
node: &NodeRuntime,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
maybe!(async {
|
maybe!(async {
|
||||||
let old_server_path = container_dir.join(TypeScriptLspAdapter::OLD_SERVER_PATH);
|
let old_server_path = container_dir.join(TypeScriptLspAdapter::OLD_SERVER_PATH);
|
||||||
|
@ -293,7 +293,7 @@ async fn get_cached_ts_server_binary(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EsLintLspAdapter {
|
pub struct EsLintLspAdapter {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EsLintLspAdapter {
|
impl EsLintLspAdapter {
|
||||||
|
@ -310,7 +310,7 @@ impl EsLintLspAdapter {
|
||||||
const FLAT_CONFIG_FILE_NAMES: &'static [&'static str] =
|
const FLAT_CONFIG_FILE_NAMES: &'static [&'static str] =
|
||||||
&["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs"];
|
&["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs"];
|
||||||
|
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
pub fn new(node: NodeRuntime) -> Self {
|
||||||
EsLintLspAdapter { node }
|
EsLintLspAdapter { node }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,11 +476,11 @@ impl LspAdapter for EsLintLspAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.node
|
self.node
|
||||||
.run_npm_subcommand(Some(&repo_root), "install", &[])
|
.run_npm_subcommand(&repo_root, "install", &[])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.node
|
self.node
|
||||||
.run_npm_subcommand(Some(&repo_root), "run-script", &["compile"])
|
.run_npm_subcommand(&repo_root, "run-script", &["compile"])
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,20 +496,20 @@ impl LspAdapter for EsLintLspAdapter {
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
_: &dyn LspAdapterDelegate,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_eslint_server_binary(container_dir, &*self.node).await
|
get_cached_eslint_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn installation_test_binary(
|
async fn installation_test_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_eslint_server_binary(container_dir, &*self.node).await
|
get_cached_eslint_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_cached_eslint_server_binary(
|
async fn get_cached_eslint_server_binary(
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
node: &dyn NodeRuntime,
|
node: &NodeRuntime,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
maybe!(async {
|
maybe!(async {
|
||||||
// This is unfortunate but we don't know what the version is to build a path directly
|
// This is unfortunate but we don't know what the version is to build a path directly
|
||||||
|
|
|
@ -20,13 +20,13 @@ fn typescript_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct VtslsLspAdapter {
|
pub struct VtslsLspAdapter {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VtslsLspAdapter {
|
impl VtslsLspAdapter {
|
||||||
const SERVER_PATH: &'static str = "node_modules/@vtsls/language-server/bin/vtsls.js";
|
const SERVER_PATH: &'static str = "node_modules/@vtsls/language-server/bin/vtsls.js";
|
||||||
|
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
pub fn new(node: NodeRuntime) -> Self {
|
||||||
VtslsLspAdapter { node }
|
VtslsLspAdapter { node }
|
||||||
}
|
}
|
||||||
async fn tsdk_path(adapter: &Arc<dyn LspAdapterDelegate>) -> &'static str {
|
async fn tsdk_path(adapter: &Arc<dyn LspAdapterDelegate>) -> &'static str {
|
||||||
|
@ -154,14 +154,14 @@ impl LspAdapter for VtslsLspAdapter {
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
_: &dyn LspAdapterDelegate,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_ts_server_binary(container_dir, &*self.node).await
|
get_cached_ts_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn installation_test_binary(
|
async fn installation_test_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_ts_server_binary(container_dir, &*self.node).await
|
get_cached_ts_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
|
fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
|
||||||
|
@ -298,7 +298,7 @@ impl LspAdapter for VtslsLspAdapter {
|
||||||
|
|
||||||
async fn get_cached_ts_server_binary(
|
async fn get_cached_ts_server_binary(
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
node: &dyn NodeRuntime,
|
node: &NodeRuntime,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
maybe!(async {
|
maybe!(async {
|
||||||
let server_path = container_dir.join(VtslsLspAdapter::SERVER_PATH);
|
let server_path = container_dir.join(VtslsLspAdapter::SERVER_PATH);
|
||||||
|
|
|
@ -26,12 +26,12 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct YamlLspAdapter {
|
pub struct YamlLspAdapter {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl YamlLspAdapter {
|
impl YamlLspAdapter {
|
||||||
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("yaml-language-server");
|
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("yaml-language-server");
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
pub fn new(node: NodeRuntime) -> Self {
|
||||||
YamlLspAdapter { node }
|
YamlLspAdapter { node }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,14 +117,14 @@ impl LspAdapter for YamlLspAdapter {
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
_: &dyn LspAdapterDelegate,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn installation_test_binary(
|
async fn installation_test_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
get_cached_server_binary(container_dir, &self.node).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn workspace_configuration(
|
async fn workspace_configuration(
|
||||||
|
@ -157,7 +157,7 @@ impl LspAdapter for YamlLspAdapter {
|
||||||
|
|
||||||
async fn get_cached_server_binary(
|
async fn get_cached_server_binary(
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
node: &dyn NodeRuntime,
|
node: &NodeRuntime,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
maybe!(async {
|
maybe!(async {
|
||||||
let mut last_version_dir = None;
|
let mut last_version_dir = None;
|
||||||
|
|
|
@ -2,7 +2,7 @@ use assets::Assets;
|
||||||
use gpui::{prelude::*, rgb, App, KeyBinding, StyleRefinement, View, WindowOptions};
|
use gpui::{prelude::*, rgb, App, KeyBinding, StyleRefinement, View, WindowOptions};
|
||||||
use language::{language_settings::AllLanguageSettings, LanguageRegistry};
|
use language::{language_settings::AllLanguageSettings, LanguageRegistry};
|
||||||
use markdown::{Markdown, MarkdownStyle};
|
use markdown::{Markdown, MarkdownStyle};
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use theme::LoadThemes;
|
use theme::LoadThemes;
|
||||||
|
@ -102,7 +102,7 @@ pub fn main() {
|
||||||
});
|
});
|
||||||
cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]);
|
cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]);
|
||||||
|
|
||||||
let node_runtime = FakeNodeRuntime::new();
|
let node_runtime = NodeRuntime::unavailable();
|
||||||
theme::init(LoadThemes::JustBase, cx);
|
theme::init(LoadThemes::JustBase, cx);
|
||||||
|
|
||||||
let language_registry = LanguageRegistry::new(cx.background_executor().clone());
|
let language_registry = LanguageRegistry::new(cx.background_executor().clone());
|
||||||
|
|
|
@ -2,7 +2,7 @@ use assets::Assets;
|
||||||
use gpui::*;
|
use gpui::*;
|
||||||
use language::{language_settings::AllLanguageSettings, LanguageRegistry};
|
use language::{language_settings::AllLanguageSettings, LanguageRegistry};
|
||||||
use markdown::{Markdown, MarkdownStyle};
|
use markdown::{Markdown, MarkdownStyle};
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use theme::LoadThemes;
|
use theme::LoadThemes;
|
||||||
|
@ -28,7 +28,7 @@ pub fn main() {
|
||||||
});
|
});
|
||||||
cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]);
|
cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]);
|
||||||
|
|
||||||
let node_runtime = FakeNodeRuntime::new();
|
let node_runtime = NodeRuntime::unavailable();
|
||||||
let language_registry = Arc::new(LanguageRegistry::new(cx.background_executor().clone()));
|
let language_registry = Arc::new(LanguageRegistry::new(cx.background_executor().clone()));
|
||||||
languages::init(language_registry.clone(), node_runtime, cx);
|
languages::init(language_registry.clone(), node_runtime, cx);
|
||||||
theme::init(LoadThemes::JustBase, cx);
|
theme::init(LoadThemes::JustBase, cx);
|
||||||
|
|
|
@ -18,6 +18,7 @@ test-support = ["tempfile"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
async-compression.workspace = true
|
async-compression.workspace = true
|
||||||
|
async-watch.workspace = true
|
||||||
async-tar.workspace = true
|
async-tar.workspace = true
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
async_zip.workspace = true
|
async_zip.workspace = true
|
||||||
|
@ -32,6 +33,7 @@ smol.workspace = true
|
||||||
tempfile = { workspace = true, optional = true }
|
tempfile = { workspace = true, optional = true }
|
||||||
util.workspace = true
|
util.workspace = true
|
||||||
walkdir = "2.5.0"
|
walkdir = "2.5.0"
|
||||||
|
which.workspace = true
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
async-std = { version = "1.12.0", features = ["unstable"] }
|
async-std = { version = "1.12.0", features = ["unstable"] }
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub use archive::extract_zip;
|
||||||
use async_compression::futures::bufread::GzipDecoder;
|
use async_compression::futures::bufread::GzipDecoder;
|
||||||
use async_tar::Archive;
|
use async_tar::Archive;
|
||||||
use futures::AsyncReadExt;
|
use futures::AsyncReadExt;
|
||||||
use http_client::HttpClient;
|
use http_client::{HttpClient, Uri};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use smol::io::BufReader;
|
use smol::io::BufReader;
|
||||||
|
@ -23,60 +23,166 @@ use util::ResultExt;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use smol::process::windows::CommandExt;
|
use smol::process::windows::CommandExt;
|
||||||
|
|
||||||
const VERSION: &str = "v22.5.1";
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||||
|
pub struct NodeBinaryOptions {
|
||||||
#[cfg(not(windows))]
|
pub allow_path_lookup: bool,
|
||||||
const NODE_PATH: &str = "bin/node";
|
pub allow_binary_download: bool,
|
||||||
#[cfg(windows)]
|
pub use_paths: Option<(PathBuf, PathBuf)>,
|
||||||
const NODE_PATH: &str = "node.exe";
|
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
const NPM_PATH: &str = "bin/npm";
|
|
||||||
#[cfg(windows)]
|
|
||||||
const NPM_PATH: &str = "node_modules/npm/bin/npm-cli.js";
|
|
||||||
|
|
||||||
enum ArchiveType {
|
|
||||||
TarGz,
|
|
||||||
Zip,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Clone)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
pub struct NodeRuntime(Arc<Mutex<NodeRuntimeState>>);
|
||||||
pub struct NpmInfo {
|
|
||||||
#[serde(default)]
|
struct NodeRuntimeState {
|
||||||
dist_tags: NpmInfoDistTags,
|
http: Arc<dyn HttpClient>,
|
||||||
versions: Vec<String>,
|
instance: Option<Box<dyn NodeRuntimeTrait>>,
|
||||||
|
last_options: Option<NodeBinaryOptions>,
|
||||||
|
options: async_watch::Receiver<Option<NodeBinaryOptions>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Default)]
|
impl NodeRuntime {
|
||||||
pub struct NpmInfoDistTags {
|
pub fn new(
|
||||||
latest: Option<String>,
|
http: Arc<dyn HttpClient>,
|
||||||
}
|
options: async_watch::Receiver<Option<NodeBinaryOptions>>,
|
||||||
|
) -> Self {
|
||||||
|
NodeRuntime(Arc::new(Mutex::new(NodeRuntimeState {
|
||||||
|
http,
|
||||||
|
instance: None,
|
||||||
|
last_options: None,
|
||||||
|
options,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
pub fn unavailable() -> Self {
|
||||||
pub trait NodeRuntime: Send + Sync {
|
NodeRuntime(Arc::new(Mutex::new(NodeRuntimeState {
|
||||||
async fn binary_path(&self) -> Result<PathBuf>;
|
http: Arc::new(http_client::BlockedHttpClient),
|
||||||
async fn node_environment_path(&self) -> Result<OsString>;
|
instance: None,
|
||||||
|
last_options: None,
|
||||||
|
options: async_watch::channel(Some(NodeBinaryOptions::default())).1,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
async fn run_npm_subcommand(
|
async fn instance(&self) -> Result<Box<dyn NodeRuntimeTrait>> {
|
||||||
|
let mut state = self.0.lock().await;
|
||||||
|
|
||||||
|
while state.options.borrow().is_none() {
|
||||||
|
state.options.changed().await?;
|
||||||
|
}
|
||||||
|
let options = state.options.borrow().clone().unwrap();
|
||||||
|
if state.last_options.as_ref() != Some(&options) {
|
||||||
|
state.instance.take();
|
||||||
|
}
|
||||||
|
if let Some(instance) = state.instance.as_ref() {
|
||||||
|
return Ok(instance.boxed_clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some((node, npm)) = options.use_paths.as_ref() {
|
||||||
|
let instance = SystemNodeRuntime::new(node.clone(), npm.clone()).await?;
|
||||||
|
state.instance = Some(instance.boxed_clone());
|
||||||
|
return Ok(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.allow_path_lookup {
|
||||||
|
if let Some(instance) = SystemNodeRuntime::detect().await {
|
||||||
|
state.instance = Some(instance.boxed_clone());
|
||||||
|
return Ok(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let instance = if options.allow_binary_download {
|
||||||
|
ManagedNodeRuntime::install_if_needed(&state.http).await?
|
||||||
|
} else {
|
||||||
|
Box::new(UnavailableNodeRuntime)
|
||||||
|
};
|
||||||
|
|
||||||
|
state.instance = Some(instance.boxed_clone());
|
||||||
|
return Ok(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn binary_path(&self) -> Result<PathBuf> {
|
||||||
|
self.instance().await?.binary_path()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run_npm_subcommand(
|
||||||
&self,
|
&self,
|
||||||
directory: Option<&Path>,
|
directory: &Path,
|
||||||
subcommand: &str,
|
subcommand: &str,
|
||||||
args: &[&str],
|
args: &[&str],
|
||||||
) -> Result<Output>;
|
) -> Result<Output> {
|
||||||
|
let http = self.0.lock().await.http.clone();
|
||||||
|
self.instance()
|
||||||
|
.await?
|
||||||
|
.run_npm_subcommand(Some(directory), http.proxy(), subcommand, args)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn npm_package_latest_version(&self, name: &str) -> Result<String>;
|
pub async fn npm_package_installed_version(
|
||||||
|
|
||||||
async fn npm_install_packages(&self, directory: &Path, packages: &[(&str, &str)])
|
|
||||||
-> Result<()>;
|
|
||||||
|
|
||||||
async fn npm_package_installed_version(
|
|
||||||
&self,
|
&self,
|
||||||
local_package_directory: &Path,
|
local_package_directory: &Path,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Result<Option<String>>;
|
) -> Result<Option<String>> {
|
||||||
|
self.instance()
|
||||||
|
.await?
|
||||||
|
.npm_package_installed_version(local_package_directory, name)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn should_install_npm_package(
|
pub async fn npm_package_latest_version(&self, name: &str) -> Result<String> {
|
||||||
|
let http = self.0.lock().await.http.clone();
|
||||||
|
let output = self
|
||||||
|
.instance()
|
||||||
|
.await?
|
||||||
|
.run_npm_subcommand(
|
||||||
|
None,
|
||||||
|
http.proxy(),
|
||||||
|
"info",
|
||||||
|
&[
|
||||||
|
name,
|
||||||
|
"--json",
|
||||||
|
"--fetch-retry-mintimeout",
|
||||||
|
"2000",
|
||||||
|
"--fetch-retry-maxtimeout",
|
||||||
|
"5000",
|
||||||
|
"--fetch-timeout",
|
||||||
|
"5000",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut info: NpmInfo = serde_json::from_slice(&output.stdout)?;
|
||||||
|
info.dist_tags
|
||||||
|
.latest
|
||||||
|
.or_else(|| info.versions.pop())
|
||||||
|
.ok_or_else(|| anyhow!("no version found for npm package {}", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn npm_install_packages(
|
||||||
|
&self,
|
||||||
|
directory: &Path,
|
||||||
|
packages: &[(&str, &str)],
|
||||||
|
) -> Result<()> {
|
||||||
|
let packages: Vec<_> = packages
|
||||||
|
.iter()
|
||||||
|
.map(|(name, version)| format!("{name}@{version}"))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut arguments: Vec<_> = packages.iter().map(|p| p.as_str()).collect();
|
||||||
|
arguments.extend_from_slice(&[
|
||||||
|
"--save-exact",
|
||||||
|
"--fetch-retry-mintimeout",
|
||||||
|
"2000",
|
||||||
|
"--fetch-retry-maxtimeout",
|
||||||
|
"5000",
|
||||||
|
"--fetch-timeout",
|
||||||
|
"5000",
|
||||||
|
]);
|
||||||
|
|
||||||
|
self.run_npm_subcommand(directory, "install", &arguments)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn should_install_npm_package(
|
||||||
&self,
|
&self,
|
||||||
package_name: &str,
|
package_name: &str,
|
||||||
local_executable_path: &Path,
|
local_executable_path: &Path,
|
||||||
|
@ -110,21 +216,78 @@ pub trait NodeRuntime: Send + Sync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RealNodeRuntime {
|
enum ArchiveType {
|
||||||
http: Arc<dyn HttpClient>,
|
TarGz,
|
||||||
installation_lock: Mutex<()>,
|
Zip,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RealNodeRuntime {
|
#[derive(Debug, Deserialize)]
|
||||||
pub fn new(http: Arc<dyn HttpClient>) -> Arc<dyn NodeRuntime> {
|
#[serde(rename_all = "kebab-case")]
|
||||||
Arc::new(RealNodeRuntime {
|
pub struct NpmInfo {
|
||||||
http,
|
#[serde(default)]
|
||||||
installation_lock: Mutex::new(()),
|
dist_tags: NpmInfoDistTags,
|
||||||
})
|
versions: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Default)]
|
||||||
|
pub struct NpmInfoDistTags {
|
||||||
|
latest: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
trait NodeRuntimeTrait: Send + Sync {
|
||||||
|
fn boxed_clone(&self) -> Box<dyn NodeRuntimeTrait>;
|
||||||
|
fn binary_path(&self) -> Result<PathBuf>;
|
||||||
|
|
||||||
|
async fn run_npm_subcommand(
|
||||||
|
&self,
|
||||||
|
directory: Option<&Path>,
|
||||||
|
proxy: Option<&Uri>,
|
||||||
|
subcommand: &str,
|
||||||
|
args: &[&str],
|
||||||
|
) -> Result<Output>;
|
||||||
|
|
||||||
|
async fn npm_package_installed_version(
|
||||||
|
&self,
|
||||||
|
local_package_directory: &Path,
|
||||||
|
name: &str,
|
||||||
|
) -> Result<Option<String>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct ManagedNodeRuntime {
|
||||||
|
installation_path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ManagedNodeRuntime {
|
||||||
|
const VERSION: &str = "v22.5.1";
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
const NODE_PATH: &str = "bin/node";
|
||||||
|
#[cfg(windows)]
|
||||||
|
const NODE_PATH: &str = "node.exe";
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
const NPM_PATH: &str = "bin/npm";
|
||||||
|
#[cfg(windows)]
|
||||||
|
const NPM_PATH: &str = "node_modules/npm/bin/npm-cli.js";
|
||||||
|
|
||||||
|
async fn node_environment_path(&self) -> Result<OsString> {
|
||||||
|
let node_binary = self.installation_path.join(Self::NODE_PATH);
|
||||||
|
let mut env_path = vec![node_binary
|
||||||
|
.parent()
|
||||||
|
.expect("invalid node binary path")
|
||||||
|
.to_path_buf()];
|
||||||
|
|
||||||
|
if let Some(existing_path) = std::env::var_os("PATH") {
|
||||||
|
let mut paths = std::env::split_paths(&existing_path).collect::<Vec<_>>();
|
||||||
|
env_path.append(&mut paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::env::join_paths(env_path).context("failed to create PATH env variable")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn install_if_needed(&self) -> Result<PathBuf> {
|
async fn install_if_needed(http: &Arc<dyn HttpClient>) -> Result<Box<dyn NodeRuntimeTrait>> {
|
||||||
let _lock = self.installation_lock.lock().await;
|
|
||||||
log::info!("Node runtime install_if_needed");
|
log::info!("Node runtime install_if_needed");
|
||||||
|
|
||||||
let os = match consts::OS {
|
let os = match consts::OS {
|
||||||
|
@ -140,11 +303,12 @@ impl RealNodeRuntime {
|
||||||
other => bail!("Running on unsupported architecture: {other}"),
|
other => bail!("Running on unsupported architecture: {other}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let folder_name = format!("node-{VERSION}-{os}-{arch}");
|
let version = Self::VERSION;
|
||||||
|
let folder_name = format!("node-{version}-{os}-{arch}");
|
||||||
let node_containing_dir = paths::support_dir().join("node");
|
let node_containing_dir = paths::support_dir().join("node");
|
||||||
let node_dir = node_containing_dir.join(folder_name);
|
let node_dir = node_containing_dir.join(folder_name);
|
||||||
let node_binary = node_dir.join(NODE_PATH);
|
let node_binary = node_dir.join(Self::NODE_PATH);
|
||||||
let npm_file = node_dir.join(NPM_PATH);
|
let npm_file = node_dir.join(Self::NPM_PATH);
|
||||||
|
|
||||||
let mut command = Command::new(&node_binary);
|
let mut command = Command::new(&node_binary);
|
||||||
|
|
||||||
|
@ -177,16 +341,16 @@ impl RealNodeRuntime {
|
||||||
other => bail!("Running on unsupported os: {other}"),
|
other => bail!("Running on unsupported os: {other}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let version = Self::VERSION;
|
||||||
let file_name = format!(
|
let file_name = format!(
|
||||||
"node-{VERSION}-{os}-{arch}.{extension}",
|
"node-{version}-{os}-{arch}.{extension}",
|
||||||
extension = match archive_type {
|
extension = match archive_type {
|
||||||
ArchiveType::TarGz => "tar.gz",
|
ArchiveType::TarGz => "tar.gz",
|
||||||
ArchiveType::Zip => "zip",
|
ArchiveType::Zip => "zip",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
let url = format!("https://nodejs.org/dist/{VERSION}/{file_name}");
|
let url = format!("https://nodejs.org/dist/{version}/{file_name}");
|
||||||
let mut response = self
|
let mut response = http
|
||||||
.http
|
|
||||||
.get(&url, Default::default(), true)
|
.get(&url, Default::default(), true)
|
||||||
.await
|
.await
|
||||||
.context("error downloading Node binary tarball")?;
|
.context("error downloading Node binary tarball")?;
|
||||||
|
@ -207,43 +371,32 @@ impl RealNodeRuntime {
|
||||||
_ = fs::write(node_dir.join("blank_user_npmrc"), []).await;
|
_ = fs::write(node_dir.join("blank_user_npmrc"), []).await;
|
||||||
_ = fs::write(node_dir.join("blank_global_npmrc"), []).await;
|
_ = fs::write(node_dir.join("blank_global_npmrc"), []).await;
|
||||||
|
|
||||||
anyhow::Ok(node_dir)
|
anyhow::Ok(Box::new(ManagedNodeRuntime {
|
||||||
|
installation_path: node_dir,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl NodeRuntime for RealNodeRuntime {
|
impl NodeRuntimeTrait for ManagedNodeRuntime {
|
||||||
async fn binary_path(&self) -> Result<PathBuf> {
|
fn boxed_clone(&self) -> Box<dyn NodeRuntimeTrait> {
|
||||||
let installation_path = self.install_if_needed().await?;
|
Box::new(self.clone())
|
||||||
Ok(installation_path.join(NODE_PATH))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn node_environment_path(&self) -> Result<OsString> {
|
fn binary_path(&self) -> Result<PathBuf> {
|
||||||
let installation_path = self.install_if_needed().await?;
|
Ok(self.installation_path.join(Self::NODE_PATH))
|
||||||
let node_binary = installation_path.join(NODE_PATH);
|
|
||||||
let mut env_path = vec![node_binary
|
|
||||||
.parent()
|
|
||||||
.expect("invalid node binary path")
|
|
||||||
.to_path_buf()];
|
|
||||||
|
|
||||||
if let Some(existing_path) = std::env::var_os("PATH") {
|
|
||||||
let mut paths = std::env::split_paths(&existing_path).collect::<Vec<_>>();
|
|
||||||
env_path.append(&mut paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(std::env::join_paths(env_path).context("failed to create PATH env variable")?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_npm_subcommand(
|
async fn run_npm_subcommand(
|
||||||
&self,
|
&self,
|
||||||
directory: Option<&Path>,
|
directory: Option<&Path>,
|
||||||
|
proxy: Option<&Uri>,
|
||||||
subcommand: &str,
|
subcommand: &str,
|
||||||
args: &[&str],
|
args: &[&str],
|
||||||
) -> Result<Output> {
|
) -> Result<Output> {
|
||||||
let attempt = || async move {
|
let attempt = || async move {
|
||||||
let installation_path = self.install_if_needed().await?;
|
let node_binary = self.installation_path.join(Self::NODE_PATH);
|
||||||
let node_binary = installation_path.join(NODE_PATH);
|
let npm_file = self.installation_path.join(Self::NPM_PATH);
|
||||||
let npm_file = installation_path.join(NPM_PATH);
|
|
||||||
let env_path = self.node_environment_path().await?;
|
let env_path = self.node_environment_path().await?;
|
||||||
|
|
||||||
if smol::fs::metadata(&node_binary).await.is_err() {
|
if smol::fs::metadata(&node_binary).await.is_err() {
|
||||||
|
@ -258,54 +411,17 @@ impl NodeRuntime for RealNodeRuntime {
|
||||||
command.env_clear();
|
command.env_clear();
|
||||||
command.env("PATH", env_path);
|
command.env("PATH", env_path);
|
||||||
command.arg(npm_file).arg(subcommand);
|
command.arg(npm_file).arg(subcommand);
|
||||||
command.args(["--cache".into(), installation_path.join("cache")]);
|
command.args(["--cache".into(), self.installation_path.join("cache")]);
|
||||||
command.args([
|
command.args([
|
||||||
"--userconfig".into(),
|
"--userconfig".into(),
|
||||||
installation_path.join("blank_user_npmrc"),
|
self.installation_path.join("blank_user_npmrc"),
|
||||||
]);
|
]);
|
||||||
command.args([
|
command.args([
|
||||||
"--globalconfig".into(),
|
"--globalconfig".into(),
|
||||||
installation_path.join("blank_global_npmrc"),
|
self.installation_path.join("blank_global_npmrc"),
|
||||||
]);
|
]);
|
||||||
command.args(args);
|
command.args(args);
|
||||||
|
configure_npm_command(&mut command, directory, proxy);
|
||||||
if let Some(directory) = directory {
|
|
||||||
command.current_dir(directory);
|
|
||||||
command.args(["--prefix".into(), directory.to_path_buf()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(proxy) = self.http.proxy() {
|
|
||||||
// Map proxy settings from `http://localhost:10809` to `http://127.0.0.1:10809`
|
|
||||||
// NodeRuntime without environment information can not parse `localhost`
|
|
||||||
// correctly.
|
|
||||||
// TODO: map to `[::1]` if we are using ipv6
|
|
||||||
let proxy = proxy
|
|
||||||
.to_string()
|
|
||||||
.to_ascii_lowercase()
|
|
||||||
.replace("localhost", "127.0.0.1");
|
|
||||||
|
|
||||||
command.args(["--proxy", &proxy]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
{
|
|
||||||
// SYSTEMROOT is a critical environment variables for Windows.
|
|
||||||
if let Some(val) = std::env::var("SYSTEMROOT")
|
|
||||||
.context("Missing environment variable: SYSTEMROOT!")
|
|
||||||
.log_err()
|
|
||||||
{
|
|
||||||
command.env("SYSTEMROOT", val);
|
|
||||||
}
|
|
||||||
// Without ComSpec, the post-install will always fail.
|
|
||||||
if let Some(val) = std::env::var("ComSpec")
|
|
||||||
.context("Missing environment variable: ComSpec!")
|
|
||||||
.log_err()
|
|
||||||
{
|
|
||||||
command.env("ComSpec", val);
|
|
||||||
}
|
|
||||||
command.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
command.output().await.map_err(|e| anyhow!("{e}"))
|
command.output().await.map_err(|e| anyhow!("{e}"))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -332,30 +448,123 @@ impl NodeRuntime for RealNodeRuntime {
|
||||||
|
|
||||||
output.map_err(|e| anyhow!("{e}"))
|
output.map_err(|e| anyhow!("{e}"))
|
||||||
}
|
}
|
||||||
|
async fn npm_package_installed_version(
|
||||||
|
&self,
|
||||||
|
local_package_directory: &Path,
|
||||||
|
name: &str,
|
||||||
|
) -> Result<Option<String>> {
|
||||||
|
read_package_installed_version(local_package_directory.join("node_modules"), name).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn npm_package_latest_version(&self, name: &str) -> Result<String> {
|
#[derive(Clone)]
|
||||||
let output = self
|
pub struct SystemNodeRuntime {
|
||||||
.run_npm_subcommand(
|
node: PathBuf,
|
||||||
None,
|
npm: PathBuf,
|
||||||
"info",
|
global_node_modules: PathBuf,
|
||||||
&[
|
scratch_dir: PathBuf,
|
||||||
name,
|
}
|
||||||
"--json",
|
|
||||||
"--fetch-retry-mintimeout",
|
impl SystemNodeRuntime {
|
||||||
"2000",
|
const MIN_VERSION: semver::Version = Version::new(18, 0, 0);
|
||||||
"--fetch-retry-maxtimeout",
|
async fn new(node: PathBuf, npm: PathBuf) -> Result<Box<dyn NodeRuntimeTrait>> {
|
||||||
"5000",
|
let output = Command::new(&node)
|
||||||
"--fetch-timeout",
|
.arg("--version")
|
||||||
"5000",
|
.output()
|
||||||
],
|
.await
|
||||||
|
.with_context(|| format!("running node from {:?}", node))?;
|
||||||
|
if !output.status.success() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"failed to run node --version. stdout: {}, stderr: {}",
|
||||||
|
String::from_utf8_lossy(&output.stdout),
|
||||||
|
String::from_utf8_lossy(&output.stderr),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let version_str = String::from_utf8_lossy(&output.stdout);
|
||||||
|
let version = semver::Version::parse(version_str.trim().trim_start_matches('v'))?;
|
||||||
|
if version < Self::MIN_VERSION {
|
||||||
|
anyhow::bail!(
|
||||||
|
"node at {} is too old. want: {}, got: {}",
|
||||||
|
node.to_string_lossy(),
|
||||||
|
Self::MIN_VERSION,
|
||||||
|
version
|
||||||
)
|
)
|
||||||
.await?;
|
}
|
||||||
|
|
||||||
let mut info: NpmInfo = serde_json::from_slice(&output.stdout)?;
|
let scratch_dir = paths::support_dir().join("node");
|
||||||
info.dist_tags
|
fs::create_dir(&scratch_dir).await.ok();
|
||||||
.latest
|
fs::create_dir(scratch_dir.join("cache")).await.ok();
|
||||||
.or_else(|| info.versions.pop())
|
fs::write(scratch_dir.join("blank_user_npmrc"), [])
|
||||||
.ok_or_else(|| anyhow!("no version found for npm package {}", name))
|
.await
|
||||||
|
.ok();
|
||||||
|
fs::write(scratch_dir.join("blank_global_npmrc"), [])
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
let mut this = Self {
|
||||||
|
node,
|
||||||
|
npm,
|
||||||
|
global_node_modules: PathBuf::default(),
|
||||||
|
scratch_dir,
|
||||||
|
};
|
||||||
|
let output = this.run_npm_subcommand(None, None, "root", &["-g"]).await?;
|
||||||
|
this.global_node_modules =
|
||||||
|
PathBuf::from(String::from_utf8_lossy(&output.stdout).to_string());
|
||||||
|
|
||||||
|
Ok(Box::new(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn detect() -> Option<Box<dyn NodeRuntimeTrait>> {
|
||||||
|
let node = which::which("node").ok()?;
|
||||||
|
let npm = which::which("npm").ok()?;
|
||||||
|
Self::new(node, npm).await.log_err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl NodeRuntimeTrait for SystemNodeRuntime {
|
||||||
|
fn boxed_clone(&self) -> Box<dyn NodeRuntimeTrait> {
|
||||||
|
Box::new(self.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn binary_path(&self) -> Result<PathBuf> {
|
||||||
|
Ok(self.node.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn run_npm_subcommand(
|
||||||
|
&self,
|
||||||
|
directory: Option<&Path>,
|
||||||
|
proxy: Option<&Uri>,
|
||||||
|
subcommand: &str,
|
||||||
|
args: &[&str],
|
||||||
|
) -> anyhow::Result<Output> {
|
||||||
|
let mut command = Command::new(self.node.clone());
|
||||||
|
command
|
||||||
|
.env_clear()
|
||||||
|
.env("PATH", std::env::var_os("PATH").unwrap_or_default())
|
||||||
|
.arg(self.npm.clone())
|
||||||
|
.arg(subcommand)
|
||||||
|
.args(["--cache".into(), self.scratch_dir.join("cache")])
|
||||||
|
.args([
|
||||||
|
"--userconfig".into(),
|
||||||
|
self.scratch_dir.join("blank_user_npmrc"),
|
||||||
|
])
|
||||||
|
.args([
|
||||||
|
"--globalconfig".into(),
|
||||||
|
self.scratch_dir.join("blank_global_npmrc"),
|
||||||
|
])
|
||||||
|
.args(args);
|
||||||
|
configure_npm_command(&mut command, directory, proxy);
|
||||||
|
let output = command.output().await?;
|
||||||
|
if !output.status.success() {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"failed to execute npm {subcommand} subcommand:\nstdout: {:?}\nstderr: {:?}",
|
||||||
|
String::from_utf8_lossy(&output.stdout),
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn npm_package_installed_version(
|
async fn npm_package_installed_version(
|
||||||
|
@ -363,151 +572,104 @@ impl NodeRuntime for RealNodeRuntime {
|
||||||
local_package_directory: &Path,
|
local_package_directory: &Path,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Result<Option<String>> {
|
) -> Result<Option<String>> {
|
||||||
let mut package_json_path = local_package_directory.to_owned();
|
read_package_installed_version(local_package_directory.join("node_modules"), name).await
|
||||||
package_json_path.extend(["node_modules", name, "package.json"]);
|
// todo: allow returning a globally installed version (requires callers not to hard-code the path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut file = match fs::File::open(package_json_path).await {
|
async fn read_package_installed_version(
|
||||||
Ok(file) => file,
|
node_module_directory: PathBuf,
|
||||||
Err(err) => {
|
name: &str,
|
||||||
if err.kind() == io::ErrorKind::NotFound {
|
) -> Result<Option<String>> {
|
||||||
return Ok(None);
|
let package_json_path = node_module_directory.join(name).join("package.json");
|
||||||
}
|
|
||||||
|
|
||||||
Err(err)?
|
let mut file = match fs::File::open(package_json_path).await {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(err) => {
|
||||||
|
if err.kind() == io::ErrorKind::NotFound {
|
||||||
|
return Ok(None);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
Err(err)?
|
||||||
struct PackageJson {
|
|
||||||
version: String,
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut contents = String::new();
|
#[derive(Deserialize)]
|
||||||
file.read_to_string(&mut contents).await?;
|
struct PackageJson {
|
||||||
let package_json: PackageJson = serde_json::from_str(&contents)?;
|
version: String,
|
||||||
Ok(Some(package_json.version))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn npm_install_packages(
|
let mut contents = String::new();
|
||||||
&self,
|
file.read_to_string(&mut contents).await?;
|
||||||
directory: &Path,
|
let package_json: PackageJson = serde_json::from_str(&contents)?;
|
||||||
packages: &[(&str, &str)],
|
Ok(Some(package_json.version))
|
||||||
) -> Result<()> {
|
|
||||||
let packages: Vec<_> = packages
|
|
||||||
.iter()
|
|
||||||
.map(|(name, version)| format!("{name}@{version}"))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let mut arguments: Vec<_> = packages.iter().map(|p| p.as_str()).collect();
|
|
||||||
arguments.extend_from_slice(&[
|
|
||||||
"--save-exact",
|
|
||||||
"--fetch-retry-mintimeout",
|
|
||||||
"2000",
|
|
||||||
"--fetch-retry-maxtimeout",
|
|
||||||
"5000",
|
|
||||||
"--fetch-timeout",
|
|
||||||
"5000",
|
|
||||||
]);
|
|
||||||
|
|
||||||
self.run_npm_subcommand(Some(directory), "install", &arguments)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FakeNodeRuntime;
|
pub struct UnavailableNodeRuntime;
|
||||||
|
|
||||||
impl FakeNodeRuntime {
|
|
||||||
pub fn new() -> Arc<dyn NodeRuntime> {
|
|
||||||
Arc::new(Self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl NodeRuntime for FakeNodeRuntime {
|
impl NodeRuntimeTrait for UnavailableNodeRuntime {
|
||||||
async fn binary_path(&self) -> anyhow::Result<PathBuf> {
|
fn boxed_clone(&self) -> Box<dyn NodeRuntimeTrait> {
|
||||||
unreachable!()
|
Box::new(UnavailableNodeRuntime)
|
||||||
}
|
}
|
||||||
|
fn binary_path(&self) -> Result<PathBuf> {
|
||||||
async fn node_environment_path(&self) -> anyhow::Result<OsString> {
|
bail!("binary_path: no node runtime available")
|
||||||
unreachable!()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_npm_subcommand(
|
async fn run_npm_subcommand(
|
||||||
&self,
|
&self,
|
||||||
_: Option<&Path>,
|
_: Option<&Path>,
|
||||||
subcommand: &str,
|
_: Option<&Uri>,
|
||||||
args: &[&str],
|
_: &str,
|
||||||
|
_: &[&str],
|
||||||
) -> anyhow::Result<Output> {
|
) -> anyhow::Result<Output> {
|
||||||
unreachable!("Should not run npm subcommand '{subcommand}' with args {args:?}")
|
bail!("run_npm_subcommand: no node runtime available")
|
||||||
}
|
|
||||||
|
|
||||||
async fn npm_package_latest_version(&self, name: &str) -> anyhow::Result<String> {
|
|
||||||
unreachable!("Should not query npm package '{name}' for latest version")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn npm_package_installed_version(
|
async fn npm_package_installed_version(
|
||||||
&self,
|
&self,
|
||||||
_local_package_directory: &Path,
|
_local_package_directory: &Path,
|
||||||
name: &str,
|
_: &str,
|
||||||
) -> Result<Option<String>> {
|
) -> Result<Option<String>> {
|
||||||
unreachable!("Should not query npm package '{name}' for installed version")
|
bail!("npm_package_installed_version: no node runtime available")
|
||||||
}
|
|
||||||
|
|
||||||
async fn npm_install_packages(
|
|
||||||
&self,
|
|
||||||
_: &Path,
|
|
||||||
packages: &[(&str, &str)],
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
unreachable!("Should not install packages {packages:?}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this when headless binary can run node
|
fn configure_npm_command(command: &mut Command, directory: Option<&Path>, proxy: Option<&Uri>) {
|
||||||
pub struct DummyNodeRuntime;
|
if let Some(directory) = directory {
|
||||||
|
command.current_dir(directory);
|
||||||
|
command.args(["--prefix".into(), directory.to_path_buf()]);
|
||||||
|
}
|
||||||
|
|
||||||
impl DummyNodeRuntime {
|
if let Some(proxy) = proxy {
|
||||||
pub fn new() -> Arc<dyn NodeRuntime> {
|
// Map proxy settings from `http://localhost:10809` to `http://127.0.0.1:10809`
|
||||||
Arc::new(Self)
|
// NodeRuntime without environment information can not parse `localhost`
|
||||||
}
|
// correctly.
|
||||||
}
|
// TODO: map to `[::1]` if we are using ipv6
|
||||||
|
let proxy = proxy
|
||||||
#[async_trait::async_trait]
|
.to_string()
|
||||||
impl NodeRuntime for DummyNodeRuntime {
|
.to_ascii_lowercase()
|
||||||
async fn binary_path(&self) -> anyhow::Result<PathBuf> {
|
.replace("localhost", "127.0.0.1");
|
||||||
anyhow::bail!("Dummy Node Runtime")
|
|
||||||
}
|
command.args(["--proxy", &proxy]);
|
||||||
|
}
|
||||||
async fn node_environment_path(&self) -> anyhow::Result<OsString> {
|
|
||||||
anyhow::bail!("Dummy node runtime")
|
#[cfg(windows)]
|
||||||
}
|
{
|
||||||
|
// SYSTEMROOT is a critical environment variables for Windows.
|
||||||
async fn run_npm_subcommand(
|
if let Some(val) = std::env::var("SYSTEMROOT")
|
||||||
&self,
|
.context("Missing environment variable: SYSTEMROOT!")
|
||||||
_: Option<&Path>,
|
.log_err()
|
||||||
_subcommand: &str,
|
{
|
||||||
_args: &[&str],
|
command.env("SYSTEMROOT", val);
|
||||||
) -> anyhow::Result<Output> {
|
}
|
||||||
anyhow::bail!("Dummy node runtime")
|
// Without ComSpec, the post-install will always fail.
|
||||||
}
|
if let Some(val) = std::env::var("ComSpec")
|
||||||
|
.context("Missing environment variable: ComSpec!")
|
||||||
async fn npm_package_latest_version(&self, _name: &str) -> anyhow::Result<String> {
|
.log_err()
|
||||||
anyhow::bail!("Dummy node runtime")
|
{
|
||||||
}
|
command.env("ComSpec", val);
|
||||||
|
}
|
||||||
async fn npm_package_installed_version(
|
command.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);
|
||||||
&self,
|
|
||||||
_local_package_directory: &Path,
|
|
||||||
_name: &str,
|
|
||||||
) -> Result<Option<String>> {
|
|
||||||
anyhow::bail!("Dummy node runtime")
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn npm_install_packages(
|
|
||||||
&self,
|
|
||||||
_: &Path,
|
|
||||||
_packages: &[(&str, &str)],
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
anyhow::bail!("Dummy node runtime")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ impl Prettier {
|
||||||
pub async fn start(
|
pub async fn start(
|
||||||
_: LanguageServerId,
|
_: LanguageServerId,
|
||||||
prettier_dir: PathBuf,
|
prettier_dir: PathBuf,
|
||||||
_: Arc<dyn NodeRuntime>,
|
_: NodeRuntime,
|
||||||
_: AsyncAppContext,
|
_: AsyncAppContext,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
Ok(Self::Test(TestPrettier {
|
Ok(Self::Test(TestPrettier {
|
||||||
|
@ -151,7 +151,7 @@ impl Prettier {
|
||||||
pub async fn start(
|
pub async fn start(
|
||||||
server_id: LanguageServerId,
|
server_id: LanguageServerId,
|
||||||
prettier_dir: PathBuf,
|
prettier_dir: PathBuf,
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
cx: AsyncAppContext,
|
cx: AsyncAppContext,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
use lsp::LanguageServerBinary;
|
use lsp::LanguageServerBinary;
|
||||||
|
|
|
@ -17,7 +17,7 @@ use async_trait::async_trait;
|
||||||
use client::{proto, TypedEnvelope};
|
use client::{proto, TypedEnvelope};
|
||||||
use collections::{btree_map, BTreeMap, HashMap, HashSet};
|
use collections::{btree_map, BTreeMap, HashMap, HashSet};
|
||||||
use futures::{
|
use futures::{
|
||||||
future::{join_all, BoxFuture, Shared},
|
future::{join_all, Shared},
|
||||||
select,
|
select,
|
||||||
stream::FuturesUnordered,
|
stream::FuturesUnordered,
|
||||||
AsyncWriteExt, Future, FutureExt, StreamExt,
|
AsyncWriteExt, Future, FutureExt, StreamExt,
|
||||||
|
@ -27,7 +27,7 @@ use gpui::{
|
||||||
AppContext, AsyncAppContext, Context, Entity, EventEmitter, Model, ModelContext, PromptLevel,
|
AppContext, AsyncAppContext, Context, Entity, EventEmitter, Model, ModelContext, PromptLevel,
|
||||||
Task, WeakModel,
|
Task, WeakModel,
|
||||||
};
|
};
|
||||||
use http_client::{AsyncBody, HttpClient, Request, Response, Uri};
|
use http_client::{BlockedHttpClient, HttpClient};
|
||||||
use language::{
|
use language::{
|
||||||
language_settings::{
|
language_settings::{
|
||||||
all_language_settings, language_settings, AllLanguageSettings, FormatOnSave, Formatter,
|
all_language_settings, language_settings, AllLanguageSettings, FormatOnSave, Formatter,
|
||||||
|
@ -7979,35 +7979,6 @@ impl LspAdapterDelegate for LocalLspAdapterDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BlockedHttpClient;
|
|
||||||
|
|
||||||
impl HttpClient for BlockedHttpClient {
|
|
||||||
fn send(
|
|
||||||
&self,
|
|
||||||
_req: Request<AsyncBody>,
|
|
||||||
) -> BoxFuture<'static, Result<Response<AsyncBody>, anyhow::Error>> {
|
|
||||||
Box::pin(async {
|
|
||||||
Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::PermissionDenied,
|
|
||||||
"ssh host blocked http connection",
|
|
||||||
)
|
|
||||||
.into())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn proxy(&self) -> Option<&Uri> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_with_redirect_policy(
|
|
||||||
&self,
|
|
||||||
req: Request<AsyncBody>,
|
|
||||||
_: bool,
|
|
||||||
) -> BoxFuture<'static, Result<Response<AsyncBody>, anyhow::Error>> {
|
|
||||||
self.send(req)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SshLspAdapterDelegate {
|
struct SshLspAdapterDelegate {
|
||||||
lsp_store: WeakModel<LspStore>,
|
lsp_store: WeakModel<LspStore>,
|
||||||
worktree: worktree::Snapshot,
|
worktree: worktree::Snapshot,
|
||||||
|
|
|
@ -30,7 +30,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct PrettierStore {
|
pub struct PrettierStore {
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
worktree_store: Model<WorktreeStore>,
|
worktree_store: Model<WorktreeStore>,
|
||||||
|
@ -52,7 +52,7 @@ impl EventEmitter<PrettierStoreEvent> for PrettierStore {}
|
||||||
|
|
||||||
impl PrettierStore {
|
impl PrettierStore {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
worktree_store: Model<WorktreeStore>,
|
worktree_store: Model<WorktreeStore>,
|
||||||
|
@ -212,7 +212,7 @@ impl PrettierStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_prettier(
|
fn start_prettier(
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
prettier_dir: PathBuf,
|
prettier_dir: PathBuf,
|
||||||
worktree_id: Option<WorktreeId>,
|
worktree_id: Option<WorktreeId>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
|
@ -241,7 +241,7 @@ impl PrettierStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_default_prettier(
|
fn start_default_prettier(
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
worktree_id: Option<WorktreeId>,
|
worktree_id: Option<WorktreeId>,
|
||||||
cx: &mut ModelContext<PrettierStore>,
|
cx: &mut ModelContext<PrettierStore>,
|
||||||
) -> Task<anyhow::Result<PrettierTask>> {
|
) -> Task<anyhow::Result<PrettierTask>> {
|
||||||
|
@ -749,7 +749,7 @@ impl DefaultPrettier {
|
||||||
|
|
||||||
pub fn prettier_task(
|
pub fn prettier_task(
|
||||||
&mut self,
|
&mut self,
|
||||||
node: &Arc<dyn NodeRuntime>,
|
node: &NodeRuntime,
|
||||||
worktree_id: Option<WorktreeId>,
|
worktree_id: Option<WorktreeId>,
|
||||||
cx: &mut ModelContext<PrettierStore>,
|
cx: &mut ModelContext<PrettierStore>,
|
||||||
) -> Option<Task<anyhow::Result<PrettierTask>>> {
|
) -> Option<Task<anyhow::Result<PrettierTask>>> {
|
||||||
|
@ -767,7 +767,7 @@ impl DefaultPrettier {
|
||||||
impl PrettierInstance {
|
impl PrettierInstance {
|
||||||
pub fn prettier_task(
|
pub fn prettier_task(
|
||||||
&mut self,
|
&mut self,
|
||||||
node: &Arc<dyn NodeRuntime>,
|
node: &NodeRuntime,
|
||||||
prettier_dir: Option<&Path>,
|
prettier_dir: Option<&Path>,
|
||||||
worktree_id: Option<WorktreeId>,
|
worktree_id: Option<WorktreeId>,
|
||||||
cx: &mut ModelContext<PrettierStore>,
|
cx: &mut ModelContext<PrettierStore>,
|
||||||
|
@ -786,7 +786,7 @@ impl PrettierInstance {
|
||||||
None => match prettier_dir {
|
None => match prettier_dir {
|
||||||
Some(prettier_dir) => {
|
Some(prettier_dir) => {
|
||||||
let new_task = PrettierStore::start_prettier(
|
let new_task = PrettierStore::start_prettier(
|
||||||
Arc::clone(node),
|
node.clone(),
|
||||||
prettier_dir.to_path_buf(),
|
prettier_dir.to_path_buf(),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
cx,
|
cx,
|
||||||
|
@ -797,7 +797,7 @@ impl PrettierInstance {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
self.attempt += 1;
|
self.attempt += 1;
|
||||||
let node = Arc::clone(node);
|
let node = node.clone();
|
||||||
cx.spawn(|prettier_store, mut cx| async move {
|
cx.spawn(|prettier_store, mut cx| async move {
|
||||||
prettier_store
|
prettier_store
|
||||||
.update(&mut cx, |_, cx| {
|
.update(&mut cx, |_, cx| {
|
||||||
|
@ -818,7 +818,7 @@ impl PrettierInstance {
|
||||||
async fn install_prettier_packages(
|
async fn install_prettier_packages(
|
||||||
fs: &dyn Fs,
|
fs: &dyn Fs,
|
||||||
plugins_to_install: HashSet<Arc<str>>,
|
plugins_to_install: HashSet<Arc<str>>,
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let packages_to_versions = future::try_join_all(
|
let packages_to_versions = future::try_join_all(
|
||||||
plugins_to_install
|
plugins_to_install
|
||||||
|
|
|
@ -153,7 +153,7 @@ pub struct Project {
|
||||||
git_diff_debouncer: DebouncedDelay<Self>,
|
git_diff_debouncer: DebouncedDelay<Self>,
|
||||||
remotely_created_models: Arc<Mutex<RemotelyCreatedModels>>,
|
remotely_created_models: Arc<Mutex<RemotelyCreatedModels>>,
|
||||||
terminals: Terminals,
|
terminals: Terminals,
|
||||||
node: Option<Arc<dyn NodeRuntime>>,
|
node: Option<NodeRuntime>,
|
||||||
tasks: Model<Inventory>,
|
tasks: Model<Inventory>,
|
||||||
hosted_project_id: Option<ProjectId>,
|
hosted_project_id: Option<ProjectId>,
|
||||||
dev_server_project_id: Option<client::DevServerProjectId>,
|
dev_server_project_id: Option<client::DevServerProjectId>,
|
||||||
|
@ -579,7 +579,7 @@ impl Project {
|
||||||
|
|
||||||
pub fn local(
|
pub fn local(
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
user_store: Model<UserStore>,
|
user_store: Model<UserStore>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
|
@ -675,7 +675,7 @@ impl Project {
|
||||||
pub fn ssh(
|
pub fn ssh(
|
||||||
ssh: Arc<SshSession>,
|
ssh: Arc<SshSession>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
node: Arc<dyn NodeRuntime>,
|
node: NodeRuntime,
|
||||||
user_store: Model<UserStore>,
|
user_store: Model<UserStore>,
|
||||||
languages: Arc<LanguageRegistry>,
|
languages: Arc<LanguageRegistry>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
|
@ -1064,7 +1064,7 @@ impl Project {
|
||||||
.update(|cx| {
|
.update(|cx| {
|
||||||
Project::local(
|
Project::local(
|
||||||
client,
|
client,
|
||||||
node_runtime::FakeNodeRuntime::new(),
|
node_runtime::NodeRuntime::unavailable(),
|
||||||
user_store,
|
user_store,
|
||||||
Arc::new(languages),
|
Arc::new(languages),
|
||||||
fs,
|
fs,
|
||||||
|
@ -1104,7 +1104,7 @@ impl Project {
|
||||||
let project = cx.update(|cx| {
|
let project = cx.update(|cx| {
|
||||||
Project::local(
|
Project::local(
|
||||||
client,
|
client,
|
||||||
node_runtime::FakeNodeRuntime::new(),
|
node_runtime::NodeRuntime::unavailable(),
|
||||||
user_store,
|
user_store,
|
||||||
Arc::new(languages),
|
Arc::new(languages),
|
||||||
fs,
|
fs,
|
||||||
|
@ -1157,7 +1157,7 @@ impl Project {
|
||||||
self.user_store.clone()
|
self.user_store.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_runtime(&self) -> Option<&Arc<dyn NodeRuntime>> {
|
pub fn node_runtime(&self) -> Option<&NodeRuntime> {
|
||||||
self.node.as_ref()
|
self.node.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,10 @@ pub struct ProjectSettings {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub git: GitSettings,
|
pub git: GitSettings,
|
||||||
|
|
||||||
|
/// Configuration for Node-related features
|
||||||
|
#[serde(default)]
|
||||||
|
pub node: NodeBinarySettings,
|
||||||
|
|
||||||
/// Configuration for how direnv configuration should be loaded
|
/// Configuration for how direnv configuration should be loaded
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub load_direnv: DirenvSettings,
|
pub load_direnv: DirenvSettings,
|
||||||
|
@ -43,6 +47,17 @@ pub struct ProjectSettings {
|
||||||
pub session: SessionSettings,
|
pub session: SessionSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||||
|
pub struct NodeBinarySettings {
|
||||||
|
/// The path to the node binary
|
||||||
|
pub path: Option<String>,
|
||||||
|
/// The path to the npm binary Zed should use (defaults to .path/../npm)
|
||||||
|
pub npm_path: Option<String>,
|
||||||
|
/// If disabled, zed will download its own copy of node.
|
||||||
|
#[serde(default)]
|
||||||
|
pub disable_path_lookup: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum DirenvSettings {
|
pub enum DirenvSettings {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use anyhow::{anyhow, Result};
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use gpui::{AppContext, AsyncAppContext, Context, Model, ModelContext};
|
use gpui::{AppContext, AsyncAppContext, Context, Model, ModelContext};
|
||||||
use language::{proto::serialize_operation, Buffer, BufferEvent, LanguageRegistry};
|
use language::{proto::serialize_operation, Buffer, BufferEvent, LanguageRegistry};
|
||||||
use node_runtime::DummyNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use project::{
|
use project::{
|
||||||
buffer_store::{BufferStore, BufferStoreEvent},
|
buffer_store::{BufferStore, BufferStoreEvent},
|
||||||
project_settings::SettingsObserver,
|
project_settings::SettingsObserver,
|
||||||
|
@ -57,7 +57,7 @@ impl HeadlessProject {
|
||||||
});
|
});
|
||||||
let prettier_store = cx.new_model(|cx| {
|
let prettier_store = cx.new_model(|cx| {
|
||||||
PrettierStore::new(
|
PrettierStore::new(
|
||||||
DummyNodeRuntime::new(),
|
NodeRuntime::unavailable(),
|
||||||
fs.clone(),
|
fs.clone(),
|
||||||
languages.clone(),
|
languages.clone(),
|
||||||
worktree_store.clone(),
|
worktree_store.clone(),
|
||||||
|
|
|
@ -9,7 +9,7 @@ use language::{
|
||||||
Buffer, FakeLspAdapter, LanguageConfig, LanguageMatcher, LanguageRegistry, LanguageServerName,
|
Buffer, FakeLspAdapter, LanguageConfig, LanguageMatcher, LanguageRegistry, LanguageServerName,
|
||||||
};
|
};
|
||||||
use lsp::{CompletionContext, CompletionResponse, CompletionTriggerKind};
|
use lsp::{CompletionContext, CompletionResponse, CompletionTriggerKind};
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use project::{
|
use project::{
|
||||||
search::{SearchQuery, SearchResult},
|
search::{SearchQuery, SearchResult},
|
||||||
Project,
|
Project,
|
||||||
|
@ -502,7 +502,7 @@ fn build_project(ssh: Arc<SshSession>, cx: &mut TestAppContext) -> Model<Project
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let node = FakeNodeRuntime::new();
|
let node = NodeRuntime::unavailable();
|
||||||
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
|
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
|
||||||
let languages = Arc::new(LanguageRegistry::test(cx.executor()));
|
let languages = Arc::new(LanguageRegistry::test(cx.executor()));
|
||||||
let fs = FakeFs::new(cx.executor());
|
let fs = FakeFs::new(cx.executor());
|
||||||
|
|
|
@ -556,7 +556,7 @@ pub struct AppState {
|
||||||
pub workspace_store: Model<WorkspaceStore>,
|
pub workspace_store: Model<WorkspaceStore>,
|
||||||
pub fs: Arc<dyn fs::Fs>,
|
pub fs: Arc<dyn fs::Fs>,
|
||||||
pub build_window_options: fn(Option<Uuid>, &mut AppContext) -> WindowOptions,
|
pub build_window_options: fn(Option<Uuid>, &mut AppContext) -> WindowOptions,
|
||||||
pub node_runtime: Arc<dyn NodeRuntime>,
|
pub node_runtime: NodeRuntime,
|
||||||
pub session: Model<AppSession>,
|
pub session: Model<AppSession>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,7 +590,7 @@ impl AppState {
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn test(cx: &mut AppContext) -> Arc<Self> {
|
pub fn test(cx: &mut AppContext) -> Arc<Self> {
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use session::Session;
|
use session::Session;
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
use ui::Context as _;
|
use ui::Context as _;
|
||||||
|
@ -619,7 +619,7 @@ impl AppState {
|
||||||
languages,
|
languages,
|
||||||
user_store,
|
user_store,
|
||||||
workspace_store,
|
workspace_store,
|
||||||
node_runtime: FakeNodeRuntime::new(),
|
node_runtime: NodeRuntime::unavailable(),
|
||||||
build_window_options: |_, _| Default::default(),
|
build_window_options: |_, _| Default::default(),
|
||||||
session,
|
session,
|
||||||
})
|
})
|
||||||
|
@ -4418,7 +4418,7 @@ impl Workspace {
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn test_new(project: Model<Project>, cx: &mut ViewContext<Self>) -> Self {
|
pub fn test_new(project: Model<Project>, cx: &mut ViewContext<Self>) -> Self {
|
||||||
use node_runtime::FakeNodeRuntime;
|
use node_runtime::NodeRuntime;
|
||||||
use session::Session;
|
use session::Session;
|
||||||
|
|
||||||
let client = project.read(cx).client();
|
let client = project.read(cx).client();
|
||||||
|
@ -4434,7 +4434,7 @@ impl Workspace {
|
||||||
user_store,
|
user_store,
|
||||||
fs: project.read(cx).fs().clone(),
|
fs: project.read(cx).fs().clone(),
|
||||||
build_window_options: |_, _| Default::default(),
|
build_window_options: |_, _| Default::default(),
|
||||||
node_runtime: FakeNodeRuntime::new(),
|
node_runtime: NodeRuntime::unavailable(),
|
||||||
session,
|
session,
|
||||||
});
|
});
|
||||||
let workspace = Self::new(Default::default(), project, app_state, cx);
|
let workspace = Self::new(Default::default(), project, app_state, cx);
|
||||||
|
|
|
@ -19,6 +19,7 @@ activity_indicator.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
assets.workspace = true
|
assets.workspace = true
|
||||||
assistant.workspace = true
|
assistant.workspace = true
|
||||||
|
async-watch.workspace = true
|
||||||
audio.workspace = true
|
audio.workspace = true
|
||||||
auto_update.workspace = true
|
auto_update.workspace = true
|
||||||
backtrace = "0.3"
|
backtrace = "0.3"
|
||||||
|
@ -92,6 +93,7 @@ serde_json.workspace = true
|
||||||
session.workspace = true
|
session.workspace = true
|
||||||
settings.workspace = true
|
settings.workspace = true
|
||||||
settings_ui.workspace = true
|
settings_ui.workspace = true
|
||||||
|
shellexpand.workspace = true
|
||||||
simplelog.workspace = true
|
simplelog.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
snippet_provider.workspace = true
|
snippet_provider.workspace = true
|
||||||
|
|
|
@ -29,8 +29,9 @@ use language::LanguageRegistry;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
|
|
||||||
use assets::Assets;
|
use assets::Assets;
|
||||||
use node_runtime::RealNodeRuntime;
|
use node_runtime::{NodeBinaryOptions, NodeRuntime};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use project::project_settings::ProjectSettings;
|
||||||
use recent_projects::open_ssh_project;
|
use recent_projects::open_ssh_project;
|
||||||
use release_channel::{AppCommitSha, AppVersion};
|
use release_channel::{AppCommitSha, AppVersion};
|
||||||
use session::{AppSession, Session};
|
use session::{AppSession, Session};
|
||||||
|
@ -43,7 +44,7 @@ use std::{
|
||||||
env,
|
env,
|
||||||
fs::OpenOptions,
|
fs::OpenOptions,
|
||||||
io::{IsTerminal, Write},
|
io::{IsTerminal, Write},
|
||||||
path::Path,
|
path::{Path, PathBuf},
|
||||||
process,
|
process,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
@ -477,7 +478,32 @@ fn main() {
|
||||||
let mut languages = LanguageRegistry::new(cx.background_executor().clone());
|
let mut languages = LanguageRegistry::new(cx.background_executor().clone());
|
||||||
languages.set_language_server_download_dir(paths::languages_dir().clone());
|
languages.set_language_server_download_dir(paths::languages_dir().clone());
|
||||||
let languages = Arc::new(languages);
|
let languages = Arc::new(languages);
|
||||||
let node_runtime = RealNodeRuntime::new(client.http_client());
|
let (tx, rx) = async_watch::channel(None);
|
||||||
|
cx.observe_global::<SettingsStore>(move |cx| {
|
||||||
|
let settings = &ProjectSettings::get_global(cx).node;
|
||||||
|
let options = NodeBinaryOptions {
|
||||||
|
allow_path_lookup: !settings.disable_path_lookup.unwrap_or_default(),
|
||||||
|
// TODO: Expose this setting
|
||||||
|
allow_binary_download: true,
|
||||||
|
use_paths: settings.path.as_ref().map(|node_path| {
|
||||||
|
let node_path = PathBuf::from(shellexpand::tilde(node_path).as_ref());
|
||||||
|
let npm_path = settings
|
||||||
|
.npm_path
|
||||||
|
.as_ref()
|
||||||
|
.map(|path| PathBuf::from(shellexpand::tilde(&path).as_ref()));
|
||||||
|
(
|
||||||
|
node_path.clone(),
|
||||||
|
npm_path.unwrap_or_else(|| {
|
||||||
|
let base_path = PathBuf::new();
|
||||||
|
node_path.parent().unwrap_or(&base_path).join("npm")
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
tx.send(Some(options)).log_err();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
let node_runtime = NodeRuntime::new(client.http_client(), rx);
|
||||||
|
|
||||||
language::init(cx);
|
language::init(cx);
|
||||||
languages::init(languages.clone(), node_runtime.clone(), cx);
|
languages::init(languages.clone(), node_runtime.clone(), cx);
|
||||||
|
|
|
@ -3365,7 +3365,7 @@ mod tests {
|
||||||
cx.set_global(settings);
|
cx.set_global(settings);
|
||||||
let languages = LanguageRegistry::test(cx.executor());
|
let languages = LanguageRegistry::test(cx.executor());
|
||||||
let languages = Arc::new(languages);
|
let languages = Arc::new(languages);
|
||||||
let node_runtime = node_runtime::FakeNodeRuntime::new();
|
let node_runtime = node_runtime::NodeRuntime::unavailable();
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
languages::init(languages.clone(), node_runtime, cx);
|
languages::init(languages.clone(), node_runtime, cx);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue