diff --git a/crates/project/src/task_inventory.rs b/crates/project/src/task_inventory.rs index af48841b26cfdd..a27e6a8461b1e6 100644 --- a/crates/project/src/task_inventory.rs +++ b/crates/project/src/task_inventory.rs @@ -18,7 +18,7 @@ use language::{ language_settings::LanguageSettings, }; use lsp::{LanguageServerId, LanguageServerName}; -use paths::{debug_task_file_name, task_file_name}; +use paths::{debug_task_file_name, extensions_dir, task_file_name}; use settings::{InvalidSettingsError, parse_json_with_comments}; use task::{ DebugScenario, ResolvedTask, SharedTaskContext, TaskContext, TaskHook, TaskId, TaskTemplate, @@ -1125,6 +1125,11 @@ impl ContextProvider for BasicContextProvider { task_variables.insert(VariableName::Language, language.name().to_string()); } + task_variables.insert( + VariableName::ExtensionWorkDir, + extensions_dir().join("work").to_string_lossy().into_owned(), + ); + Task::ready(Ok(task_variables)) } } diff --git a/crates/task/src/task.rs b/crates/task/src/task.rs index 37dc3d7556b888..968ab92c6290fc 100644 --- a/crates/task/src/task.rs +++ b/crates/task/src/task.rs @@ -195,6 +195,8 @@ pub enum VariableName { GitRepositoryPath, /// Name of the Git ref (branch, remote ref, or tag) associated with the task context. GitRef, + /// Absolute path of the Zed extensions work directory + ExtensionWorkDir, /// Custom variable, provided by the plugin or other external source. /// Will be printed with `CUSTOM_` prefix to avoid potential conflicts with other variables. Custom(Cow<'static, str>), @@ -236,6 +238,7 @@ impl FromStr for VariableName { "GIT_REPOSITORY_NAME" => Self::GitRepositoryName, "GIT_REPOSITORY_PATH" => Self::GitRepositoryPath, "GIT_REF" => Self::GitRef, + "EXTENSION_WORK_DIR" => Self::ExtensionWorkDir, _ => { if let Some(custom_name) = without_prefix.strip_prefix(ZED_CUSTOM_VARIABLE_NAME_PREFIX) @@ -277,6 +280,7 @@ impl std::fmt::Display for VariableName { Self::GitRepositoryName => write!(f, "{ZED_VARIABLE_NAME_PREFIX}GIT_REPOSITORY_NAME"), Self::GitRepositoryPath => write!(f, "{ZED_VARIABLE_NAME_PREFIX}GIT_REPOSITORY_PATH"), Self::GitRef => write!(f, "{ZED_VARIABLE_NAME_PREFIX}GIT_REF"), + Self::ExtensionWorkDir => write!(f, "{ZED_VARIABLE_NAME_PREFIX}EXTENSION_WORK_DIR"), Self::Custom(s) => write!( f, "{ZED_VARIABLE_NAME_PREFIX}{ZED_CUSTOM_VARIABLE_NAME_PREFIX}{s}" diff --git a/docs/src/tasks.md b/docs/src/tasks.md index fa7996712786f1..f8b038c3d6d6e2 100644 --- a/docs/src/tasks.md +++ b/docs/src/tasks.md @@ -98,6 +98,7 @@ These variables allow you to pull information from the current editor and use it - `ZED_WORKTREE_ROOT`: absolute path to the root of the current worktree. (e.g. `/Users/my-user/path/to/project`) - `ZED_MAIN_GIT_WORKTREE`: absolute path to the main git worktree's working directory. For normal checkouts this equals `ZED_WORKTREE_ROOT`; for linked git worktrees this is the original repository's working directory. - `ZED_CUSTOM_RUST_PACKAGE`: (Rust-specific) name of the parent package of $ZED_FILE source file. +- `ZED_EXTENSION_WORK_DIR`: the absolute path to the Zed extension work directory To use a variable in a task, prefix it with a dollar sign (`$`):