Skip to content

Commit

Permalink
Fix ZED_WORKTREE_ROOT to always point to a directory
Browse files Browse the repository at this point in the history
Fixes zed-industries#22912

Update `ZED_WORKTREE_ROOT` to always point to a directory.

* **Documentation**
  - Add an example of correct usage of `ZED_WORKTREE_ROOT` in `docs/src/tasks.md`.

* **Static Source**
  - Remove unnecessary comment in `crates/task/src/static_source.rs`.

* **VSCode Format**
  - Add a test case in `crates/task/src/vscode_format.rs` to verify that `ZED_WORKTREE_ROOT` points to a directory.

* **Tasks UI**
  - Modify the `task_context` function in `crates/tasks_ui/src/lib.rs` to ensure `ZED_WORKTREE_ROOT` points to a directory.
  • Loading branch information
SkywardSyntax committed Jan 14, 2025
1 parent 26be440 commit c7113f2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 0 additions & 2 deletions crates/task/src/static_source.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//! A source of tasks, based on a static configuration, deserialized from the tasks config file, and related infrastructure for tracking changes to the file.
use std::sync::Arc;

use futures::{channel::mpsc::UnboundedSender, StreamExt};
Expand Down
16 changes: 16 additions & 0 deletions crates/task/src/vscode_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,20 @@ mod tests {
let tasks: TaskTemplates = vscode_definitions.try_into().unwrap();
assert_eq!(tasks.0, expected);
}

#[test]
fn test_zed_worktree_root_points_to_directory() {
let replacer = EnvVariableReplacer::new(HashMap::from_iter([(
"workspaceFolder".to_owned(),
"ZED_WORKTREE_ROOT".to_owned(),
)]));

let input = "${workspaceFolder}/some/path";
let expected = "${ZED_WORKTREE_ROOT}/some/path";
assert_eq!(replacer.replace(input), expected);

let input = "${workspaceFolder:default}/some/path";
let expected = "${ZED_WORKTREE_ROOT:default}/some/path";
assert_eq!(replacer.replace(input), expected);
}
}
2 changes: 1 addition & 1 deletion crates/tasks_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn spawn_task_with_name(
Some(())
})?
.is_some();
if !did_spawn {
if (!did_spawn) {
workspace
.update(&mut cx, |workspace, cx| {
spawn_task_or_modal(
Expand Down
14 changes: 14 additions & 0 deletions docs/src/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,17 @@ To tag a task, add the runnable tag name to `tags` field on task template:
```

In doing so, you can change which task is shown in runnables indicator.

### Example of Correct Usage of `ZED_WORKTREE_ROOT`

To ensure that `ZED_WORKTREE_ROOT` always points to a directory, you can use it in a task as follows:

```json
{
"label": "lazygit",
"command": "alacritty -o 'window.startup_mode=\"SimpleFullscreen\"' --working-directory ${ZED_WORKTREE_ROOT} --command lazygit",
"hide": "always"
}
```

In this example, `ZED_WORKTREE_ROOT` is used to set the working directory for the `alacritty` terminal emulator, ensuring that it always points to the root directory of the current worktree.

0 comments on commit c7113f2

Please sign in to comment.