ribosome-host-0.9.9.9: Neovim plugin host for Polysemy
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ribosome.Host.Handler

Description

Combinators for creating and manipulating RPC handlers.

Synopsis

Documentation

rpcFunction Source #

Arguments

:: forall r h. HandlerCodec h r 
=> RpcName

Name of the Neovim function that will be created.

-> Execution

Execute sync or async.

-> h

The handler function.

-> RpcHandler r 

Create an RpcHandler that is triggered by a Neovim function of the specified name.

The handler can take arbitrary parameters, as long as they are instances of MsgpackDecode (or more specifically, HandlerArg), just like the return type.

When invoking the function from Neovim, a value must be passed for each of the handler function's parameters, except for some special cases, like a number of successive Maybe parameters at the tail of the parameter list.

The function is converted to use messagepack types by the class HandlerCodec.

For easier type inference, it is advisable to use Handler r a for the return type of the handler instead of using Member (Stop LogReport) r.

Example:

import Ribosome

ping :: Int -> Handler r Int
ping 0 = basicLogReport "Invalid ping number!" ["This is written to the log"]
ping i = pure i

rpcFunction "Ping" Sync ping

rpcCommand Source #

Arguments

:: forall r h. HandlerCodec h r 
=> CommandHandler OptionStateZero h 
=> RpcName

Name of the Neovim function that will be created.

-> Execution

Execute sync or async.

-> h

The handler function.

-> RpcHandler r 

Create an RpcHandler that is triggered by a Neovim command of the specified name.

The handler can take arbitrary parameters, as long as they are instances of MsgpackDecode (or more specifically, HandlerArg), just like the return type. The function is converted to use messagepack types by the class HandlerCodec.

Commands have an (open) family of special parameter types that will be translated into command options, like Range for the line range specified to the command. See command params.

For easier type inference, it is advisable to use Handler r a for the return type of the handler instead of using Member (Stop Report) r.

complete :: CommandCompletion -> RpcHandler r -> RpcHandler r Source #

Add the given completion to an RpcHandler.

completeBuiltin :: Text -> RpcHandler r -> RpcHandler r Source #

Configure the given RpcHandler to use the specified builtin completion.

completeCustom :: RpcName -> (Text -> Text -> Int -> Handler r [Text]) -> CompleteStyle -> RpcHandler r Source #

Create a completion handler that can be used by another handler by wrapping it with complete, using the same RpcName.

completeWith :: CompleteStyle -> (Text -> Text -> Int -> Handler r [Text]) -> RpcHandler r -> [RpcHandler r] Source #

Add command line completion to another RpcHandler by creating a new handler that calls the given function to obtain possible completions.

rpcAutocmd Source #

Arguments

:: forall r h. HandlerCodec h r 
=> RpcName 
-> Execution

Execute sync or async. While autocommands can not interact with return values, this is still useful to keep Neovim from continuing execution while the handler is active, which is particularly important for VimLeave.

-> AutocmdEvents

The Neovim event identifier, like BufWritePre or User.

-> AutocmdOptions

Various Neovim options like the file pattern.

-> h

The handler function.

-> RpcHandler r 

Create an RpcHandler that is triggered by a Neovim autocommand for the specified event. For a user autocommand, specify User for the event and the event name for the file pattern in AutocmdOptions.

For easier type inference, it is advisable to use Handler r a for the return type of the handler instead of using Member (Stop Report) r.

rpc :: forall r h. HandlerCodec h r => CommandHandler OptionStateZero h => RpcName -> Execution -> h -> [RpcHandler r] Source #

Convenience function for creating a handler that is triggered by both a function and a command of the same name. See rpcFunction and rpcCommand.