Skip to content

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

Merged
SomeoneToIgnore merged 3 commits intozed-industries:mainfrom
mvanhorn:osc/12628-task-language-variable
Mar 17, 2026
Merged

task: Expose current buffer language as $ZED_LANGUAGE variable#51614
SomeoneToIgnore merged 3 commits intozed-industries:mainfrom
mvanhorn:osc/12628-task-language-variable

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

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

Closes zed-industries#12628

Add a Language variant to VariableName that resolves to the language
name of the active buffer. Populated from buffer.language().name()
in BasicContextProvider::build_context, following the same pattern
as existing variables like File and Stem.

Release Notes:

- Added `$ZED_LANGUAGE` task variable that exposes the current buffer's language name
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 15, 2026
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 15, 2026
Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@SomeoneToIgnore SomeoneToIgnore enabled auto-merge (squash) March 17, 2026 10:41
Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, sorry, one more thing that's needed is an adjustment in tasks.md, could you do that?

@mvanhorn
Copy link
Copy Markdown
Contributor Author

Applied the language.name().to_string() suggestion in the "Tidy up" commit. The tasks.md update is already included in this PR (line 92) - added ZED_LANGUAGE to the variables list. Is there something else you'd like adjusted there?

@SomeoneToIgnore
Copy link
Copy Markdown
Contributor

Indeed, thanks, then — just the last test fix, the one that fails in CI.

…onfig

The test was using LanguageConfig::default() which has an empty language
name, so $ZED_LANGUAGE was always "". Set the name field to "Rust" and
"TypeScript" to match the expected test assertions.
@SomeoneToIgnore SomeoneToIgnore merged commit 83adaa5 into zed-industries:main Mar 17, 2026
29 checks passed
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Test fix pushed in the latest commit - CI is green across all platforms now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a current buffer language variable in task

2 participants