jon.recoil.org

Module Js_top_worker_message.MessageSource

Message protocol for worker communication.

This module defines a simple JSON-based message protocol for communication between the client and the OCaml toplevel worker.

Types

Sourcetype mime_val = {
  1. mime_type : string;
  2. data : string;
}
Sourcetype position = {
  1. pos_cnum : int;
  2. pos_lnum : int;
  3. pos_bol : int;
}
Sourcetype compl_entry = {
  1. name : string;
  2. kind : string;
  3. desc : string;
  4. info : string;
  5. deprecated : bool;
}
Sourcetype completions = {
  1. from : int;
  2. to_ : int;
  3. entries : Js_top_worker_message.Message.compl_entry list;
}
Sourcetype error = {
  1. kind : string;
  2. loc : Js_top_worker_message.Message.location;
  3. main : string;
  4. sub : string list;
  5. source : string;
}
Sourcetype type_info = {
  1. loc : Js_top_worker_message.Message.location;
  2. type_str : string;
  3. tail : string;
}
Sourcetype init_config = {
  1. findlib_requires : string list;
  2. stdlib_dcs : string option;
  3. findlib_index : string option;
}

Client -> Worker messages

Sourcetype client_msg =
  1. | Init of Js_top_worker_message.Message.init_config
  2. | Eval of {
    1. cell_id : int;
    2. env_id : string;
    3. code : string;
    }
  3. | Complete of {
    1. cell_id : int;
    2. env_id : string;
    3. source : string;
    4. position : int;
    5. filename : string option;
    }
  4. | TypeAt of {
    1. cell_id : int;
    2. env_id : string;
    3. source : string;
    4. position : int;
    5. filename : string option;
    }
  5. | Errors of {
    1. cell_id : int;
    2. env_id : string;
    3. source : string;
    4. filename : string option;
    }
  6. | CreateEnv of {
    1. env_id : string;
    }
  7. | DestroyEnv of {
    1. env_id : string;
    }
  8. | WidgetEvent of {
    1. widget_id : string;
    2. handler_id : string;
    3. event_type : string;
    4. value : string option;
    }

Worker -> Client messages

Sourcetype worker_msg =
  1. | Ready
  2. | InitError of {
    1. message : string;
    }
  3. | Output of {
    1. cell_id : int;
    2. stdout : string;
    3. stderr : string;
    4. caml_ppf : string;
    5. mime_vals : Js_top_worker_message.Message.mime_val list;
    }
  4. | OutputAt of {
    1. cell_id : int;
    2. loc : int;
    3. caml_ppf : string;
    4. mime_vals : Js_top_worker_message.Message.mime_val list;
    }
  5. | Completions of {
    1. cell_id : int;
    2. completions : Js_top_worker_message.Message.completions;
    }
  6. | Types of {
    1. cell_id : int;
    2. types : Js_top_worker_message.Message.type_info list;
    }
  7. | ErrorList of {
    1. cell_id : int;
    2. errors : Js_top_worker_message.Message.error list;
    }
  8. | EvalError of {
    1. cell_id : int;
    2. message : string;
    }
  9. | EnvCreated of {
    1. env_id : string;
    }
  10. | EnvDestroyed of {
    1. env_id : string;
    }
  11. | WidgetUpdate of {
    1. widget_id : string;
    2. view : Js_top_worker_message.Widget_view.node;
    }
  12. | WidgetClear of {
    1. widget_id : string;
    }
  13. | WidgetConfig of {
    1. widget_id : string;
    2. config : string;
    }
  14. | WidgetCommand of {
    1. widget_id : string;
    2. command : string;
    3. data : string;
    }
  15. | WidgetRegisterAdapter of {
    1. kind : string;
    2. js_code : string;
    }

JSON helpers

Sourceval json_global : 'a Js_of_ocaml.Js.t

Use plain JSON.stringify/JSON.parse instead of jsoo's Json.output/Json.unsafe_input. The jsoo versions use bytestring revivers that are incompatible across different jsoo versions (e.g., 6.0.1+ox vs 6.2.0). Since all values in our message objects are already proper JS values (created via Js.string, Js.Unsafe.inject, etc.), plain JSON works correctly and is cross-version compatible.

Sourceval plain_stringify : 't1 -> 'res
Sourceval json_of_obj : (string * 'a) list -> 'b
Sourceval json_string : string -> Js_of_ocaml.Js.Unsafe.any
Sourceval json_int : 'a -> Js_of_ocaml.Js.Unsafe.any
Sourceval json_bool : bool -> Js_of_ocaml.Js.Unsafe.any
Sourceval json_array : 'a list -> Js_of_ocaml.Js.Unsafe.any
Sourceval get_string : 'a -> string -> string
Sourceval get_int : 'a -> string -> 'b
Sourceval get_string_opt : 'a -> string -> string option
Sourceval get_array : 'a -> string -> 'b array
Sourceval get_string_array : 'a -> string -> string list

View node JSON encoding

Sourceval json_of_view_attr : Js_top_worker_message.Widget_view.attr -> 'a
Sourceval json_of_view_node : Js_top_worker_message.Widget_view.node -> 'a
Sourceval view_attr_of_json : 'a -> Js_top_worker_message.Widget_view.attr
Sourceval view_node_of_json : 'a -> Js_top_worker_message.Widget_view.node

Worker message serialization

Sourceval json_of_compl_entry : Js_top_worker_message.Message.compl_entry -> 'a
Sourceval json_of_completions : Js_top_worker_message.Message.completions -> 'a
Sourceval json_of_type_info : Js_top_worker_message.Message.type_info -> 'a
Sourceval json_of_worker_msg : Js_top_worker_message.Message.worker_msg -> string

Client message parsing

Sourceval client_msg_of_string : string -> Js_top_worker_message.Message.client_msg
Sourceval string_of_worker_msg : Js_top_worker_message.Message.worker_msg -> string