diff --git a/Cargo.lock b/Cargo.lock index 6afd9734604e518d290571f82b860b9699cf06e8..a1a747adeb0c795c28ee84a1f2cac88ac5282822 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9945,6 +9945,7 @@ dependencies = [ "assets", "base64 0.22.1", "env_logger 0.11.8", + "fs", "futures 0.3.31", "gpui", "language", diff --git a/crates/eval/src/eval.rs b/crates/eval/src/eval.rs index 9e0504abca479483b4e5f49c41eec1f6ba3834f1..32399e26c020b315f948e7e9013c7000ef9bd899 100644 --- a/crates/eval/src/eval.rs +++ b/crates/eval/src/eval.rs @@ -419,7 +419,7 @@ pub fn init(cx: &mut App) -> Arc { language_extension::init(LspAccess::Noop, extension_host_proxy, languages.clone()); language_model::init(client.clone(), cx); language_models::init(user_store.clone(), client.clone(), cx); - languages::init(languages.clone(), node_runtime.clone(), cx); + languages::init(languages.clone(), fs.clone(), node_runtime.clone(), cx); prompt_store::init(cx); terminal_view::init(cx); let stdout_is_a_pty = false; diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 256f6d45734ec068f1e038fe0d07049bb732e34b..aa07524ea9a86d3d2279e28df7a1aeab3103adcd 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -27,7 +27,6 @@ use crate::language_settings::SoftWrap; use anyhow::{Context as _, Result}; use async_trait::async_trait; use collections::{HashMap, HashSet, IndexSet}; -use fs::Fs; use futures::Future; use gpui::{App, AsyncApp, Entity, SharedString, Task}; pub use highlight_map::HighlightMap; @@ -511,7 +510,6 @@ pub trait LspAdapter: 'static + Send + Sync { /// Returns initialization options that are going to be sent to a LSP server as a part of [`lsp::InitializeParams`] async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { Ok(None) @@ -519,7 +517,6 @@ pub trait LspAdapter: 'static + Send + Sync { async fn workspace_configuration( self: Arc, - _: &dyn Fs, _: &Arc, _: Option, _cx: &mut AsyncApp, @@ -530,7 +527,6 @@ pub trait LspAdapter: 'static + Send + Sync { async fn additional_initialization_options( self: Arc, _target_language_server_id: LanguageServerName, - _: &dyn Fs, _: &Arc, ) -> Result> { Ok(None) @@ -539,7 +535,6 @@ pub trait LspAdapter: 'static + Send + Sync { async fn additional_workspace_configuration( self: Arc, _target_language_server_id: LanguageServerName, - _: &dyn Fs, _: &Arc, _cx: &mut AsyncApp, ) -> Result> { @@ -2261,7 +2256,6 @@ impl LspAdapter for FakeLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { Ok(self.initialization_options.clone()) diff --git a/crates/language/src/task_context.rs b/crates/language/src/task_context.rs index 5bede45cdb7aad30ebd4fb52f1b5e26779292180..b8cc6d13fff14576ca938e36d8982973f6307912 100644 --- a/crates/language/src/task_context.rs +++ b/crates/language/src/task_context.rs @@ -37,12 +37,7 @@ pub trait ContextProvider: Send + Sync { } /// Provides all tasks, associated with the current language. - fn associated_tasks( - &self, - _: Arc, - _: Option>, - _: &App, - ) -> Task> { + fn associated_tasks(&self, _: Option>, _: &App) -> Task> { Task::ready(None) } diff --git a/crates/language_extension/src/extension_lsp_adapter.rs b/crates/language_extension/src/extension_lsp_adapter.rs index c1bc058a344e02fd4830c9db89684579a9e7e045..318f5e62d8d586c3cfa0cbc261ac1850641f611e 100644 --- a/crates/language_extension/src/extension_lsp_adapter.rs +++ b/crates/language_extension/src/extension_lsp_adapter.rs @@ -8,7 +8,6 @@ use anyhow::{Context as _, Result}; use async_trait::async_trait; use collections::{HashMap, HashSet}; use extension::{Extension, ExtensionLanguageServerProxy, WorktreeDelegate}; -use fs::Fs; use futures::{Future, FutureExt, future::join_all}; use gpui::{App, AppContext, AsyncApp, Task}; use language::{ @@ -264,7 +263,6 @@ impl LspAdapter for ExtensionLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, delegate: &Arc, ) -> Result> { let delegate = Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _; @@ -287,7 +285,6 @@ impl LspAdapter for ExtensionLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, delegate: &Arc, _: Option, _cx: &mut AsyncApp, @@ -309,7 +306,6 @@ impl LspAdapter for ExtensionLspAdapter { async fn additional_initialization_options( self: Arc, target_language_server_id: LanguageServerName, - _: &dyn Fs, delegate: &Arc, ) -> Result> { let delegate = Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _; @@ -335,7 +331,7 @@ impl LspAdapter for ExtensionLspAdapter { async fn additional_workspace_configuration( self: Arc, target_language_server_id: LanguageServerName, - _: &dyn Fs, + delegate: &Arc, _cx: &mut AsyncApp, diff --git a/crates/languages/src/css.rs b/crates/languages/src/css.rs index 79e3a62a342092a6203361e5611b9ff81481e984..37955b31c5d111577a3ab36951df9edb09187aac 100644 --- a/crates/languages/src/css.rs +++ b/crates/languages/src/css.rs @@ -5,7 +5,7 @@ use gpui::AsyncApp; use language::{LspAdapter, LspAdapterDelegate, Toolchain}; use lsp::{LanguageServerBinary, LanguageServerName}; use node_runtime::{NodeRuntime, VersionStrategy}; -use project::{Fs, lsp_store::language_server_settings}; +use project::lsp_store::language_server_settings; use serde_json::json; use smol::fs; use std::{ @@ -133,7 +133,6 @@ impl LspAdapter for CssLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { Ok(Some(json!({ @@ -143,7 +142,6 @@ impl LspAdapter for CssLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, delegate: &Arc, _: Option, cx: &mut AsyncApp, diff --git a/crates/languages/src/go.rs b/crates/languages/src/go.rs index 55441c33b8fa076654a2231b0a69a0579306ce18..ff98f7bc8689a197a9eca2f1ec8ba068ac7a4984 100644 --- a/crates/languages/src/go.rs +++ b/crates/languages/src/go.rs @@ -6,7 +6,7 @@ use gpui::{App, AsyncApp, Task}; use http_client::github::latest_github_release; pub use language::*; use lsp::{LanguageServerBinary, LanguageServerName}; -use project::Fs; + use regex::Regex; use serde_json::json; use smol::fs; @@ -200,7 +200,6 @@ impl super::LspAdapter for GoLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { Ok(Some(json!({ @@ -568,12 +567,7 @@ impl ContextProvider for GoContextProvider { ))) } - fn associated_tasks( - &self, - _: Arc, - _: Option>, - _: &App, - ) -> Task> { + fn associated_tasks(&self, _: Option>, _: &App) -> Task> { let package_cwd = if GO_PACKAGE_TASK_VARIABLE.template_value() == "." { None } else { diff --git a/crates/languages/src/json.rs b/crates/languages/src/json.rs index a33f5c9836f621a59b45aba7a249f7b1c2d1489d..0d5d21de0b2e497f662551d45fd2a7c809b84291 100644 --- a/crates/languages/src/json.rs +++ b/crates/languages/src/json.rs @@ -13,7 +13,7 @@ use language::{ }; use lsp::{LanguageServerBinary, LanguageServerName}; use node_runtime::{NodeRuntime, VersionStrategy}; -use project::{Fs, lsp_store::language_server_settings}; +use project::lsp_store::language_server_settings; use serde_json::{Value, json}; use settings::{KeymapFile, SettingsJsonSchemaParams, SettingsStore}; use smol::{ @@ -46,7 +46,6 @@ pub(crate) struct JsonTaskProvider; impl ContextProvider for JsonTaskProvider { fn associated_tasks( &self, - _: Arc, file: Option>, cx: &App, ) -> gpui::Task> { @@ -393,7 +392,6 @@ impl LspAdapter for JsonLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { Ok(Some(json!({ @@ -403,7 +401,6 @@ impl LspAdapter for JsonLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, delegate: &Arc, _: Option, cx: &mut AsyncApp, diff --git a/crates/languages/src/lib.rs b/crates/languages/src/lib.rs index 95fe1312183a3412509375050b1e1ff67642ef3e..8dd2a6b9fdd356aa0c57cc44227073ae11798074 100644 --- a/crates/languages/src/lib.rs +++ b/crates/languages/src/lib.rs @@ -1,6 +1,7 @@ use anyhow::Context as _; use gpui::{App, SharedString, UpdateGlobal}; use node_runtime::NodeRuntime; +use project::Fs; use python::PyprojectTomlManifestProvider; use rust::CargoManifestProvider; use rust_embed::RustEmbed; @@ -53,7 +54,7 @@ pub static LANGUAGE_GIT_COMMIT: std::sync::LazyLock> = )) }); -pub fn init(languages: Arc, node: NodeRuntime, cx: &mut App) { +pub fn init(languages: Arc, fs: Arc, node: NodeRuntime, cx: &mut App) { #[cfg(feature = "load-grammars")] languages.register_native_grammars([ ("bash", tree_sitter_bash::LANGUAGE), @@ -94,9 +95,12 @@ pub fn init(languages: Arc, node: NodeRuntime, cx: &mut App) { let rust_context_provider = Arc::new(rust::RustContextProvider); let rust_lsp_adapter = Arc::new(rust::RustLspAdapter); let tailwind_adapter = Arc::new(tailwind::TailwindLspAdapter::new(node.clone())); - let typescript_context = Arc::new(typescript::TypeScriptContextProvider::new()); - let typescript_lsp_adapter = Arc::new(typescript::TypeScriptLspAdapter::new(node.clone())); - let vtsls_adapter = Arc::new(vtsls::VtslsLspAdapter::new(node.clone())); + let typescript_context = Arc::new(typescript::TypeScriptContextProvider::new(fs.clone())); + let typescript_lsp_adapter = Arc::new(typescript::TypeScriptLspAdapter::new( + node.clone(), + fs.clone(), + )); + let vtsls_adapter = Arc::new(vtsls::VtslsLspAdapter::new(node.clone(), fs.clone())); let yaml_lsp_adapter = Arc::new(yaml::YamlLspAdapter::new(node)); let built_in_languages = [ diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index f5ce2cee5e89e4141277d195849f6fe3dc95dc62..c8738a70005d0ee63ef0a36e7c7521bf53f6f3b3 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -119,7 +119,6 @@ impl LspAdapter for PythonLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { // Provide minimal initialization options @@ -324,7 +323,7 @@ impl LspAdapter for PythonLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, + adapter: &Arc, toolchain: Option, cx: &mut AsyncApp, @@ -471,7 +470,6 @@ impl ContextProvider for PythonContextProvider { fn associated_tasks( &self, - _: Arc, file: Option>, cx: &App, ) -> Task> { @@ -1270,7 +1268,6 @@ impl LspAdapter for PyLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, adapter: &Arc, toolchain: Option, cx: &mut AsyncApp, @@ -1405,7 +1402,6 @@ impl LspAdapter for BasedPyrightLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { // Provide minimal initialization options @@ -1576,7 +1572,6 @@ impl LspAdapter for BasedPyrightLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, adapter: &Arc, toolchain: Option, cx: &mut AsyncApp, diff --git a/crates/languages/src/rust.rs b/crates/languages/src/rust.rs index 3d5ff1cd06149594e54de03d454bef64483b7e47..ce73c70c0ceec4bdca4b19d7155a01e1f0940dcf 100644 --- a/crates/languages/src/rust.rs +++ b/crates/languages/src/rust.rs @@ -7,7 +7,6 @@ use http_client::github::AssetKind; use http_client::github::{GitHubLspBinaryVersion, latest_github_release}; pub use language::*; use lsp::{InitializeParams, LanguageServerBinary}; -use project::Fs; use project::lsp_store::rust_analyzer_ext::CARGO_DIAGNOSTICS_SOURCE_NAME; use project::project_settings::ProjectSettings; use regex::Regex; @@ -632,7 +631,6 @@ impl ContextProvider for RustContextProvider { fn associated_tasks( &self, - _: Arc, file: Option>, cx: &App, ) -> Task> { diff --git a/crates/languages/src/tailwind.rs b/crates/languages/src/tailwind.rs index af7653ea9e3059a40e0023e5d5d2ccd3c8b02556..1d8b3db212b62367354a333fa9f30a99efb8be1d 100644 --- a/crates/languages/src/tailwind.rs +++ b/crates/languages/src/tailwind.rs @@ -6,7 +6,7 @@ use gpui::AsyncApp; use language::{LanguageName, LspAdapter, LspAdapterDelegate, Toolchain}; use lsp::{LanguageServerBinary, LanguageServerName}; use node_runtime::{NodeRuntime, VersionStrategy}; -use project::{Fs, lsp_store::language_server_settings}; +use project::lsp_store::language_server_settings; use serde_json::{Value, json}; use smol::fs; use std::{ @@ -138,7 +138,6 @@ impl LspAdapter for TailwindLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { Ok(Some(json!({ @@ -154,7 +153,6 @@ impl LspAdapter for TailwindLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, delegate: &Arc, _: Option, cx: &mut AsyncApp, diff --git a/crates/languages/src/typescript.rs b/crates/languages/src/typescript.rs index d8f18f5f045f67e658a5458ee5db443f5c85d92e..8f9d362c0dff0bdb8e001155264f1e75f86f5172 100644 --- a/crates/languages/src/typescript.rs +++ b/crates/languages/src/typescript.rs @@ -27,8 +27,8 @@ use util::{ResultExt, fs::remove_matching, maybe}; use crate::{PackageJson, PackageJsonData, github_download::download_server_binary}; -#[derive(Debug)] pub(crate) struct TypeScriptContextProvider { + fs: Arc, last_package_json: PackageJsonContents, } @@ -253,8 +253,9 @@ impl PackageJsonData { } impl TypeScriptContextProvider { - pub fn new() -> Self { + pub fn new(fs: Arc) -> Self { Self { + fs, last_package_json: PackageJsonContents::default(), } } @@ -358,7 +359,6 @@ async fn detect_package_manager( impl ContextProvider for TypeScriptContextProvider { fn associated_tasks( &self, - fs: Arc, file: Option>, cx: &App, ) -> Task> { @@ -369,8 +369,12 @@ impl ContextProvider for TypeScriptContextProvider { return Task::ready(None); }; let file_relative_path = file.path().clone(); - let package_json_data = - self.combined_package_json_data(fs.clone(), &worktree_root, &file_relative_path, cx); + let package_json_data = self.combined_package_json_data( + self.fs.clone(), + &worktree_root, + &file_relative_path, + cx, + ); cx.background_spawn(async move { let mut task_templates = TaskTemplates(Vec::new()); @@ -514,6 +518,7 @@ fn replace_test_name_parameters(test_name: &str) -> String { } pub struct TypeScriptLspAdapter { + fs: Arc, node: NodeRuntime, } @@ -523,10 +528,10 @@ impl TypeScriptLspAdapter { const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("typescript-language-server"); const PACKAGE_NAME: &str = "typescript"; - pub fn new(node: NodeRuntime) -> Self { - TypeScriptLspAdapter { node } + pub fn new(node: NodeRuntime, fs: Arc) -> Self { + TypeScriptLspAdapter { fs, node } } - async fn tsdk_path(fs: &dyn Fs, adapter: &Arc) -> Option<&'static str> { + async fn tsdk_path(&self, adapter: &Arc) -> Option<&'static str> { let is_yarn = adapter .read_text_file(PathBuf::from(".yarn/sdks/typescript/lib/typescript.js")) .await @@ -538,7 +543,8 @@ impl TypeScriptLspAdapter { "node_modules/typescript/lib" }; - if fs + if self + .fs .is_dir(&adapter.worktree_root_path().join(tsdk_path)) .await { @@ -696,10 +702,9 @@ impl LspAdapter for TypeScriptLspAdapter { async fn initialization_options( self: Arc, - fs: &dyn Fs, adapter: &Arc, ) -> Result> { - let tsdk_path = Self::tsdk_path(fs, adapter).await; + let tsdk_path = self.tsdk_path(adapter).await; Ok(Some(json!({ "provideFormatter": true, "hostInfo": "zed", @@ -721,7 +726,7 @@ impl LspAdapter for TypeScriptLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, + delegate: &Arc, _: Option, cx: &mut AsyncApp, @@ -821,7 +826,6 @@ impl LspAdapter for EsLintLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, delegate: &Arc, _: Option, cx: &mut AsyncApp, @@ -1145,7 +1149,7 @@ mod tests { ) .await; - let provider = TypeScriptContextProvider::new(); + let provider = TypeScriptContextProvider::new(fs.clone()); let package_json_data = cx .update(|cx| { provider.combined_package_json_data( diff --git a/crates/languages/src/vtsls.rs b/crates/languages/src/vtsls.rs index 1cf3c8aa52db7bbfc1e784afecc62972884a3d47..32554fe651860a1db3732565fe163b702734e11c 100644 --- a/crates/languages/src/vtsls.rs +++ b/crates/languages/src/vtsls.rs @@ -21,6 +21,7 @@ fn typescript_server_binary_arguments(server_path: &Path) -> Vec { pub struct VtslsLspAdapter { node: NodeRuntime, + fs: Arc, } impl VtslsLspAdapter { @@ -30,11 +31,11 @@ impl VtslsLspAdapter { const TYPESCRIPT_PACKAGE_NAME: &'static str = "typescript"; const TYPESCRIPT_TSDK_PATH: &'static str = "node_modules/typescript/lib"; - pub fn new(node: NodeRuntime) -> Self { - VtslsLspAdapter { node } + pub fn new(node: NodeRuntime, fs: Arc) -> Self { + VtslsLspAdapter { node, fs } } - async fn tsdk_path(fs: &dyn Fs, adapter: &Arc) -> Option<&'static str> { + async fn tsdk_path(&self, adapter: &Arc) -> Option<&'static str> { let is_yarn = adapter .read_text_file(PathBuf::from(".yarn/sdks/typescript/lib/typescript.js")) .await @@ -46,7 +47,8 @@ impl VtslsLspAdapter { Self::TYPESCRIPT_TSDK_PATH }; - if fs + if self + .fs .is_dir(&adapter.worktree_root_path().join(tsdk_path)) .await { @@ -210,12 +212,11 @@ impl LspAdapter for VtslsLspAdapter { async fn workspace_configuration( self: Arc, - fs: &dyn Fs, delegate: &Arc, _: Option, cx: &mut AsyncApp, ) -> Result { - let tsdk_path = Self::tsdk_path(fs, delegate).await; + let tsdk_path = self.tsdk_path(delegate).await; let config = serde_json::json!({ "tsdk": tsdk_path, "suggest": { diff --git a/crates/languages/src/yaml.rs b/crates/languages/src/yaml.rs index bf634aafbab9fb3312f63fa818a55ddae90a05f3..39c30a3714332044eff137fd735fa53e07160070 100644 --- a/crates/languages/src/yaml.rs +++ b/crates/languages/src/yaml.rs @@ -5,7 +5,7 @@ use gpui::AsyncApp; use language::{LspAdapter, LspAdapterDelegate, Toolchain, language_settings::AllLanguageSettings}; use lsp::{LanguageServerBinary, LanguageServerName}; use node_runtime::{NodeRuntime, VersionStrategy}; -use project::{Fs, lsp_store::language_server_settings}; +use project::lsp_store::language_server_settings; use serde_json::Value; use settings::{Settings, SettingsLocation}; use smol::fs; @@ -132,7 +132,7 @@ impl LspAdapter for YamlLspAdapter { async fn workspace_configuration( self: Arc, - _: &dyn Fs, + delegate: &Arc, _: Option, cx: &mut AsyncApp, diff --git a/crates/markdown/Cargo.toml b/crates/markdown/Cargo.toml index b278ef1cd41817e7f442c1a904f5e8e0e8d3771a..9dfb3fdcd6c38f65357d93e5701cb0b72a6814a7 100644 --- a/crates/markdown/Cargo.toml +++ b/crates/markdown/Cargo.toml @@ -35,6 +35,7 @@ workspace-hack.workspace = true [dev-dependencies] assets.workspace = true env_logger.workspace = true +fs = {workspace = true, features = ["test-support"]} gpui = { workspace = true, features = ["test-support"] } languages = { workspace = true, features = ["load-grammars"] } node_runtime.workspace = true diff --git a/crates/markdown/examples/markdown.rs b/crates/markdown/examples/markdown.rs index c651c7921d4d92562e68bfea6cb1954132c215bc..c019bad1d081e59077bedb05cb36673a48f294bc 100644 --- a/crates/markdown/examples/markdown.rs +++ b/crates/markdown/examples/markdown.rs @@ -47,10 +47,11 @@ pub fn main() { let node_runtime = NodeRuntime::unavailable(); theme::init(LoadThemes::JustBase, cx); + let fs = fs::FakeFs::new(cx.background_executor().clone()); let language_registry = LanguageRegistry::new(cx.background_executor().clone()); language_registry.set_theme(cx.theme().clone()); let language_registry = Arc::new(language_registry); - languages::init(language_registry.clone(), node_runtime, cx); + languages::init(language_registry.clone(), fs, node_runtime, cx); Assets.load_fonts(cx).unwrap(); cx.activate(true); diff --git a/crates/markdown/examples/markdown_as_child.rs b/crates/markdown/examples/markdown_as_child.rs index 16c198601a31707602aea3dd250e3958c4c8f0fb..6c0960c88b3021b6012b769aef8ffb22050b1abd 100644 --- a/crates/markdown/examples/markdown_as_child.rs +++ b/crates/markdown/examples/markdown_as_child.rs @@ -30,7 +30,8 @@ pub fn main() { let node_runtime = NodeRuntime::unavailable(); let language_registry = Arc::new(LanguageRegistry::new(cx.background_executor().clone())); - languages::init(language_registry, node_runtime, cx); + let fs = fs::FakeFs::new(cx.background_executor().clone()); + languages::init(language_registry, fs, node_runtime, cx); theme::init(LoadThemes::JustBase, cx); Assets.load_fonts(cx).unwrap(); diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index 1ba5dc4f9001d577c9d4987bb7d01db117ded80b..e719c9e4fb1aee3d6b20e0a46f2bb28b252795d4 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -361,7 +361,7 @@ impl LocalLspStore { let adapter = adapter.clone(); let lsp_store = self.weak.clone(); let pending_workspace_folders = pending_workspace_folders.clone(); - let fs = self.fs.clone(); + let pull_diagnostics = ProjectSettings::get_global(cx) .diagnostics .lsp_pull_diagnostics @@ -372,7 +372,6 @@ impl LocalLspStore { let workspace_config = Self::workspace_configuration_for_adapter( adapter.adapter.clone(), - fs.as_ref(), &delegate, toolchain, cx, @@ -381,7 +380,6 @@ impl LocalLspStore { let mut initialization_options = Self::initialization_options_for_adapter( adapter.adapter.clone(), - fs.as_ref(), &delegate, ) .await?; @@ -403,7 +401,6 @@ impl LocalLspStore { Self::setup_lsp_messages( lsp_store.clone(), - fs, &language_server, delegate.clone(), adapter.clone(), @@ -568,7 +565,7 @@ impl LocalLspStore { fn setup_lsp_messages( this: WeakEntity, - fs: Arc, + language_server: &LanguageServer, delegate: Arc, adapter: Arc, @@ -623,12 +620,11 @@ impl LocalLspStore { let adapter = adapter.adapter.clone(); let delegate = delegate.clone(); let this = this.clone(); - let fs = fs.clone(); + move |params, cx| { let adapter = adapter.clone(); let delegate = delegate.clone(); let this = this.clone(); - let fs = fs.clone(); let mut cx = cx.clone(); async move { let toolchain_for_id = this @@ -642,7 +638,6 @@ impl LocalLspStore { .context("Expected the LSP store to be in a local mode")?; let workspace_config = Self::workspace_configuration_for_adapter( adapter.clone(), - fs.as_ref(), &delegate, toolchain_for_id, &mut cx, @@ -3370,11 +3365,10 @@ impl LocalLspStore { async fn initialization_options_for_adapter( adapter: Arc, - fs: &dyn Fs, delegate: &Arc, ) -> Result> { let Some(mut initialization_config) = - adapter.clone().initialization_options(fs, delegate).await? + adapter.clone().initialization_options(delegate).await? else { return Ok(None); }; @@ -3385,7 +3379,7 @@ impl LocalLspStore { } if let Ok(Some(target_config)) = other_adapter .clone() - .additional_initialization_options(adapter.name(), fs, delegate) + .additional_initialization_options(adapter.name(), delegate) .await { merge_json_value_into(target_config.clone(), &mut initialization_config); @@ -3395,20 +3389,15 @@ impl LocalLspStore { Ok(Some(initialization_config)) } - fn toolchain_store(&self) -> &Entity { - &self.toolchain_store - } - async fn workspace_configuration_for_adapter( adapter: Arc, - fs: &dyn Fs, delegate: &Arc, toolchain: Option, cx: &mut AsyncApp, ) -> Result { let mut workspace_config = adapter .clone() - .workspace_configuration(fs, delegate, toolchain, cx) + .workspace_configuration(delegate, toolchain, cx) .await?; for other_adapter in delegate.registered_lsp_adapters() { @@ -3417,7 +3406,7 @@ impl LocalLspStore { } if let Ok(Some(target_config)) = other_adapter .clone() - .additional_workspace_configuration(adapter.name(), fs, delegate, cx) + .additional_workspace_configuration(adapter.name(), delegate, cx) .await { merge_json_value_into(target_config.clone(), &mut workspace_config); @@ -3705,10 +3694,7 @@ impl LspStore { let _maintain_workspace_config = { let (sender, receiver) = watch::channel(); - ( - Self::maintain_workspace_config(fs.clone(), receiver, cx), - sender, - ) + (Self::maintain_workspace_config(receiver, cx), sender) }; Self { @@ -3795,7 +3781,6 @@ impl LspStore { languages: Arc, upstream_client: AnyProtoClient, project_id: u64, - fs: Arc, cx: &mut Context, ) -> Self { cx.subscribe(&buffer_store, Self::on_buffer_store_event) @@ -3805,7 +3790,7 @@ impl LspStore { subscribe_to_binary_statuses(&languages, cx).detach(); let _maintain_workspace_config = { let (sender, receiver) = watch::channel(); - (Self::maintain_workspace_config(fs, receiver, cx), sender) + (Self::maintain_workspace_config(receiver, cx), sender) }; Self { mode: LspStoreMode::Remote(RemoteLspStore { @@ -4045,19 +4030,11 @@ impl LspStore { return; }; - let Ok(Some((fs, _))) = this.read_with(cx, |this, _| { - let local = this.as_local()?; - let toolchain_store = local.toolchain_store().clone(); - Some((local.fs.clone(), toolchain_store)) - }) else { - return; - }; for (adapter, server, delegate) in servers { adapter.clear_zed_json_schema_cache().await; let Some(json_workspace_config) = LocalLspStore::workspace_configuration_for_adapter( adapter, - fs.as_ref(), &delegate, None, cx, @@ -7358,11 +7335,7 @@ impl LspStore { None } - async fn refresh_workspace_configurations( - lsp_store: &WeakEntity, - fs: Arc, - cx: &mut AsyncApp, - ) { + async fn refresh_workspace_configurations(lsp_store: &WeakEntity, cx: &mut AsyncApp) { maybe!(async move { let mut refreshed_servers = HashSet::default(); let servers = lsp_store @@ -7398,8 +7371,6 @@ impl LspStore { LanguageServerState::Running { adapter, server, .. } => { - let fs = fs.clone(); - let adapter = adapter.clone(); let server = server.clone(); refreshed_servers.insert(server.name()); @@ -7408,7 +7379,6 @@ impl LspStore { let settings = LocalLspStore::workspace_configuration_for_adapter( adapter.adapter.clone(), - fs.as_ref(), &delegate, toolchain, cx, @@ -7445,7 +7415,6 @@ impl LspStore { } fn maintain_workspace_config( - fs: Arc, external_refresh_requests: watch::Receiver<()>, cx: &mut Context, ) -> Task> { @@ -7471,7 +7440,7 @@ impl LspStore { }) .ok(); - Self::refresh_workspace_configurations(&this, fs.clone(), cx).await; + Self::refresh_workspace_configurations(&this, cx).await; } drop(settings_observation); @@ -12618,7 +12587,6 @@ impl LspAdapter for SshLspAdapter { async fn initialization_options( self: Arc, - _: &dyn Fs, _: &Arc, ) -> Result> { let Some(options) = &self.initialization_options else { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 1ef3de7a166b785de7799269548cbddf7202ad0d..b39e84e7c0816e944fb6d97ead9015b796dc1aef 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1132,7 +1132,6 @@ impl Project { let task_store = cx.new(|cx| { TaskStore::local( - fs.clone(), buffer_store.downgrade(), worktree_store.clone(), toolchain_store.read(cx).as_language_toolchain_store(), @@ -1290,7 +1289,6 @@ impl Project { }); let task_store = cx.new(|cx| { TaskStore::remote( - fs.clone(), buffer_store.downgrade(), worktree_store.clone(), toolchain_store.read(cx).as_language_toolchain_store(), @@ -1321,7 +1319,6 @@ impl Project { languages.clone(), remote_proto.clone(), REMOTE_SERVER_PROJECT_ID, - fs.clone(), cx, ) }); @@ -1540,7 +1537,6 @@ impl Project { languages.clone(), client.clone().into(), remote_id, - fs.clone(), cx, ) })?; @@ -1548,7 +1544,6 @@ impl Project { let task_store = cx.new(|cx| { if run_tasks { TaskStore::remote( - fs.clone(), buffer_store.downgrade(), worktree_store.clone(), Arc::new(EmptyToolchainStore), diff --git a/crates/project/src/task_inventory.rs b/crates/project/src/task_inventory.rs index 20dce218f4a4bd7c45a85d56110ec2b69c84391a..818a5c58cff7a57705a6498581e62f010ff6dcf9 100644 --- a/crates/project/src/task_inventory.rs +++ b/crates/project/src/task_inventory.rs @@ -11,7 +11,6 @@ use std::{ use anyhow::Result; use collections::{HashMap, HashSet, VecDeque}; use dap::DapRegistry; -use fs::Fs; use gpui::{App, AppContext as _, Context, Entity, SharedString, Task, WeakEntity}; use itertools::Itertools; use language::{ @@ -40,7 +39,6 @@ pub struct DebugScenarioContext { /// Inventory tracks available tasks for a given project. pub struct Inventory { - fs: Arc, last_scheduled_tasks: VecDeque<(TaskSourceKind, ResolvedTask)>, last_scheduled_scenarios: VecDeque<(DebugScenario, DebugScenarioContext)>, templates_from_settings: InventoryFor, @@ -242,9 +240,8 @@ impl TaskSourceKind { } impl Inventory { - pub fn new(fs: Arc, cx: &mut App) -> Entity { + pub fn new(cx: &mut App) -> Entity { cx.new(|_| Self { - fs, last_scheduled_tasks: VecDeque::default(), last_scheduled_scenarios: VecDeque::default(), templates_from_settings: InventoryFor::default(), @@ -387,7 +384,6 @@ impl Inventory { cx: &App, ) -> Task> { let global_tasks = self.global_templates_from_settings().collect::>(); - let fs = self.fs.clone(); let mut worktree_tasks = worktree .into_iter() .flat_map(|worktree| self.worktree_templates_from_settings(worktree)) @@ -404,7 +400,7 @@ impl Inventory { .and_then(|language| { language .context_provider() - .map(|provider| provider.associated_tasks(fs, file, cx)) + .map(|provider| provider.associated_tasks(file, cx)) }); cx.background_spawn(async move { if let Some(t) = language_tasks { @@ -432,7 +428,6 @@ impl Inventory { Vec<(TaskSourceKind, ResolvedTask)>, Vec<(TaskSourceKind, ResolvedTask)>, )> { - let fs = self.fs.clone(); let worktree = task_contexts.worktree(); let location = task_contexts.location(); let language = location.and_then(|location| location.buffer.read(cx).language()); @@ -489,7 +484,7 @@ impl Inventory { .and_then(|language| { language .context_provider() - .map(|provider| provider.associated_tasks(fs, file, cx)) + .map(|provider| provider.associated_tasks(file, cx)) }); let worktree_tasks = worktree .into_iter() @@ -1088,19 +1083,13 @@ impl ContextProviderWithTasks { } impl ContextProvider for ContextProviderWithTasks { - fn associated_tasks( - &self, - _: Arc, - _: Option>, - _: &App, - ) -> Task> { + fn associated_tasks(&self, _: Option>, _: &App) -> Task> { Task::ready(Some(self.templates.clone())) } } #[cfg(test)] mod tests { - use fs::FakeFs; use gpui::TestAppContext; use paths::tasks_file; use pretty_assertions::assert_eq; @@ -1115,8 +1104,7 @@ mod tests { #[gpui::test] async fn test_task_list_sorting(cx: &mut TestAppContext) { init_test(cx); - let fs = FakeFs::new(cx.executor()); - let inventory = cx.update(|cx| Inventory::new(fs, cx)); + let inventory = cx.update(|cx| Inventory::new(cx)); let initial_tasks = resolved_task_names(&inventory, None, cx).await; assert!( initial_tasks.is_empty(), @@ -1296,8 +1284,7 @@ mod tests { #[gpui::test] async fn test_reloading_debug_scenarios(cx: &mut TestAppContext) { init_test(cx); - let fs = FakeFs::new(cx.executor()); - let inventory = cx.update(|cx| Inventory::new(fs, cx)); + let inventory = cx.update(|cx| Inventory::new(cx)); inventory.update(cx, |inventory, _| { inventory .update_file_based_scenarios( @@ -1406,8 +1393,7 @@ mod tests { #[gpui::test] async fn test_inventory_static_task_filters(cx: &mut TestAppContext) { init_test(cx); - let fs = FakeFs::new(cx.executor()); - let inventory = cx.update(|cx| Inventory::new(fs, cx)); + let inventory = cx.update(|cx| Inventory::new(cx)); let common_name = "common_task_name"; let worktree_1 = WorktreeId::from_usize(1); let worktree_2 = WorktreeId::from_usize(2); diff --git a/crates/project/src/task_store.rs b/crates/project/src/task_store.rs index ae49ce5b4d708171e28ef6ade5b05267638c6a31..6a62209b54e999ab7c3fca11fe6344bd3b5955fa 100644 --- a/crates/project/src/task_store.rs +++ b/crates/project/src/task_store.rs @@ -159,7 +159,6 @@ impl TaskStore { } pub fn local( - fs: Arc, buffer_store: WeakEntity, worktree_store: Entity, toolchain_store: Arc, @@ -171,7 +170,7 @@ impl TaskStore { downstream_client: None, environment, }, - task_inventory: Inventory::new(fs, cx), + task_inventory: Inventory::new(cx), buffer_store, toolchain_store, worktree_store, @@ -179,7 +178,6 @@ impl TaskStore { } pub fn remote( - fs: Arc, buffer_store: WeakEntity, worktree_store: Entity, toolchain_store: Arc, @@ -192,7 +190,7 @@ impl TaskStore { upstream_client, project_id, }, - task_inventory: Inventory::new(fs, cx), + task_inventory: Inventory::new(cx), buffer_store, toolchain_store, worktree_store, diff --git a/crates/remote_server/src/headless_project.rs b/crates/remote_server/src/headless_project.rs index bdfd46002e63069b68b5661f1733060818a291e7..f107ff2c8f8860a621ad5c637e6fa34b54734a6d 100644 --- a/crates/remote_server/src/headless_project.rs +++ b/crates/remote_server/src/headless_project.rs @@ -85,7 +85,7 @@ impl HeadlessProject { cx: &mut Context, ) -> Self { debug_adapter_extension::init(proxy.clone(), cx); - languages::init(languages.clone(), node_runtime.clone(), cx); + languages::init(languages.clone(), fs.clone(), node_runtime.clone(), cx); let worktree_store = cx.new(|cx| { let mut store = WorktreeStore::local(true, fs.clone()); @@ -153,7 +153,6 @@ impl HeadlessProject { let task_store = cx.new(|cx| { let mut task_store = TaskStore::local( - fs.clone(), buffer_store.downgrade(), worktree_store.clone(), toolchain_store.read(cx).as_language_toolchain_store(), diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index b5dbbba865d0a7e9578f6d0f1b7d193e372cd7af..63ee30043b61fd55af2edad7cd4a7a407af743bd 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -460,7 +460,7 @@ pub fn main() { debug_adapter_extension::init(extension_host_proxy.clone(), cx); language::init(cx); - languages::init(languages.clone(), node_runtime.clone(), cx); + languages::init(languages.clone(), fs.clone(), node_runtime.clone(), cx); let user_store = cx.new(|cx| UserStore::new(client.clone(), cx)); let workspace_store = cx.new(|cx| WorkspaceStore::new(client.clone(), cx)); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 0041bba6d0537d739363a451cc5e0683de9ba6e2..49a803e1ee7bdd247584fd218b278554598be33d 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -4589,6 +4589,7 @@ mod tests { #[gpui::test] async fn test_bundled_languages(cx: &mut TestAppContext) { + let fs = fs::FakeFs::new(cx.background_executor.clone()); env_logger::builder().is_test(true).try_init().ok(); let settings = cx.update(SettingsStore::test); cx.set_global(settings); @@ -4596,7 +4597,7 @@ mod tests { let languages = Arc::new(languages); let node_runtime = node_runtime::NodeRuntime::unavailable(); cx.update(|cx| { - languages::init(languages.clone(), node_runtime, cx); + languages::init(languages.clone(), fs, node_runtime, cx); }); for name in languages.language_names() { languages diff --git a/crates/zeta_cli/src/headless.rs b/crates/zeta_cli/src/headless.rs index cfa7d606bababb4509bdaa6fc4d1fbf4e0c9112d..a11fd707591d0403409b5bc9e243d35c70fd65d3 100644 --- a/crates/zeta_cli/src/headless.rs +++ b/crates/zeta_cli/src/headless.rs @@ -110,7 +110,7 @@ pub fn init(cx: &mut App) -> ZetaCliAppState { language_extension::init(LspAccess::Noop, extension_host_proxy, languages.clone()); language_model::init(client.clone(), cx); language_models::init(user_store.clone(), client.clone(), cx); - languages::init(languages.clone(), node_runtime.clone(), cx); + languages::init(languages.clone(), fs.clone(), node_runtime.clone(), cx); prompt_store::init(cx); terminal_view::init(cx);