Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

remote: Use SSH nicknames in display names (#53103)

Saketheeb87cb17768
diff --git a/crates/remote/src/remote_client.rs b/crates/remote/src/remote_client.rs
index e746d82aac8..c04d3630f92 100644
--- a/crates/remote/src/remote_client.rs
+++ b/crates/remote/src/remote_client.rs
@@ -1285,7 +1285,10 @@ pub enum RemoteConnectionOptions {
impl RemoteConnectionOptions {
pub fn display_name(&self) -> String {
match self {
- RemoteConnectionOptions::Ssh(opts) => opts.host.to_string(),
+ RemoteConnectionOptions::Ssh(opts) => opts
+ .nickname
+ .clone()
+ .unwrap_or_else(|| opts.host.to_string()),
RemoteConnectionOptions::Wsl(opts) => opts.distro_name.clone(),
RemoteConnectionOptions::Docker(opts) => {
if opts.use_podman {
@@ -1300,6 +1303,32 @@ impl RemoteConnectionOptions {
}
}
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_ssh_display_name_prefers_nickname() {
+ let options = RemoteConnectionOptions::Ssh(SshConnectionOptions {
+ host: "1.2.3.4".into(),
+ nickname: Some("My Cool Project".to_string()),
+ ..Default::default()
+ });
+
+ assert_eq!(options.display_name(), "My Cool Project");
+ }
+
+ #[test]
+ fn test_ssh_display_name_falls_back_to_host() {
+ let options = RemoteConnectionOptions::Ssh(SshConnectionOptions {
+ host: "1.2.3.4".into(),
+ ..Default::default()
+ });
+
+ assert_eq!(options.display_name(), "1.2.3.4");
+ }
+}
+
impl From<SshConnectionOptions> for RemoteConnectionOptions {
fn from(opts: SshConnectionOptions) -> Self {
RemoteConnectionOptions::Ssh(opts)