Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file vcaml_plugin_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166openCoreopenAsyncopenVcaml(** This library provides helpful abstractions for common patterns for interfacing with
Neovim.
[Oneshot] plugins are launched synchronously from Neovim and shut down after
performing their task, allowing Neovim to resume. Because they use stdout to
communicate with Neovim, any logging must be done via stderr (or to a file).
[Persistent] plugins are launched asynchronously from Neovim and serve both
synchronous and asynchronous requests.
If you have a use case that doesn't fit one of these models (e.g., you are starting an
OCaml app from outside Neovim that needs to talk to a running Neovim instance), use
the VCaml library directly. *)moduleOneshot=structmoduleRpc=structtypet=|Sync_rpc:{name:string;type_:('fn,'leftmost)Defun.Ocaml.Sync.t;f:keyboard_interrupted:unitDeferred.t->client:[`connected]Client.t->'fn}->tletcreate~name~type_~f=Sync_rpc{name;type_;f}endmoduletypeArg=sigvalname:string(** [on_error] is invoked when VCaml fails to parse a response from Neovim and when
Neovim sends us an asynchronous error event to inform us that it encountered a
problem with a message we sent. *)valon_error:[`Raise|`CallofVcaml_error.t->unit]valrpc_handlers:Rpc.tlistendmoduletypeS=sig(** A function like this should be defined for your plugin:
{v
function! s:rpcrequest(...) abort
let l:job_id = jobstart(['/path/to/exe'], { 'rpc': 1 })
return call('rpcrequest', [l:job_id] + a:000)
endfunction
v}
Then you can invoke [s:rpcrequest] the same way you would call [rpcrequest] on a
synchronous callback of a persistent plugin. *)valcommand:summary:string->Core.Command.t(* There is no special [run_for_testing] function exposed for [Oneshot] plugins
because the interesting "oneshot" aspect comes from launching them from Neovim
and using an [Stdio] client. Tests using [Embed] clients already have channels to
Neovim established can just [rpcrequest] the RPCs normally. *)endendmodulePersistent=structmoduleRpc=structtype'statet=|Sync_rpc:{name:string;type_:('fn,'leftmost)Defun.Ocaml.Sync.t;f:'state->shutdown:(unit->unit)->keyboard_interrupted:unitDeferred.t->client:[`connected]Client.t->'fn}->'statet|Async_rpc:{name:string;type_:'fnDefun.Ocaml.Async.t;f:'state->shutdown:(unit->unit)->client:[`connected]Client.t->'fn}->'statetletcreate_sync~name~type_~f=Sync_rpc{name;type_;f}letcreate_async~name~type_~f=Async_rpc{name;type_;f}endmoduletypeArg=sigtypestate[@@derivingsexp_of]valname:string(** Used as the [summary] argument for [command]. *)valdescription:string(** [on_error] is invoked when VCaml fails to parse a response from Neovim and when
Neovim sends us an asynchronous error event to inform us that it encountered a
problem with a message we sent. *)valon_error:[`Raise|`CallofVcaml_error.t->unit]valrpc_handlers:stateRpc.tlistvalinit_state:unit->statevalon_startup:[`connected]Client.t->state->shutdown:(unit->unit)->unitDeferred.Or_error.t(** If specified, this Vimscript function will be called after [on_startup] finishes.
It should be used as the indication to Neovim that the plugin is now ready to
start serving RPCs - before this it's possible to be in a bad state (the RPCs may
not yet be registered or [on_startup] may not have finished running). It should
take a single integer argument, which will be the channel ID. *)valvimscript_notify_fn:stringoptionvalon_shutdown:[`connected]Client.t->state->unitDeferred.Or_error.tendmoduleFor_testing=structmoduletypeS=sigtypeplugin_state[@@derivingsexp_of]moduleState:sigtypet={plugin_state:plugin_state;shutdown:unit->unit;wait_for_shutdown:unitOr_error.tDeferred.t}endvalstart:client:[`connected]Client.t->State.tDeferred.Or_error.tendendmoduletypeS=sigtypestatevalcommand:Core.Command.tmoduleFor_testing:For_testing.Swithtypeplugin_state=stateendendmoduletypeVcaml_plugin=sigmoduleOneshot:sigincludemoduletypeofstructincludeOneshotendmoduleMake(O:Arg):SendmodulePersistent:sigincludemoduletypeofstructincludePersistentendmoduleMake(P:Arg):Swithtypestate:=P.stateendend