diff options
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/schema.rs | 4 | ||||
| -rw-r--r-- | src/api/schema/response.rs | 4 | ||||
| -rw-r--r-- | src/api/schema/session.rs | 23 | ||||
| -rw-r--r-- | src/api/schema/tests.rs | 34 | ||||
| -rw-r--r-- | src/api/server.rs | 1 |
5 files changed, 66 insertions, 0 deletions
diff --git a/src/api/schema.rs b/src/api/schema.rs index c3349c04..a404d56c 100644 --- a/src/api/schema.rs +++ b/src/api/schema.rs @@ -8,6 +8,7 @@ pub mod panes; pub mod plugins; pub mod response; pub mod server; +pub mod session; pub mod tabs; pub mod workspaces; pub mod worktrees; @@ -20,6 +21,7 @@ pub use panes::*; pub use plugins::*; pub use response::*; pub use server::*; +pub use session::*; pub use tabs::*; pub use workspaces::*; pub use worktrees::*; @@ -59,6 +61,8 @@ pub enum Method { ClientWindowTitleSet(ClientWindowTitleSetParams), #[serde(rename = "client.window_title.clear")] ClientWindowTitleClear(EmptyParams), + #[serde(rename = "session.snapshot")] + SessionSnapshot(EmptyParams), #[serde(rename = "workspace.create")] WorkspaceCreate(WorkspaceCreateParams), #[serde(rename = "workspace.list")] diff --git a/src/api/schema/response.rs b/src/api/schema/response.rs index 57ab215b..8ad41ec4 100644 --- a/src/api/schema/response.rs +++ b/src/api/schema/response.rs @@ -16,6 +16,7 @@ use super::plugins::{ PluginPaneInfo, }; use super::server::ServerCapabilities; +use super::session::SessionSnapshot; use super::tabs::TabInfo; use super::workspaces::WorkspaceInfo; use super::worktrees::{WorktreeInfo, WorktreeSourceInfo}; @@ -47,6 +48,9 @@ pub enum ResponseResult { #[serde(default)] capabilities: Option<ServerCapabilities>, }, + SessionSnapshot { + snapshot: Box<SessionSnapshot>, + }, WorkspaceInfo { workspace: WorkspaceInfo, }, diff --git a/src/api/schema/session.rs b/src/api/schema/session.rs new file mode 100644 index 00000000..b51f6969 --- /dev/null +++ b/src/api/schema/session.rs @@ -0,0 +1,23 @@ +use serde::{Deserialize, Serialize}; + +use super::agents::AgentInfo; +use super::panes::{PaneInfo, PaneLayoutSnapshot}; +use super::tabs::TabInfo; +use super::workspaces::WorkspaceInfo; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct SessionSnapshot { + pub version: String, + pub protocol: u32, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub focused_workspace_id: Option<String>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub focused_tab_id: Option<String>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub focused_pane_id: Option<String>, + pub workspaces: Vec<WorkspaceInfo>, + pub tabs: Vec<TabInfo>, + pub panes: Vec<PaneInfo>, + pub layouts: Vec<PaneLayoutSnapshot>, + pub agents: Vec<AgentInfo>, +} diff --git a/src/api/schema/tests.rs b/src/api/schema/tests.rs index dd2004cf..5d61e972 100644 --- a/src/api/schema/tests.rs +++ b/src/api/schema/tests.rs @@ -377,6 +377,40 @@ fn success_response_round_trips() { } #[test] +fn session_snapshot_request_and_response_round_trip() { + let request = Request { + id: "req_snapshot".into(), + method: Method::SessionSnapshot(EmptyParams::default()), + }; + let json = serde_json::to_string(&request).unwrap(); + assert!(json.contains("\"method\":\"session.snapshot\"")); + let restored: Request = serde_json::from_str(&json).unwrap(); + assert_eq!(restored, request); + + let response = SuccessResponse { + id: "req_snapshot".into(), + result: ResponseResult::SessionSnapshot { + snapshot: Box::new(SessionSnapshot { + version: "0.1.2".into(), + protocol: 15, + focused_workspace_id: None, + focused_tab_id: None, + focused_pane_id: None, + workspaces: Vec::new(), + tabs: Vec::new(), + panes: Vec::new(), + layouts: Vec::new(), + agents: Vec::new(), + }), + }, + }; + let json = serde_json::to_string(&response).unwrap(); + assert!(json.contains("\"type\":\"session_snapshot\"")); + let restored: SuccessResponse = serde_json::from_str(&json).unwrap(); + assert_eq!(restored, response); +} + +#[test] fn worktree_request_and_response_round_trip() { let request = Request { id: "req_worktree".into(), diff --git a/src/api/server.rs b/src/api/server.rs index 039ede12..d01f4199 100644 --- a/src/api/server.rs +++ b/src/api/server.rs @@ -281,6 +281,7 @@ fn api_method_name(method: &Method) -> &'static str { Method::NotificationShow(_) => "notification.show", Method::ClientWindowTitleSet(_) => "client.window_title.set", Method::ClientWindowTitleClear(_) => "client.window_title.clear", + Method::SessionSnapshot(_) => "session.snapshot", Method::WorkspaceCreate(_) => "workspace.create", Method::WorkspaceList(_) => "workspace.list", Method::WorkspaceGet(_) => "workspace.get", |
