bastianplsfix

Run and watch the current file from the editor

This last step is optional, and I thought hard about whether to include it at all. It configures Zed tasks and a keyboard shortcut so you can run or continuously retest the file you're editing with a few keystrokes, instead of typing paths like deno run programs/answer.ts each time. The convenience is real; I use exactly this setup.

My hesitation, and my one ground rule if you proceed: the lessons will keep showing the typed command, and the typed command remains the ground truth. Shortcuts are compressed knowledge, and compression is only safe once you know what's inside. If a shortcut ever surprises or confuses you, open the terminal and type the command instead.

Create the tasks file

  1. Right-click the .zed folder in Zed's Project Panel.
  2. Choose New File and name it tasks.json.
  3. Add this content:
[
{
"label": "deno: check and run this file",
"command": "deno run --check \"$ZED_FILE\""
},
{
"label": "deno: test this file",
"command": "deno test \"$ZED_FILE\""
},
{
"label": "deno: watch this test file",
"command": "deno",
"args": ["test", "--watch", "--no-clear-screen", "$ZED_FILE"],
"save": "current",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "deno: test everything",
"command": "deno test"
}
]

The $ZED_FILE variable automatically inserts the path of the file you currently have open. The watch task keeps tests re-running after each save, and --no-clear-screen preserves earlier results so you can scroll back through them.

Run a task

Open Zed's command palette:

Type task: spawn, select it, and choose one of the four tasks. To repeat the most recent task, use task: rerun from the palette.

Bind the watch task to a key

The watch task is the one you'll reach for constantly once the lessons get going, so give it a key of its own. Open your keymap file via the command palette (zed: open keymap file).

macOS:

[
{
"context": "Workspace",
"bindings": {
"cmd-alt-t": [
"task::Spawn",
{ "task_name": "deno: watch this test file" }
]
}
}
]

Windows/Linux:

[
{
"context": "Workspace",
"bindings": {
"ctrl-alt-shift-t": [
"task::Spawn",
{ "task_name": "deno: watch this test file" }
]
}
}
]

The watcher keeps running until you press Control-C in its terminal. If you switch to a different test file, stop the old watcher and press the shortcut again from the new file.

Your setup check

Confirm three things:

  1. .zed/tasks.json exists with all four tasks.
  2. task: spawn lists all four labels in the command palette.
  3. Your keymap contains the watch-task shortcut.

That's the whole toolchain: a runtime, an editor, a project, and a feedback loop. Setup is behind you. Let's write your first program.


Start the testing guide →