oo-protocol 0.0.3

Protocol between ∞ ide and extensions.
Documentation
//! Shared protocol types for the oo extension ABI.
//!
//! Used by both the host (`oo`) and WASM extensions (`oo-api`).
//! Compiled with `no_std` when the `std` feature is disabled (for WASM targets).

#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use alloc::string::String;
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};

// ---------------------------------------------------------------------------
// Envelope
// ---------------------------------------------------------------------------

/// Top-level message envelope — either a request from WASM→host or a
/// response from host→WASM.
#[derive(Serialize, Deserialize)]
pub enum Message {
    Request(Request),
    Response(Response),
}

/// A request from the WASM extension to the host.
#[derive(Serialize, Deserialize)]
pub struct Request {
    /// Monotonically increasing request ID used to match responses.
    pub id: u32,
    pub payload: HostRequest,
}

/// A response from the host back to the WASM extension.
#[derive(Serialize, Deserialize)]
pub struct Response {
    /// Mirrors the `id` field of the originating `Request`.
    pub id: u32,
    pub result: ResponsePayload,
}

#[derive(Serialize, Deserialize)]
pub enum ResponsePayload {
    None,
    String(String),
    Error(String),
}

// ---------------------------------------------------------------------------
// Host requests
// ---------------------------------------------------------------------------

#[derive(Serialize, Deserialize)]
pub enum HostRequest {
    Operation(Operation),
    GetConfig { key: String },
    HasLanguage { lang: String },
    Log { message: String },
}

// ---------------------------------------------------------------------------
// Namespaced operations
// ---------------------------------------------------------------------------

#[derive(Serialize, Deserialize)]
pub enum Operation {
    Window(WindowOp),
    Workspace(WorkspaceOp),
    Terminal(TerminalOp),
    Command(CommandOp),
}

#[derive(Serialize, Deserialize)]
pub enum WindowOp {
    ShowNotification {
        message: String,
        level: String,
    },
    UpdateStatusBar {
        text: String,
        slot: Option<String>,
    },
    ShowPicker {
        title: Option<String>,
        items: Vec<PickerItem>,
    },
}

#[derive(Serialize, Deserialize)]
pub enum WorkspaceOp {
    OpenFile { path: String },
}

#[derive(Serialize, Deserialize)]
pub enum TerminalOp {
    Create { command: String },
}

#[derive(Serialize, Deserialize)]
pub enum CommandOp {
    Run { id: String },
}

#[derive(Serialize, Deserialize, Clone)]
pub struct PickerItem {
    pub label: String,
    pub value: String,
}