project: Re-resolve recent tasks against current editor context - #57380
Conversation
Fixes $ZED_FILE and other task variables remaining stale when reusing a recently-spawned task from the task picker after switching the active editor.
tasks.json: "Run current file" and "Compile with Options" now invoke autoit-run instead of AutoIt3.exe directly. autoit-run is a console-subsystem wrapper that spawns AutoIt3.exe with a real pipe, streaming ConsoleWrite() output to Zed's terminal line-by-line. Discovery: Get-Command (PATH) first, then HKCU\SOFTWARE\zed-autoit\RunnerPath written by autoit-lsp.exe at startup. README: add Limitations note about task rerun using cached $ZED_FILE, pointing at zed-industries/zed#57380 (open upstream fix) with the task:spawn workaround. Update robot.png. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
I think the change is good. Let's factor out the task context resolution to make it clearer; and fix the One thing I'm not sure about is fi we can re-use the active item context if the active item has changed (though maybe that is important). Either way it'd be good to add a test for the new behavior so it doesn't regress. |
Extract the inline context-resolution chain into a documented TaskContexts::reresolve_task helper, and add unit tests covering active item precedence, worktree scoping, and the fallback to the original task.
|
Hey @ConradIrwin, |
|
Thanks! |
Head branch was pushed to by a user without write access
|
Hi @ConradIrwin, The run_tests failure was tasks_ui::modal::tests::test_language_task_filtering, re-resolution was rewriting history task labels against the current file's context. Fixed by keeping the original label when re-resolution changes it. Verified locally. Mind re-running the workflow? Thanks! |
|
@zed-industries/approved |
…industries#57380) ## Summary Closes zed-industries#55879. When a task is run, its fully-resolved form (`ResolvedTask`, with `$ZED_FILE`/`$ZED_STEM`/`$ZED_COLUMN`/etc. already substituted) is cached in `Inventory::last_scheduled_tasks`. The next time the task picker is opened, `used_and_current_resolved_tasks` returns those cached entries as-is for the "recent" section. The "current" section *is* re-resolved against the active editor, but the label-based dedup keeps the stale recent entry. The result is that `$ZED_FILE` keeps pointing at the file that was active the first time the task ran, even after switching editors and re-running from the picker. This fix re-resolves each entry in the recent-tasks list against the current `TaskContexts` using the same context-pick chain the "current" branch already uses (item context → active worktree → other worktree → default). If re-resolution fails for any reason, we fall back to the cached `ResolvedTask` so behavior never regresses. The change is localized to `previously_spawned_tasks` inside `used_and_current_resolved_tasks`. List order, dedup, and LRU scoring are unchanged — only the variable substitutions inside each `ResolvedTask` are refreshed. ## Test plan - [x] Open a project with two source files (e.g. `1.cpp`, `2.cpp`) and a task that uses `$ZED_FILE` (e.g. `g++ $ZED_FILE -o $ZED_STEM && ./$ZED_STEM`). - [x] Open `1.cpp`, run the task from the picker, confirm it compiles `1.cpp`. - [x] Click `2.cpp`, open the task picker, pick the same task from the "recent" section, confirm it now compiles `2.cpp` (previously: still `1.cpp`). - [x] Confirm the recent-task ordering and divider in the picker are unchanged. Release Notes: - Fixed task variables like `$ZED_FILE` not updating when re-running a recently used task after switching the active editor (zed-industries#55879).
…industries#57380) ## Summary Closes zed-industries#55879. When a task is run, its fully-resolved form (`ResolvedTask`, with `$ZED_FILE`/`$ZED_STEM`/`$ZED_COLUMN`/etc. already substituted) is cached in `Inventory::last_scheduled_tasks`. The next time the task picker is opened, `used_and_current_resolved_tasks` returns those cached entries as-is for the "recent" section. The "current" section *is* re-resolved against the active editor, but the label-based dedup keeps the stale recent entry. The result is that `$ZED_FILE` keeps pointing at the file that was active the first time the task ran, even after switching editors and re-running from the picker. This fix re-resolves each entry in the recent-tasks list against the current `TaskContexts` using the same context-pick chain the "current" branch already uses (item context → active worktree → other worktree → default). If re-resolution fails for any reason, we fall back to the cached `ResolvedTask` so behavior never regresses. The change is localized to `previously_spawned_tasks` inside `used_and_current_resolved_tasks`. List order, dedup, and LRU scoring are unchanged — only the variable substitutions inside each `ResolvedTask` are refreshed. ## Test plan - [x] Open a project with two source files (e.g. `1.cpp`, `2.cpp`) and a task that uses `$ZED_FILE` (e.g. `g++ $ZED_FILE -o $ZED_STEM && ./$ZED_STEM`). - [x] Open `1.cpp`, run the task from the picker, confirm it compiles `1.cpp`. - [x] Click `2.cpp`, open the task picker, pick the same task from the "recent" section, confirm it now compiles `2.cpp` (previously: still `1.cpp`). - [x] Confirm the recent-task ordering and divider in the picker are unchanged. Release Notes: - Fixed task variables like `$ZED_FILE` not updating when re-running a recently used task after switching the active editor (zed-industries#55879).
Summary
Closes #55879.
When a task is run, its fully-resolved form (
ResolvedTask, with$ZED_FILE/$ZED_STEM/$ZED_COLUMN/etc. already substituted) is cached inInventory::last_scheduled_tasks. The next time the task picker is opened,used_and_current_resolved_tasksreturns those cached entries as-is for the "recent" section. The "current" section is re-resolved against the active editor, but the label-based dedup keeps the stale recent entry.The result is that
$ZED_FILEkeeps pointing at the file that was active the first time the task ran, even after switching editors and re-running from the picker.This fix re-resolves each entry in the recent-tasks list against the current
TaskContextsusing the same context-pick chain the "current" branch already uses (item context → active worktree → other worktree → default). If re-resolution fails for any reason, we fall back to the cachedResolvedTaskso behavior never regresses.The change is localized to
previously_spawned_tasksinsideused_and_current_resolved_tasks. List order, dedup, and LRU scoring are unchanged — only the variable substitutions inside eachResolvedTaskare refreshed.Test plan
1.cpp,2.cpp) and a task that uses$ZED_FILE(e.g.g++ $ZED_FILE -o $ZED_STEM && ./$ZED_STEM).1.cpp, run the task from the picker, confirm it compiles1.cpp.2.cpp, open the task picker, pick the same task from the "recent" section, confirm it now compiles2.cpp(previously: still1.cpp).Release Notes:
$ZED_FILEnot updating when re-running a recently used task after switching the active editor ($ZED_FILE doesn't update #55879).