Tidy up the code (#12116)

Small follow-ups for https://github.com/zed-industries/zed/pull/12063
and https://github.com/zed-industries/zed/pull/12103

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-05-22 14:36:15 +03:00 committed by GitHub
parent c440f3a71b
commit c4e87444e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 130 additions and 104 deletions

View file

@ -8,8 +8,8 @@ mod vscode_format;
use collections::{HashMap, HashSet};
use gpui::SharedString;
use serde::Serialize;
use std::borrow::Cow;
use std::path::PathBuf;
use std::{borrow::Cow, path::Path};
pub use task_template::{RevealStrategy, TaskTemplate, TaskTemplates};
pub use vscode_format::VsCodeTaskFile;
@ -34,19 +34,19 @@ pub enum TerminalWorkDir {
}
impl TerminalWorkDir {
/// is_local
/// Returns whether the terminal task is supposed to be spawned on a local machine or not.
pub fn is_local(&self) -> bool {
match self {
TerminalWorkDir::Local(_) => true,
TerminalWorkDir::Ssh { .. } => false,
Self::Local(_) => true,
Self::Ssh { .. } => false,
}
}
/// local_path
pub fn local_path(&self) -> Option<PathBuf> {
/// Returns a local CWD if the terminal is local, None otherwise.
pub fn local_path(&self) -> Option<&Path> {
match self {
TerminalWorkDir::Local(path) => Some(path.clone()),
TerminalWorkDir::Ssh { .. } => None,
Self::Local(path) => Some(path),
Self::Ssh { .. } => None,
}
}
}

View file

@ -384,8 +384,9 @@ mod tests {
assert_eq!(
resolved_task(&task_without_cwd, &cx)
.cwd
.as_ref()
.and_then(|cwd| cwd.local_path()),
Some(context_cwd.clone()),
Some(context_cwd.as_path()),
"TaskContext's cwd should be taken on resolve if task's cwd is None"
);
@ -401,8 +402,9 @@ mod tests {
assert_eq!(
resolved_task(&task_with_cwd, &cx)
.cwd
.as_ref()
.and_then(|cwd| cwd.local_path()),
Some(task_cwd.clone()),
Some(task_cwd.as_path()),
"TaskTemplate's cwd should be taken on resolve if TaskContext's cwd is None"
);
@ -413,8 +415,9 @@ mod tests {
assert_eq!(
resolved_task(&task_with_cwd, &cx)
.cwd
.as_ref()
.and_then(|cwd| cwd.local_path()),
Some(task_cwd.clone()),
Some(task_cwd.as_path()),
"TaskTemplate's cwd should be taken on resolve if TaskContext's cwd is not None"
);
}