1use std::{ops::Range, path::PathBuf, sync::Arc};
 2
 3use crate::{File, LanguageToolchainStore, Location, Runnable};
 4
 5use anyhow::Result;
 6use collections::HashMap;
 7use fs::Fs;
 8use gpui::{App, Task};
 9use lsp::LanguageServerName;
10use task::{TaskTemplates, TaskVariables};
11use text::BufferId;
12
13pub struct RunnableRange {
14    pub buffer_id: BufferId,
15    pub run_range: Range<usize>,
16    pub full_range: Range<usize>,
17    pub runnable: Runnable,
18    pub extra_captures: HashMap<String, String>,
19}
20
21/// Language Contexts are used by Zed tasks to extract information about the source file where the tasks are supposed to be scheduled from.
22/// Multiple context providers may be used together: by default, Zed provides a base [`BasicContextProvider`] context that fills all non-custom [`VariableName`] variants.
23///
24/// The context will be used to fill data for the tasks, and filter out the ones that do not have the variables required.
25pub trait ContextProvider: Send + Sync {
26    /// 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.
27    fn build_context(
28        &self,
29        _variables: &TaskVariables,
30        _location: ContextLocation<'_>,
31        _project_env: Option<HashMap<String, String>>,
32        _toolchains: Arc<dyn LanguageToolchainStore>,
33        _cx: &mut App,
34    ) -> Task<Result<TaskVariables>> {
35        let _ = _location;
36        Task::ready(Ok(TaskVariables::default()))
37    }
38
39    /// Provides all tasks, associated with the current language.
40    fn associated_tasks(&self, _: Option<Arc<dyn File>>, _: &App) -> Task<Option<TaskTemplates>> {
41        Task::ready(None)
42    }
43
44    /// A language server name, that can return tasks using LSP (ext) for this language.
45    fn lsp_task_source(&self) -> Option<LanguageServerName> {
46        None
47    }
48}
49
50/// Metadata about the place in the project we gather the context for.
51pub struct ContextLocation<'a> {
52    pub fs: Option<Arc<dyn Fs>>,
53    pub worktree_root: Option<PathBuf>,
54    pub file_location: &'a Location,
55}