-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
Summary
Running a task using task: spawn
does not always provide the current file and line number, it is stuck on previous values
Description
I created a task to include ZED_
variables and when I run it using task: spawn
, the current file and line number values that I am using in the command / args are not up to date as I move around the editor to different files and run the task (they seemed to be right the first time I ran it after creation, maybe once of twice after that, seems to vary)
From Tasks docs:
Zed supports ways to spawn (and rerun) commands using its integrated terminal to output the results. These commands can read a limited subset of Zed state (such as a path to the file currently being edited or selected text).
...
These variables allow you to pull information from the current editor and use it in your tasks.
This does not seem to be true and is really limiting the utility of Tasks.
I need a way to access the currently active file and line number (in some cases the selected text too) in Zed when I run a task so I can build a few helper tools for my workflow
How do I get the current state of the editor in the ZED_
variables every time I run a task using task: spawn
?
There have been several issues that brought this up, but they are either closed or there were discussions about work arounds using keymaps / task re-run, adding conditional attributes, UI changes etc.
I am really confused, how can a task system without access to the current state of the editor like active file and line number be used to build tools? Is there an alternative I am missing?
Previous issues:
- Tasks cache the ZED_* variables #11792
- Tasks are using file parameters from previous runs #10845
- Task: $ZED_RELATIVE_FILE keeps referring to the previous file #16996
Steps to reproduce:
- Open a folder with a few files
- Create a new Zed task using the
ZED_FILE
variable (eg.zed: open project tasks
, paste the example task below) - Run the task
task: spawn
> "echo current file's path" - See a new terminal window show up with the current file in the output
- Move around the editor to different files, switch to another file
- Repeat steps 3 and 4
- Eventually you'll end up in a state where running the command does not show the currently focused file anymore, it keeps showing a previous value
Example task using a variable, copied from docs:
{
"label": "echo current file's path",
"command": "echo $ZED_FILE"
}
This happens with various ZED_*
variables that are expected to change, as you move around the editor to different files, they do not update
Expected Behavior:
ZED_*
variables reflect the current state of the editor when you spawn a task
Actual Behavior:
ZED_*
variables are stuck on a previous value and are not updating when tasks are spawned
Zed Version and System Specs
Zed: v0.207.4 (Zed)
OS: macOS 15.7.1
Memory: 36 GiB
Architecture: aarch64