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

Ribosome.Host.Listener

Synopsis

Documentation

data ResponseLock Source #

Constructors

ResponseLock 

Instances

Instances details
Show ResponseLock Source # 
Instance details

Defined in Ribosome.Host.Listener

Eq ResponseLock Source # 
Instance details

Defined in Ribosome.Host.Listener

data ResponseSent Source #

Constructors

ResponseSent 

Instances

Instances details
Show ResponseSent Source # 
Instance details

Defined in Ribosome.Host.Listener

Eq ResponseSent Source # 
Instance details

Defined in Ribosome.Host.Listener

sendResponse :: Members [Process RpcMessage a, AtomicState RequestId, Events res ResponseSent, Log] r => RequestId -> Response -> Sem r () Source #

Send a response, increment the RequestId tracking the latest sent response, and publish an event that unblocks all waiting responses.

sendIfReady :: Member (Events res ResponseSent) r => Members [Tagged ResponseLock Lock, Process RpcMessage a, AtomicState RequestId, Log, Resource] r => RequestId -> Response -> Sem r Bool Source #

Check whether the last sent response has a RequestId one smaller than the current response. If true, send the response. This is protected by a mutex to avoid deadlock. Returns whether the response was sent for sendWhenReady to decide whether to recurse.

sendWhenReady :: Members [Events res ResponseSent, EventConsumer res ResponseSent] r => Members [Tagged ResponseLock Lock, Process RpcMessage a, AtomicState RequestId, Log, Resource] r => RequestId -> Response -> Sem r () Source #

Neovim doesn't permit responses to be sent out of order. If multiple requests from Neovim have been sent concurrently (e.g. triggered from rpc calls themselves, since the user can't achieve this through the UI due to it being single-threaded), and the first one runs longer than the rest, the others have to wait for the first response to be sent. Otherwise, Neovim will just terminate the client connection.

To ensure this, the last sent RequestId is stored and compared to the current response's ID before sending. If the last ID is not i - 1, this waits until all previous responses are sent. A new attempt to respond is triggered via Events in sendResponse. This function calls subscribe before doing the initial ID comparison, to avoid the race condition in which the last response is sent at the same time that the call to subscribe is made after comparing the IDs unsuccessfully and the ResponseSent event is therefore missed, causing this to block indefinitely.