languages: Pass fs into the init function (#38007)

Release Notes:

- N/A

---------

Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
Piotr Osiewicz
2025-09-11 19:00:51 +00:00
committed by GitHub
co-authored by Cole Miller
parent 46aa05e240
commit 3cb3f01406
26 changed files with 75 additions and 150 deletions
+11 -43
View File
@@ -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<LspStore>,
fs: Arc<dyn Fs>,
language_server: &LanguageServer,
delegate: Arc<dyn LspAdapterDelegate>,
adapter: Arc<CachedLspAdapter>,
@@ -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<dyn LspAdapter>,
fs: &dyn Fs,
delegate: &Arc<dyn LspAdapterDelegate>,
) -> Result<Option<serde_json::Value>> {
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<LocalToolchainStore> {
&self.toolchain_store
}
async fn workspace_configuration_for_adapter(
adapter: Arc<dyn LspAdapter>,
fs: &dyn Fs,
delegate: &Arc<dyn LspAdapterDelegate>,
toolchain: Option<Toolchain>,
cx: &mut AsyncApp,
) -> Result<serde_json::Value> {
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<LanguageRegistry>,
upstream_client: AnyProtoClient,
project_id: u64,
fs: Arc<dyn Fs>,
cx: &mut Context<Self>,
) -> 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<Self>,
fs: Arc<dyn Fs>,
cx: &mut AsyncApp,
) {
async fn refresh_workspace_configurations(lsp_store: &WeakEntity<Self>, 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<dyn Fs>,
external_refresh_requests: watch::Receiver<()>,
cx: &mut Context<Self>,
) -> Task<Result<()>> {
@@ -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<Self>,
_: &dyn Fs,
_: &Arc<dyn LspAdapterDelegate>,
) -> Result<Option<serde_json::Value>> {
let Some(options) = &self.initialization_options else {
-5
View File
@@ -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),
+7 -21
View File
@@ -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<dyn Fs>,
last_scheduled_tasks: VecDeque<(TaskSourceKind, ResolvedTask)>,
last_scheduled_scenarios: VecDeque<(DebugScenario, DebugScenarioContext)>,
templates_from_settings: InventoryFor<TaskTemplate>,
@@ -242,9 +240,8 @@ impl TaskSourceKind {
}
impl Inventory {
pub fn new(fs: Arc<dyn Fs>, cx: &mut App) -> Entity<Self> {
pub fn new(cx: &mut App) -> Entity<Self> {
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<Vec<(TaskSourceKind, TaskTemplate)>> {
let global_tasks = self.global_templates_from_settings().collect::<Vec<_>>();
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<dyn Fs>,
_: Option<Arc<dyn File>>,
_: &App,
) -> Task<Option<TaskTemplates>> {
fn associated_tasks(&self, _: Option<Arc<dyn File>>, _: &App) -> Task<Option<TaskTemplates>> {
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);
+2 -4
View File
@@ -159,7 +159,6 @@ impl TaskStore {
}
pub fn local(
fs: Arc<dyn Fs>,
buffer_store: WeakEntity<BufferStore>,
worktree_store: Entity<WorktreeStore>,
toolchain_store: Arc<dyn LanguageToolchainStore>,
@@ -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<dyn Fs>,
buffer_store: WeakEntity<BufferStore>,
worktree_store: Entity<WorktreeStore>,
toolchain_store: Arc<dyn LanguageToolchainStore>,
@@ -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,