package libsail

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type handle = private int
val interactive_repl : handle

This is a special handle that contains inputs to the sail -i REPL

val repl_prompt_line : unit -> int
val add_to_repl_contents : command:string -> int * int
val set_canonicalize_function : (string -> string) -> unit

For the LSP, we might have Sail and the editor use slightly different paths for the same file so we can set this to Sys.realpath, and we will then treat files with the same canonical name as the same file.

We can't just use realpath directly because it would mean increasing our minimum OCaml version to 4.13.

val open_file : string -> handle

Open a file and return a 'handle' to it's contents. Note that the file is not actually held open -- we read the contents, then close the handle storing the file information and contents in memory. As such there is no close_file. Repeatedly calling this file on the same string (as determined by set_canonicalize_function) will return the same handle.

val write_file : contents:string -> handle -> unit

Replace the contents of a file. Note that this only changes the in-memory contents of the file, and does not flush the changes to disk.

val editor_take_file : contents:string -> string -> handle

The the LSP takes control of a file by sending us a DidOpenTextDocument message, with the contents of the file as seen by the editor.

val editor_drop_file : handle -> unit

The LSP can stop editing a file using the DidCloseTextDocument message, in which case we need to manage the file.

type editor_position = {
  1. line : int;
  2. character : int;
}

The LSP protocol uses line + character offsets as positions

type editor_range = editor_position * editor_position
type text_edit = {
  1. range : editor_range;
  2. text : string;
}

Note that the empty string represents a delete operation as per LSP.

type text_edit_size =
  1. | Single_line of int
  2. | Multiple_lines of {
    1. pre : int;
    2. newlines : int;
    3. post : int;
    }
val edit_file : handle -> text_edit -> unit

Store a pending text edit to a file. This is used by editor_position and lexing_position to synchonize locations between the last type-checked version of the file, and any changes that have subsequently been made in the editor. Note that it does not change the actual contents of the file.

val editor_position : Stdlib.Lexing.position -> editor_position option

Take a Sail AST position, and return the where it will visibly appear in the user's editor. Returns None if the position no longer exists in the editor buffer, for example, the user may have deleted the position.

val lexing_position : handle -> editor_position -> Stdlib.Lexing.position option

Take a cursor position in the editor, and map it to a position in the Sail AST. Returns None if the cursor position is within a pending edit that has not yet been processed by Sail.

val contents : handle -> string

The contents of a Sail file as a string, without any pending edits.

module In_channel : sig ... end

This module aims to provide a drop-in replacement for the stdlib in_channel functionality used by Sail, essentially providing an iterator style interface to the file contents.

OCaml

Innovation. Community. Security.