1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
open Core
module Error_type = Nvim_internal.Error_type
module Notification = struct
type t = T : _ Nvim_internal.Api_result.t -> t [@@unboxed]
module Defun = struct
module Vim = struct
type notification = t
type ('fn, 'leftmost_input) t =
| Unit : (notification, notification) t
| Cons : 'a Nvim_internal.Phantom.t * ('b, _) t -> ('a -> 'b, 'a) t
let unit = Unit
let ( @-> ) a t = Cons (a, t)
end
end
let custom ~type_ ~function_name =
let rec custom
: type fn i. (fn, i) Defun.Vim.t -> (Msgpack.t list -> Msgpack.t list) -> fn
=
fun arity f ->
match arity with
| Unit -> T (Nvim_internal.nvim_call_function ~fn:function_name ~args:(f []))
| Cons (typ, rest) ->
fun i ->
let to_msgpack = Extract.inject typ in
custom rest (fun args -> f (to_msgpack i :: args))
in
custom type_ Fn.id
;;
let err_writeln ~str = T (Nvim_internal.nvim_err_writeln ~str)
module Untested = struct
let nvim_buf_add_highlight buffer ~namespace ~hl_group ~line ~col_start ~col_end =
Nvim_internal.nvim_buf_add_highlight
~buffer
~ns_id:(Namespace.id namespace)
~hl_group
~line
~col_start
~col_end
|> T
;;
end
end
let notify client (Notification.T notification) =
let client = Type_equal.conv Client.Private.eq client in
let (Connected state) = client.state in
state.call_nvim_api_fn notification Notification
;;
let error client error =
let notification = Notification.err_writeln ~str:(Error.to_string_hum error) in
notify client notification
;;
module For_testing = struct
let send_raw client ~function_name:name ~params =
let client = Type_equal.conv Client.Private.eq client in
let (Connected state) = client.state in
let notification = { Nvim_internal.Api_result.name; params; witness = Nil } in
state.call_nvim_api_fn notification Notification
;;
end