Skip to content

Commit

Permalink
ssh support!
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtimsb committed Feb 21, 2025
1 parent cf0ac80 commit dfadaa2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
79 changes: 45 additions & 34 deletions crates/terminal_view/src/terminal_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use workspace::{
ActivatePaneUp, ActivatePreviousPane, DraggedSelection, DraggedTab, ItemId, MoveItemToPane,
MoveItemToPaneInDirection, NewTerminal, Pane, PaneGroup, SplitDirection, SplitDown, SplitLeft,
SplitRight, SplitUp, SwapPaneDown, SwapPaneLeft, SwapPaneRight, SwapPaneUp, ToggleZoom,
Workspace, WorkspaceId,
Workspace,
};

use anyhow::{anyhow, Context as _, Result};
Expand Down Expand Up @@ -217,8 +217,12 @@ impl TerminalPanel {
});
}

fn serialization_key(database_id: WorkspaceId) -> String {
format!("{:?}-{:?}", TERMINAL_PANEL_KEY, database_id)
fn serialization_key(workspace: &Workspace) -> Option<String> {
workspace
.database_id()
.map(|id| i64::from(id).to_string())
.or(workspace.session_id())
.map(|id| format!("{:?}-{:?}", TERMINAL_PANEL_KEY, id))
}

pub async fn load(
Expand All @@ -227,39 +231,44 @@ impl TerminalPanel {
) -> Result<Entity<Self>> {
let mut terminal_panel = None;

if let Some(database_id) = workspace
.read_with(&mut cx, |workspace, _| workspace.database_id())
.log_err()
match workspace
.read_with(&mut cx, |workspace, _| {
workspace
.database_id()
.zip(TerminalPanel::serialization_key(workspace))
})
.ok()
.flatten()
{
if let Some(serialized_panel) = cx
.background_spawn(async move {
KEY_VALUE_STORE.read_kvp(&TerminalPanel::serialization_key(database_id))
})
.await
.log_err()
.flatten()
.map(|panel| serde_json::from_str::<SerializedTerminalPanel>(&panel))
.transpose()
.log_err()
.flatten()
{
if let Ok(serialized) = workspace
.update_in(&mut cx, |workspace, window, cx| {
deserialize_terminal_panel(
workspace.weak_handle(),
workspace.project().clone(),
database_id,
serialized_panel,
window,
cx,
)
})?
Some((database_id, serialization_key)) => {
if let Some(serialized_panel) = cx
.background_spawn(async move { KEY_VALUE_STORE.read_kvp(&serialization_key) })
.await
.log_err()
.flatten()
.map(|panel| serde_json::from_str::<SerializedTerminalPanel>(&panel))
.transpose()
.log_err()
.flatten()
{
terminal_panel = Some(serialized);
if let Ok(serialized) = workspace
.update_in(&mut cx, |workspace, window, cx| {
deserialize_terminal_panel(
workspace.weak_handle(),
workspace.project().clone(),
database_id,
serialized_panel,
window,
cx,
)
})?
.await
{
terminal_panel = Some(serialized);
}
}
}
_ => {}
}

let terminal_panel = if let Some(panel) = terminal_panel {
Expand Down Expand Up @@ -750,10 +759,12 @@ impl TerminalPanel {
fn serialize(&mut self, cx: &mut Context<Self>) {
let height = self.height;
let width = self.width;
let Some(database_id) = self
let Some(serialization_key) = self
.workspace
.update(cx, |workspace, _| workspace.database_id())
.log_err()
.update(cx, |workspace, _| {
TerminalPanel::serialization_key(workspace)
})
.ok()
.flatten()
else {
return;
Expand All @@ -776,7 +787,7 @@ impl TerminalPanel {
async move {
KEY_VALUE_STORE
.write_kvp(
TerminalPanel::serialization_key(database_id),
serialization_key,
serde_json::to_string(&SerializedTerminalPanel {
items,
active_item_id: None,
Expand Down
4 changes: 4 additions & 0 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4385,6 +4385,10 @@ impl Workspace {
self.database_id
}

pub fn session_id(&self) -> Option<String> {
self.session_id.clone()
}

fn local_paths(&self, cx: &App) -> Option<Vec<Arc<Path>>> {
let project = self.project().read(cx);

Expand Down

0 comments on commit dfadaa2

Please sign in to comment.