···2121 set_if_some_string o "info" info;
2222 Jv.set_if_some o "apply" apply;
2323 set_if_some_string o "type" type_;
2424- Jv.Int.set_if_some o "boost" boost;
2424+ Jv.Int.set_if_some o "boost" boost;
2525 o
26262727end
···32323333 include (Jv.Id : Jv.CONV with type t := t)
34343535+ let state t = Jv.get t "state" |> Editor.State.of_jv
3636+3737+ let pos t = Jv.Int.get t "pos"
3838+3939+ let explicit t = Jv.Bool.get t "explicit"
4040+3541 let token_before t types =
3642 let jv = Jv.call t "tokenBefore" [| Jv.of_list Jv.of_string types |] in
3743 if Jv.is_none jv then None else Some jv
···3945 let match_before t regex =
4046 let jv = Jv.call t "matchBefore" [| RegExp.to_jv regex |] in
4147 if Jv.is_none jv then None else Some jv
4848+4949+ let aborted t = Jv.Bool.get t "aborted"
4250end
43514452module Result = struct
···5765 o
5866end
59676060-type source = Context.t -> Result.t option Fut.t
6161-(** A completion source *)
6868+module Source = struct
6969+ type t = Jv.t
62706363-let source_to_jv (src : source) =
6464- let f ctx =
6565- let fut = Fut.map (fun v -> Ok v) @@ src (Context.of_jv ctx) in
6666- Fut.to_promise ~ok:(fun t -> Option.value ~default:Jv.null (Option.map Result.to_jv t)) fut
6767- in
7171+ include (Jv.Id : Jv.CONV with type t := t)
7272+7373+ let create (src : Context.t -> Result.t option Fut.t) =
7474+ let f ctx =
7575+ let fut = Fut.map (fun v -> Ok v) @@ src (Context.of_jv ctx) in
7676+ Fut.to_promise fut
7777+ ~ok:(fun t ->
7878+ Option.value ~default:Jv.null (Option.map Result.to_jv t))
7979+ in
6880 Jv.repr f
69818282+ let from_list (l : Completion.t list) =
8383+ Jv.call autocomplete "completeFromList" [| Jv.of_jv_list l |] |> of_jv
8484+end
8585+7086type config = Jv.t
71877272-let config
8888+let config
7389 ?activate_on_typing
7490 ?override
7591 ?max_rendered_options
···8197 () =
8298 let o = Jv.obj [||] in
8399 Jv.Bool.set_if_some o "activateOnTyping" activate_on_typing;
8484- Jv.set_if_some o "override" (Option.map (fun v -> Jv.of_list source_to_jv v) override);
100100+ Jv.set_if_some o "override" (Option.map (fun v -> Jv.of_jv_list v) override);
85101 Jv.Int.set_if_some o "maxRenderedOptions" max_rendered_options;
86102 Jv.Bool.set_if_some o "defaultKeyMap" default_key_map;
87103 Jv.Bool.set_if_some o "aboveCursor" above_cursor;
···9611297113(* type status = Active | Pending
981149999-let status state =
115115+let status state =
100116101117val status : Editor.State.t -> status option
102118(** Gets the current completion status *)
···106122107123val selected_completion : Editor.State.t -> Completion.t option
108124* Returh the currently selected completion if any *)
109109-
+73-7
src/autocomplete/autocomplete.mli
···11+open Code_mirror
22+33+(** Most of this documention originate from the code-mirror reference.
44+55+ {{:https://codemirror.net/6/docs/ref/#autocomplete} Visit the
66+ reference directly for additional information.} *)
77+18val autocomplete : Jv.t
29(** Global autocomplete value *)
310411module RegExp = RegExp
512613module Completion : sig
1414+ (** Represents individual completions. *)
1515+716 type t
1717+ (** Completion *)
818919 include Jv.CONV with type t := t
10201121 val create :
1222 label:string ->
1323 ?detail:string ->
1414- ?info:string ->
2424+ ?info:string ->
1525 ?apply:t ->
1626 ?type_:string ->
1727 ?boost:int ->
1828 unit -> t
2929+ (** Creates a completion.
3030+3131+ @param label The label to show in the completion picker.
3232+ @param detail An optional short piece of information to show after the
3333+ label.
3434+ @param info Additional info to show when the completion is selected.
3535+ @param apply (todo) How to apply the completion.
3636+ @param type The type of the completion. This is used to pick an icon to
3737+ show for the completion.
3838+ @param boost
3939+4040+ {{:https://codemirror.net/6/docs/ref/#autocomplete.Completion} See the
4141+ reference for additional information.} *)
1942end
20432144module Context : sig
4545+ (** An instance of this is passed to completion source functions. *)
4646+2247 type t
2348 (** Completion context *)
24492550 include Jv.CONV with type t := t
26515252+ val state : t -> Editor.State.t
5353+ (** The editor state that the completion happens in. *)
5454+5555+ val pos : t -> int
5656+ (** The position at which the completion is happening. *)
5757+5858+ val explicit : t -> bool
5959+ (** Indicates whether completion was activated explicitly, or implicitly by
6060+ typing. The usual way to respond to this is to only return completions when
6161+ either there is part of a completable entity before the cursor, or explicit
6262+ is true. *)
6363+2764 val token_before : t -> string list -> Jv.t option
6565+ (** Get the extent, content, and (if there is a token) type of the token
6666+ before this.pos. *)
28672968 val match_before : t -> RegExp.t -> Jv.t option
6969+ (** Get the match of the given expression directly before the cursor. *)
7070+7171+ val aborted : t -> bool
7272+ (** Yields true when the query has been aborted. Can be useful in
7373+ asynchronous queries to avoid doing work that will be ignored. *)
3074end
31753276module Result : sig
7777+ (** Objects returned by completion sources. *)
7878+3379 type t
3480 (** Completion result *)
3581···4288 ?span:RegExp.t ->
4389 ?filter:bool ->
4490 unit -> t
4545- (** Creating a new completion result (see {{: https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult} the docs}).*)
9191+ (** Creating a new completion result (see {{: https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult} the docs}).
9292+ @param from The start of the range that is being completed.
9393+ @param to_ The end of the range that is being completed. Defaults to the
9494+ main cursor position.
9595+ @param options The completions returned.
9696+ @param span When given, further input that causes the part of the document
9797+ between [from] and [to_] to match this regular expression will not query
9898+ the completion source again
9999+ @param filter By default, the library filters and scores completions. Set
100100+ filter to false to disable this, and cause your completions to all be
101101+ included, in the order they were given.
102102+ *)
46103end
471044848-type source = Context.t -> Result.t option Fut.t
4949-(** A completion source *)
105105+module Source : sig
106106+ type t
107107+ (** Completion source *)
50108109109+ include Jv.CONV with type t := t
110110+111111+ val create : (Context.t -> Result.t option Fut.t) -> t
112112+113113+ val from_list : Completion.t list -> t
114114+ (** Given a a fixed array of options, return an autocompleter that completes
115115+ them. *)
116116+end
5111752118type config
531195454-val config :
5555- ?activate_on_typing:bool ->
5656- ?override:source list ->
120120+val config :
121121+ ?activate_on_typing:bool ->
122122+ ?override:Source.t list ->
57123 ?max_rendered_options:int ->
58124 ?default_key_map:bool ->
59125 ?above_cursor:bool ->