Module Quill.Kernel

Code execution kernels.

A kernel executes code and produces outputs. The interface is abstract to support different backends: in-process toplevels, subprocess-based kernels, remote kernels, etc.

Kernel status

type status =
  1. | Starting
  2. | Idle
  3. | Busy
  4. | Shutting_down
    (*

    The type for kernel lifecycle status.

    *)

Kernel events

type event =
  1. | Output of {
    1. cell_id : Cell.id;
    2. output : Cell.output;
    }
  2. | Finished of {
    1. cell_id : Cell.id;
    2. success : bool;
    }
  3. | Status_changed of status
    (*

    The type for kernel events.

    • Output is emitted for each piece of output during execution.
    • Finished signals that execution of a cell has completed.
    • Status_changed signals a kernel lifecycle change.
    *)

Completions

type completion_kind =
  1. | Value
  2. | Type
  3. | Module
  4. | Module_type
  5. | Constructor
  6. | Label
    (*

    The type for completion item kinds.

    *)
type completion_item = {
  1. label : string;
  2. kind : completion_kind;
  3. detail : string;
}

The type for completion items. label is the identifier name, kind classifies it, and detail is a formatted type signature.

Intellisense

type severity =
  1. | Error
  2. | Warning
    (*

    The type for diagnostic severity levels.

    *)
type diagnostic = {
  1. from_pos : int;
  2. to_pos : int;
  3. severity : severity;
  4. message : string;
}

The type for diagnostics. Positions are byte offsets within the cell.

type type_info = {
  1. typ : string;
  2. doc : string option;
  3. from_pos : int;
  4. to_pos : int;
}

The type for type-at-position results. typ is the formatted type, doc is the optional documentation string, and positions delimit the expression span.

Kernel interface

type t = {
  1. execute : cell_id:Cell.id -> code:string -> unit;
  2. interrupt : unit -> unit;
  3. complete : code:string -> pos:int -> completion_item list;
  4. type_at : (code:string -> pos:int -> type_info option) option;
  5. diagnostics : (code:string -> diagnostic list) option;
  6. is_complete : (string -> bool) option;
  7. status : unit -> status;
  8. shutdown : unit -> unit;
}

The type for kernel handles.

  • execute ~cell_id ~code submits code for execution. Results are delivered as event values through the callback registered at kernel creation time.
  • interrupt () requests interruption of the current execution.
  • complete ~code ~pos returns completion candidates at the given cursor position in code.
  • type_at when Some f, f ~code ~pos returns type information at the given cursor position.
  • diagnostics when Some f, f ~code returns parse and type errors.
  • is_complete when Some f, f code returns true if code contains a complete toplevel phrase ready for execution.
  • status () returns the current kernel status.
  • shutdown () initiates graceful shutdown.