this repo has no description

add lint module

+169 -1
+3 -1
README.md
··· 1 1 jsoo-code-mirror 2 2 ---------------- 3 3 4 - Some bindings using [brr]() to [code-mirror 6](https://codemirror.net/6/). 4 + *Very, very incomplete* 5 + 6 + Some bindings using [brr](https://erratique.ch/software/brr) to [code-mirror 6](https://codemirror.net/6/).
+4
src/editor.ml
··· 18 18 let create ?(config = Jv.undefined) () = 19 19 let editor_state = Jv.get Jv.global "__CM__state" in 20 20 Jv.call editor_state "create" [| config |] 21 + 22 + let doc t = Jv.get t "doc" |> Text.of_jv 21 23 end 22 24 23 25 module View = struct ··· 37 39 38 40 let create ?(opts = Jv.undefined) () = 39 41 Jv.new' (Jv.get Jv.global "__CM__view") [| opts |] 42 + 43 + let state t = Jv.get t "state" |> State.of_jv 40 44 41 45 (* TODO *) 42 46 module Update = struct
+5
src/editor.mli
··· 16 16 end 17 17 18 18 val create : ?config:Config.t -> unit -> t 19 + 20 + val doc : t -> Text.t 19 21 end 20 22 21 23 module View : sig ··· 38 40 39 41 val create : ?opts:opts -> unit -> t 40 42 (** Create a new view *) 43 + 44 + val state : t -> State.t 45 + (** Current editor state *) 41 46 42 47 module Update : sig 43 48 type t
+6
src/lint/dune
··· 1 + (library 2 + (name lint) 3 + (js_of_ocaml 4 + (javascript_files require.js)) 5 + (public_name code-mirror.lint) 6 + (libraries code-mirror))
+79
src/lint/lint.ml
··· 1 + open Code_mirror 2 + 3 + let lint = Jv.get Jv.global "__CM__lint" 4 + 5 + module Action = struct 6 + type t = Jv.t 7 + 8 + let create ~name f = 9 + let f' view from to_ = 10 + let view = Editor.View.of_jv view in 11 + let from = Jv.to_int from in 12 + let to_ = Jv.to_int to_ in 13 + f ~view ~from ~to_ 14 + in 15 + let o = Jv.obj [||] in 16 + Jv.Jstr.set o "name" (Jstr.v name); 17 + Jv.set o "apply" (Jv.repr f'); 18 + o 19 + 20 + include (Jv.Id : Jv.CONV with type t := t) 21 + end 22 + 23 + module Diagnostic = struct 24 + type t = Jv.t 25 + 26 + let from t = Jv.Int.get t "from" 27 + 28 + let to_ t = Jv.Int.get t "to" 29 + 30 + type severity = Info | Warning | Error 31 + 32 + let severity_of_string = function 33 + | "info" -> Info 34 + | "warning" -> Warning 35 + | "error" -> Error 36 + | _ -> raise (Invalid_argument "Unknown severity level") 37 + 38 + let severity_to_string = function 39 + | Info -> "info" 40 + | Warning -> "warning" 41 + | Error -> "error" 42 + 43 + let severity t = 44 + Jv.Jstr.get t "severity" |> Jstr.to_string |> severity_of_string 45 + 46 + let create ?source ?actions ~from ~to_ ~severity ~message () = 47 + let o = Jv.obj [||] in 48 + Jv.Int.set o "from" from; 49 + Jv.Int.set o "to" to_; 50 + Jv.Jstr.set o "severity" (severity_to_string severity |> Jstr.v); 51 + Jv.Jstr.set o "message" (Jstr.v message); 52 + Jv.Jstr.set_if_some o "source" (Option.map Jstr.v source); 53 + Jv.set_if_some o "actions" (Option.map (Jv.of_array Action.to_jv) actions); 54 + o 55 + 56 + let source t = Jv.Jstr.find t "source" 57 + 58 + let message t = Jv.Jstr.get t "message" 59 + 60 + let actions t = Option.map (Jv.to_array Action.to_jv) (Jv.find t "actions") 61 + 62 + include (Jv.Id : Jv.CONV with type t := t) 63 + end 64 + 65 + let create ?delay 66 + (source : Code_mirror.Editor.View.t -> Diagnostic.t array Fut.t) = 67 + let o = 68 + match delay with 69 + | None -> Jv.obj [||] 70 + | Some d -> Jv.obj [| ("delay", Jv.of_int d) |] 71 + in 72 + let source' view = 73 + let fut = 74 + Fut.map (Jv.of_array Diagnostic.to_jv) @@ source (Editor.View.of_jv view) 75 + in 76 + Fut.to_promise ~ok:Fun.id (Fut.map Result.ok fut) 77 + in 78 + let ext = Jv.call lint "linter" [| Jv.repr source'; o |] in 79 + Code_mirror.Extension.of_jv ext
+50
src/lint/lint.mli
··· 1 + open Code_mirror 2 + 3 + val lint : Jv.t 4 + (** Global lint value *) 5 + 6 + module Action : sig 7 + type t 8 + (** The type for actions associated with a diagnostic *) 9 + 10 + val create : 11 + name:string -> (view:Editor.View.t -> from:int -> to_:int -> unit) -> t 12 + (** [create ~name f] makes a new action with a function to call when the user activates the action *) 13 + end 14 + 15 + module Diagnostic : sig 16 + type t 17 + 18 + type severity = Info | Warning | Error 19 + 20 + val severity_of_string : string -> severity 21 + 22 + val severity_to_string : severity -> string 23 + 24 + val create : 25 + ?source:string -> 26 + ?actions:t array -> 27 + from:int -> 28 + to_:int -> 29 + severity:severity -> 30 + message:string -> 31 + unit -> 32 + t 33 + 34 + val severity : t -> severity 35 + 36 + val from : t -> int 37 + 38 + val to_ : t -> int 39 + 40 + val source : t -> Jstr.t option 41 + 42 + val actions : t -> Action.t array option 43 + 44 + val message : t -> Jstr.t 45 + end 46 + 47 + val create : 48 + ?delay:int -> 49 + (Editor.View.t -> Diagnostic.t array Fut.t) -> 50 + Code_mirror.Extension.t
+1
src/lint/require.js
··· 1 + joo_global_object.__CM__lint = require('@codemirror/lint');
+10
src/text.ml
··· 1 + type t = Jv.t 2 + 3 + include (Jv.Id : Jv.CONV with type t := t) 4 + 1 5 module Line = struct 2 6 type t = Jv.t 3 7 ··· 11 15 12 16 let length t = Jv.Int.get t "length" 13 17 end 18 + 19 + let length t = Jv.Int.get t "length" 20 + 21 + let line n t = Jv.call t "line" [| Jv.of_int n |] 22 + 23 + let to_jstr_array t = Jv.call t "toJSON" [||] |> Jv.to_jstr_array
+11
src/text.mli
··· 1 + type t 2 + 3 + include Jv.CONV with type t := t 4 + 1 5 module Line : sig 2 6 type t 3 7 (** A text line *) ··· 17 21 val length : t -> int 18 22 (** The length of the line *) 19 23 end 24 + 25 + val length : t -> int 26 + (** Length of the text *) 27 + 28 + val line : int -> t -> Line.t 29 + 30 + val to_jstr_array : t -> Jstr.t array