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
+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);