task_context.rs

 1use std::{ops::Range, sync::Arc};
 2
 3use crate::{LanguageToolchainStore, Location, Runnable};
 4
 5use anyhow::Result;
 6use collections::HashMap;
 7use gpui::{App, Task};
 8use task::{TaskTemplates, TaskVariables};
 9use text::BufferId;
10
11pub struct RunnableRange {
12    pub buffer_id: BufferId,
13    pub run_range: Range<usize>,
14    pub full_range: Range<usize>,
15    pub runnable: Runnable,
16    pub extra_captures: HashMap<String, String>,
17}
18/// Language Contexts are used by Zed tasks to extract information about the source file where the tasks are supposed to be scheduled from.
19/// Multiple context providers may be used together: by default, Zed provides a base [`BasicContextProvider`] context that fills all non-custom [`VariableName`] variants.
20///
21/// The context will be used to fill data for the tasks, and filter out the ones that do not have the variables required.
22pub trait ContextProvider: Send + Sync {
23    /// Builds a specific context to be placed on top of the basic one (replacing all conflicting entries) and to be used for task resolving later.
24    fn build_context(
25        &self,
26        _variables: &TaskVariables,
27        _location: &Location,
28        _project_env: Option<HashMap<String, String>>,
29        _toolchains: Arc<dyn LanguageToolchainStore>,
30        _cx: &mut App,
31    ) -> Task<Result<TaskVariables>> {
32        Task::ready(Ok(TaskVariables::default()))
33    }
34
35    /// Provides all tasks, associated with the current language.
36    fn associated_tasks(
37        &self,
38        _: Option<Arc<dyn crate::File>>,
39        _cx: &App,
40    ) -> Option<TaskTemplates> {
41        None
42    }
43}