SSH remoting: terminal & tasks (#15321)
This also rolls back the `TerminalWorkDir` abstraction I added for the original remoting, and tidies up the terminal creation code to be clear about whether we're creating a task *or* a terminal. The previous logic was a little muddy because it assumed we could be doing both at the same time (which was not true). Release Notes: - remoting alpha: Removed the ability to specify `gh cs ssh` or `gcloud compute ssh` etc. See https://zed.dev/docs/remote-development for alternatives. - remoting alpha: Added support for terminal and tasks to new experimental ssh remoting
This commit is contained in:
parent
26d0a33e79
commit
583b6235fb
10 changed files with 404 additions and 454 deletions
|
@ -9,9 +9,9 @@ use collections::{hash_map, HashMap, HashSet};
|
|||
use gpui::SharedString;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::{borrow::Cow, path::Path};
|
||||
|
||||
pub use task_template::{HideStrategy, RevealStrategy, TaskTemplate, TaskTemplates};
|
||||
pub use vscode_format::VsCodeTaskFile;
|
||||
|
@ -21,38 +21,6 @@ pub use vscode_format::VsCodeTaskFile;
|
|||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize)]
|
||||
pub struct TaskId(pub String);
|
||||
|
||||
/// TerminalWorkDir describes where a task should be run
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum TerminalWorkDir {
|
||||
/// Local is on this machine
|
||||
Local(PathBuf),
|
||||
/// SSH runs the terminal over ssh
|
||||
Ssh {
|
||||
/// The command to run to connect
|
||||
ssh_command: String,
|
||||
/// The path on the remote server
|
||||
path: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
impl TerminalWorkDir {
|
||||
/// Returns whether the terminal task is supposed to be spawned on a local machine or not.
|
||||
pub fn is_local(&self) -> bool {
|
||||
match self {
|
||||
Self::Local(_) => true,
|
||||
Self::Ssh { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a local CWD if the terminal is local, None otherwise.
|
||||
pub fn local_path(&self) -> Option<&Path> {
|
||||
match self {
|
||||
Self::Local(path) => Some(path),
|
||||
Self::Ssh { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains all information needed by Zed to spawn a new terminal tab for the given task.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SpawnInTerminal {
|
||||
|
@ -70,7 +38,7 @@ pub struct SpawnInTerminal {
|
|||
/// A human-readable label, containing command and all of its arguments, joined and substituted.
|
||||
pub command_label: String,
|
||||
/// Current working directory to spawn the command into.
|
||||
pub cwd: Option<TerminalWorkDir>,
|
||||
pub cwd: Option<PathBuf>,
|
||||
/// Env overrides for the command, will be appended to the terminal's environment from the settings.
|
||||
pub env: HashMap<String, String>,
|
||||
/// Whether to use a new terminal tab or reuse the existing one to spawn the process.
|
||||
|
@ -265,7 +233,7 @@ impl IntoIterator for TaskVariables {
|
|||
|
||||
/// Keeps track of the file associated with a task and context of tasks execution (i.e. current file or current function).
|
||||
/// Keeps all Zed-related state inside, used to produce a resolved task out of its template.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct TaskContext {
|
||||
/// A path to a directory in which the task should be executed.
|
||||
pub cwd: Option<PathBuf>,
|
||||
|
|
|
@ -8,7 +8,7 @@ use sha2::{Digest, Sha256};
|
|||
use util::{truncate_and_remove_front, ResultExt};
|
||||
|
||||
use crate::{
|
||||
ResolvedTask, Shell, SpawnInTerminal, TaskContext, TaskId, TerminalWorkDir, VariableName,
|
||||
ResolvedTask, Shell, SpawnInTerminal, TaskContext, TaskId, VariableName,
|
||||
ZED_VARIABLE_NAME_PREFIX,
|
||||
};
|
||||
|
||||
|
@ -134,14 +134,11 @@ impl TaskTemplate {
|
|||
&variable_names,
|
||||
&mut substituted_variables,
|
||||
)?;
|
||||
Some(TerminalWorkDir::Local(PathBuf::from(substitured_cwd)))
|
||||
Some(PathBuf::from(substitured_cwd))
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
.or(cx
|
||||
.cwd
|
||||
.as_ref()
|
||||
.map(|cwd| TerminalWorkDir::Local(cwd.clone())));
|
||||
.or(cx.cwd.clone());
|
||||
let human_readable_label = substitute_all_template_variables_in_str(
|
||||
&self.label,
|
||||
&truncated_variables,
|
||||
|
@ -421,11 +418,8 @@ mod tests {
|
|||
project_env: HashMap::default(),
|
||||
};
|
||||
assert_eq!(
|
||||
resolved_task(&task_without_cwd, &cx)
|
||||
.cwd
|
||||
.as_ref()
|
||||
.and_then(|cwd| cwd.local_path()),
|
||||
Some(context_cwd.as_path()),
|
||||
resolved_task(&task_without_cwd, &cx).cwd,
|
||||
Some(context_cwd.clone()),
|
||||
"TaskContext's cwd should be taken on resolve if task's cwd is None"
|
||||
);
|
||||
|
||||
|
@ -440,11 +434,8 @@ mod tests {
|
|||
project_env: HashMap::default(),
|
||||
};
|
||||
assert_eq!(
|
||||
resolved_task(&task_with_cwd, &cx)
|
||||
.cwd
|
||||
.as_ref()
|
||||
.and_then(|cwd| cwd.local_path()),
|
||||
Some(task_cwd.as_path()),
|
||||
resolved_task(&task_with_cwd, &cx).cwd,
|
||||
Some(task_cwd.clone()),
|
||||
"TaskTemplate's cwd should be taken on resolve if TaskContext's cwd is None"
|
||||
);
|
||||
|
||||
|
@ -454,11 +445,8 @@ mod tests {
|
|||
project_env: HashMap::default(),
|
||||
};
|
||||
assert_eq!(
|
||||
resolved_task(&task_with_cwd, &cx)
|
||||
.cwd
|
||||
.as_ref()
|
||||
.and_then(|cwd| cwd.local_path()),
|
||||
Some(task_cwd.as_path()),
|
||||
resolved_task(&task_with_cwd, &cx).cwd,
|
||||
Some(task_cwd),
|
||||
"TaskTemplate's cwd should be taken on resolve if TaskContext's cwd is not None"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue