# task: Expose current buffer language as $ZED_LANGUAGE variable \(\#51614\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/83adaa52b3ebf5db595c29ec7c978342a96c6120)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 83adaa52b3ebf5db595c29ec7c978342a96c6120

Requested commit: 83adaa52b3ebf5db595c29ec7c978342a96c6120

Commit: 83adaa52b3ebf5db595c29ec7c978342a96c6120

Tree: a52687ff997cebad922ad31ce4629ce189367dc3

Author: Matt Van Horn

Committer: GitHub

## Message

```
task: Expose current buffer language as $ZED_LANGUAGE variable (#51614)

Closes #12628

Adds a `$ZED_LANGUAGE` task variable that resolves to the language name
of the active buffer (e.g., "Rust", "Python", "Shell Script"). This lets
tasks adapt behavior based on language without parsing file extensions.

Use cases from the issue:
- Pass syntax highlighting language to external tools (e.g., `rg --type
$ZED_LANGUAGE`)
- Adjust comment wrapping width per language
- Handle extensionless files and untitled buffers that have a language
assigned

VS Code provides equivalent functionality via
`${command:activeEditorLanguageId}`. Neovim exposes it as `&filetype`.

## Changes

- Added `Language` variant to `VariableName` in
`crates/task/src/task.rs`
- Populated from `buffer.language().name()` in
`BasicContextProvider::build_context`
(`crates/project/src/task_inventory.rs`), following the same pattern as
`File` and `Stem`
- Updated test fixtures in `crates/tasks_ui/src/tasks_ui.rs` to include
the new variable
- Added `ZED_LANGUAGE` to the variable list in `docs/src/tasks.md`

## Testing

Updated the existing `test_task_variables` test in `tasks_ui` to verify
`ZED_LANGUAGE` resolves to "Rust" and "TypeScript" for the respective
test buffers.

This contribution was developed with AI assistance (Claude Code).

Release Notes:

- Added `$ZED_LANGUAGE` task variable that exposes the current buffer's
language name

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
```

## Parents

- [546c70aeca9d7c6948a7eb1277c0b761235aeb1c](https://git.cafe/gitcafe/zed/commit/546c70aeca9d7c6948a7eb1277c0b761235aeb1c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/83adaa52b3ebf5db595c29ec7c978342a96c6120?format=markdown)
