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