Skip to main content

oo_protocol/
lib.rs

1//! Shared protocol types for the oo extension ABI.
2//!
3//! Used by both the host (`oo`) and WASM extensions (`oo-api`).
4//! Compiled with `no_std` when the `std` feature is disabled (for WASM targets).
5
6#![cfg_attr(not(feature = "std"), no_std)]
7
8extern crate alloc;
9
10use alloc::string::String;
11use alloc::vec::Vec;
12use serde::{Deserialize, Serialize};
13
14// ---------------------------------------------------------------------------
15// Envelope
16// ---------------------------------------------------------------------------
17
18/// Top-level message envelope — either a request from WASM→host or a
19/// response from host→WASM.
20#[derive(Serialize, Deserialize)]
21pub enum Message {
22    Request(Request),
23    Response(Response),
24}
25
26/// A request from the WASM extension to the host.
27#[derive(Serialize, Deserialize)]
28pub struct Request {
29    /// Monotonically increasing request ID used to match responses.
30    pub id: u32,
31    pub payload: HostRequest,
32}
33
34/// A response from the host back to the WASM extension.
35#[derive(Serialize, Deserialize)]
36pub struct Response {
37    /// Mirrors the `id` field of the originating `Request`.
38    pub id: u32,
39    pub result: ResponsePayload,
40}
41
42#[derive(Serialize, Deserialize)]
43pub enum ResponsePayload {
44    None,
45    String(String),
46    Error(String),
47}
48
49// ---------------------------------------------------------------------------
50// Host requests
51// ---------------------------------------------------------------------------
52
53#[derive(Serialize, Deserialize)]
54pub enum HostRequest {
55    Operation(Operation),
56    GetConfig { key: String },
57    HasLanguage { lang: String },
58    Log { message: String },
59}
60
61// ---------------------------------------------------------------------------
62// Namespaced operations
63// ---------------------------------------------------------------------------
64
65#[derive(Serialize, Deserialize)]
66pub enum Operation {
67    Window(WindowOp),
68    Workspace(WorkspaceOp),
69    Terminal(TerminalOp),
70    Command(CommandOp),
71}
72
73#[derive(Serialize, Deserialize)]
74pub enum WindowOp {
75    ShowNotification {
76        message: String,
77        level: String,
78    },
79    UpdateStatusBar {
80        text: String,
81        slot: Option<String>,
82    },
83    ShowPicker {
84        title: Option<String>,
85        items: Vec<PickerItem>,
86    },
87}
88
89#[derive(Serialize, Deserialize)]
90pub enum WorkspaceOp {
91    OpenFile { path: String },
92}
93
94#[derive(Serialize, Deserialize)]
95pub enum TerminalOp {
96    Create { command: String },
97}
98
99#[derive(Serialize, Deserialize)]
100pub enum CommandOp {
101    Run { id: String },
102}
103
104#[derive(Serialize, Deserialize, Clone)]
105pub struct PickerItem {
106    pub label: String,
107    pub value: String,
108}