this repo has no description
at main 143 lines 4.1 kB view raw
1open Code_mirror 2 3(** Most of this documention originate from the code-mirror reference. 4 5 {{:https://codemirror.net/6/docs/ref/#autocomplete} Visit the reference 6 directly for additional information.} *) 7 8val autocomplete : Jv.t 9(** Global autocomplete value *) 10 11module RegExp = RegExp 12 13module Completion : sig 14 (** Represents individual completions. *) 15 16 type t 17 (** Completion *) 18 19 include Jv.CONV with type t := t 20 21 val create : 22 label:string -> 23 ?detail:string -> 24 ?info:string -> 25 ?apply:t -> 26 ?type_:string -> 27 ?boost:int -> 28 unit -> 29 t 30 (** Creates a completion. 31 32 @param label The label to show in the completion picker. 33 @param detail 34 An optional short piece of information to show after the label. 35 @param info Additional info to show when the completion is selected. 36 @param apply (todo) How to apply the completion. 37 @param type 38 The type of the completion. This is used to pick an icon to show for the 39 completion. 40 @param boost 41 42 {{:https://codemirror.net/6/docs/ref/#autocomplete.Completion} See the 43 reference for additional information.} *) 44end 45 46module Context : sig 47 (** An instance of this is passed to completion source functions. *) 48 49 type t 50 (** Completion context *) 51 52 include Jv.CONV with type t := t 53 54 val state : t -> Editor.State.t 55 (** The editor state that the completion happens in. *) 56 57 val pos : t -> int 58 (** The position at which the completion is happening. *) 59 60 val explicit : t -> bool 61 (** Indicates whether completion was activated explicitly, or implicitly by 62 typing. The usual way to respond to this is to only return completions 63 when either there is part of a completable entity before the cursor, or 64 explicit is true. *) 65 66 val token_before : t -> string list -> Jv.t option 67 (** Get the extent, content, and (if there is a token) type of the token 68 before this.pos. *) 69 70 val match_before : t -> RegExp.t -> Jv.t option 71 (** Get the match of the given expression directly before the cursor. *) 72 73 val aborted : t -> bool 74 (** Yields true when the query has been aborted. Can be useful in asynchronous 75 queries to avoid doing work that will be ignored. *) 76end 77 78module Result : sig 79 (** Objects returned by completion sources. *) 80 81 type t 82 (** Completion result *) 83 84 include Jv.CONV with type t := t 85 86 val create : 87 from:int -> 88 ?to_:int -> 89 options:Completion.t list -> 90 ?span:RegExp.t -> 91 ?filter:bool -> 92 unit -> 93 t 94 (** Creating a new completion result (see 95 {{:https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult} the 96 docs}). 97 @param from The start of the range that is being completed. 98 @param to_ 99 The end of the range that is being completed. Defaults to the main 100 cursor position. 101 @param options The completions returned. 102 @param span 103 When given, further input that causes the part of the document between 104 [from] and [to_] to match this regular expression will not query the 105 completion source again 106 @param filter 107 By default, the library filters and scores completions. Set filter to 108 false to disable this, and cause your completions to all be included, in 109 the order they were given. *) 110end 111 112module Source : sig 113 type t 114 (** Completion source *) 115 116 include Jv.CONV with type t := t 117 118 val create : (Context.t -> Result.t option Fut.t) -> t 119 120 val from_list : Completion.t list -> t 121 (** Given a a fixed array of options, return an autocompleter that completes 122 them. *) 123end 124 125type config 126 127val config : 128 ?activate_on_typing:bool -> 129 ?override:Source.t list -> 130 ?max_rendered_options:int -> 131 ?default_key_map:bool -> 132 ?above_cursor:bool -> 133 ?option_class:Jv.t -> 134 ?icons:bool -> 135 ?add_to_options:Jv.t -> 136 unit -> 137 config 138(** Configuration options for your autocompleter, see 139 {{:https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config} 140 the online docs}.*) 141 142val create : ?config:config -> unit -> Code_mirror.Extension.t 143(** Autocompleter *)