@@ -985,6 +985,10 @@ impl ContextProvider for BasicContextProvider {
task_variables.insert(VariableName::File, path.to_string_lossy().into_owned());
}
+ if let Some(language) = buffer.language() {
+ task_variables.insert(VariableName::Language, language.name().to_string());
+ }
+
Task::ready(Ok(task_variables))
}
}
@@ -172,6 +172,8 @@ pub enum VariableName {
Column,
/// Text from the latest selection.
SelectedText,
+ /// The language of the currently opened buffer (e.g., "Rust", "Python").
+ Language,
/// The symbol selected by the symbol tagging system, specifically the @run capture in a runnables.scm
RunnableSymbol,
/// Open a Picker to select a process ID to use in place
@@ -209,6 +211,7 @@ impl FromStr for VariableName {
"SYMBOL" => Self::Symbol,
"RUNNABLE_SYMBOL" => Self::RunnableSymbol,
"SELECTED_TEXT" => Self::SelectedText,
+ "LANGUAGE" => Self::Language,
"ROW" => Self::Row,
"COLUMN" => Self::Column,
_ => {
@@ -243,6 +246,7 @@ impl std::fmt::Display for VariableName {
Self::Row => write!(f, "{ZED_VARIABLE_NAME_PREFIX}ROW"),
Self::Column => write!(f, "{ZED_VARIABLE_NAME_PREFIX}COLUMN"),
Self::SelectedText => write!(f, "{ZED_VARIABLE_NAME_PREFIX}SELECTED_TEXT"),
+ Self::Language => write!(f, "{ZED_VARIABLE_NAME_PREFIX}LANGUAGE"),
Self::RunnableSymbol => write!(f, "{ZED_VARIABLE_NAME_PREFIX}RUNNABLE_SYMBOL"),
Self::PickProcessId => write!(f, "{ZED_VARIABLE_NAME_PREFIX}PICK_PID"),
Self::Custom(s) => write!(
@@ -439,7 +439,10 @@ mod tests {
let worktree_store = project.read_with(cx, |project, _| project.worktree_store());
let rust_language = Arc::new(
Language::new(
- LanguageConfig::default(),
+ LanguageConfig {
+ name: "Rust".into(),
+ ..Default::default()
+ },
Some(tree_sitter_rust::LANGUAGE.into()),
)
.with_outline_query(
@@ -455,7 +458,10 @@ mod tests {
let typescript_language = Arc::new(
Language::new(
- LanguageConfig::default(),
+ LanguageConfig {
+ name: "TypeScript".into(),
+ ..Default::default()
+ },
Some(tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into()),
)
.with_outline_query(
@@ -534,6 +540,7 @@ mod tests {
(VariableName::WorktreeRoot, path!("/dir").into()),
(VariableName::Row, "1".into()),
(VariableName::Column, "1".into()),
+ (VariableName::Language, "Rust".into()),
]),
project_env: HashMap::default(),
}
@@ -568,6 +575,7 @@ mod tests {
(VariableName::Column, "15".into()),
(VariableName::SelectedText, "is_i".into()),
(VariableName::Symbol, "this_is_a_rust_file".into()),
+ (VariableName::Language, "Rust".into()),
]),
project_env: HashMap::default(),
}
@@ -596,6 +604,7 @@ mod tests {
(VariableName::Row, "1".into()),
(VariableName::Column, "1".into()),
(VariableName::Symbol, "this_is_a_test".into()),
+ (VariableName::Language, "TypeScript".into()),
]),
project_env: HashMap::default(),
}
@@ -89,6 +89,7 @@ These variables allow you to pull information from the current editor and use it
- `ZED_STEM`: stem (filename without extension) of the currently opened file (e.g. `main`)
- `ZED_SYMBOL`: currently selected symbol; should match the last symbol shown in a symbol breadcrumb (e.g. `mod tests > fn test_task_contexts`)
- `ZED_SELECTED_TEXT`: currently selected text
+- `ZED_LANGUAGE`: language of the currently opened buffer (e.g. `Rust`, `Python`, `Shell Script`)
- `ZED_WORKTREE_ROOT`: absolute path to the root of the current worktree. (e.g. `/Users/my-user/path/to/project`)
- `ZED_CUSTOM_RUST_PACKAGE`: (Rust-specific) name of the parent package of $ZED_FILE source file.