Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data SessionState = SessionState {
- initialized :: TMVar InitializeResult
- pendingRequests :: TVar RequestMap
- notificationHandlers :: TVar NotificationMap
- lastRequestId :: TVar Int32
- serverCapabilities :: TVar (HashMap Text SomeRegistration)
- clientCapabilities :: ClientCapabilities
- progressTokens :: TVar (HashSet ProgressToken)
- outgoing :: TQueue FromClientMessage
- vfs :: TVar VFS
- rootDir :: FilePath
- defaultSessionState :: VFS -> IO SessionState
- type Session = ReaderT SessionState IO
- documentChangeUri :: DocumentChange -> Uri
- handleServerMessage :: FromServerMessage -> Session ()
- sendRequest :: forall (m :: Method 'ClientToServer 'Request). TMessage m ~ TRequestMessage m => SMethod m -> MessageParams m -> (TResponseMessage m -> IO ()) -> Session (LspId m)
- sendResponse :: forall (m :: Method 'ServerToClient 'Request). TRequestMessage m -> Either ResponseError (MessageResult m) -> Session ()
- request :: forall (m :: Method 'ClientToServer 'Request). TMessage m ~ TRequestMessage m => SMethod m -> MessageParams m -> Session (TResponseMessage m)
- getResponseResult :: TResponseMessage m -> MessageResult m
- sendNotification :: forall (m :: Method 'ClientToServer 'Notification). TMessage m ~ TNotificationMessage m => SMethod m -> MessageParams m -> Session ()
- receiveNotification :: forall (m :: Method 'ServerToClient 'Notification). TMessage m ~ TNotificationMessage m => SMethod m -> (TMessage m -> IO ()) -> Session ()
- clearNotificationCallback :: forall (m :: Method 'ServerToClient 'Notification). SMethod m -> Session ()
- sendMessage :: FromClientMessage -> Session ()
- lspClientInfo :: Rec (("name" .== Text) .+ ("version" .== Maybe Text))
- initialize :: Session ()
- createDoc :: FilePath -> Text -> Text -> Session TextDocumentIdentifier
- openDoc :: FilePath -> Text -> Session TextDocumentIdentifier
- openDoc' :: FilePath -> Text -> Text -> Session TextDocumentIdentifier
- closeDoc :: TextDocumentIdentifier -> Session ()
- changeDoc :: TextDocumentIdentifier -> [TextDocumentContentChangeEvent] -> Session ()
- getDocUri :: FilePath -> Session Uri
- documentContents :: TextDocumentIdentifier -> Session (Maybe Rope)
- getVersionedDoc :: TextDocumentIdentifier -> Session VersionedTextDocumentIdentifier
Documentation
data SessionState Source #
SessionState | |
|
defaultSessionState :: VFS -> IO SessionState Source #
documentChangeUri :: DocumentChange -> Uri Source #
handleServerMessage :: FromServerMessage -> Session () Source #
Fires whenever the client receives a message from the server. Updates the session state as needed.
Note that this does not provide any business logic beyond updating the session state; you most likely
want to use sendRequest
and receiveNotification
to register callbacks for specific messages.
sendRequest :: forall (m :: Method 'ClientToServer 'Request). TMessage m ~ TRequestMessage m => SMethod m -> MessageParams m -> (TResponseMessage m -> IO ()) -> Session (LspId m) Source #
Sends a request to the server, with a callback that fires when the response arrives. Multiple requests can be waiting at the same time.
sendResponse :: forall (m :: Method 'ServerToClient 'Request). TRequestMessage m -> Either ResponseError (MessageResult m) -> Session () Source #
Send a response to the server. This is used internally to acknowledge server requests. Users of this library cannot register callbacks to server requests, so this function is probably of no use to them.
request :: forall (m :: Method 'ClientToServer 'Request). TMessage m ~ TRequestMessage m => SMethod m -> MessageParams m -> Session (TResponseMessage m) Source #
Sends a request to the server and synchronously waits for its response.
getResponseResult :: TResponseMessage m -> MessageResult m Source #
Checks the response for errors and throws an exception if needed. Returns the result if successful.
sendNotification :: forall (m :: Method 'ClientToServer 'Notification). TMessage m ~ TNotificationMessage m => SMethod m -> MessageParams m -> Session () Source #
Sends a notification to the server. Updates the VFS if the notification is a document update.
receiveNotification :: forall (m :: Method 'ServerToClient 'Notification). TMessage m ~ TNotificationMessage m => SMethod m -> (TMessage m -> IO ()) -> Session () Source #
Registers a callback for notifications received from the server. If multiple callbacks are registered for the same notification method, they will all be called.
clearNotificationCallback :: forall (m :: Method 'ServerToClient 'Notification). SMethod m -> Session () Source #
Clears the registered callback for the given notification method, if any. If multiple callbacks have been registered, this clears all of them.
sendMessage :: FromClientMessage -> Session () Source #
Queues a message to be sent to the server at the client's earliest convenience.
initialize :: Session () Source #
Performs the initialisation handshake and synchronously waits for its completion. When the function completes, the session is initialised.
:: FilePath | The path to the document to open, relative to the root directory. |
-> Text | The text document's language identifier, e.g. |
-> Text | The content of the text document to create. |
-> Session TextDocumentIdentifier | The identifier of the document just created. |
Creates a new text document. This is different from openDoc
as it sends a workspace/didChangeWatchedFiles
notification letting the server
know that a file was created within the workspace, __provided that the server
has registered for it__, and the file matches any patterns the server
registered for.
It does not actually create a file on disk, but is useful for convincing
the server that one does exist.
openDoc :: FilePath -> Text -> Session TextDocumentIdentifier Source #
Opens a text document that exists on disk, and sends a
textDocument/didOpen
notification to the server.
openDoc' :: FilePath -> Text -> Text -> Session TextDocumentIdentifier Source #
This is a variant of openDoc
that takes the file content as an argument.
Use this is the file exists outside of the current workspace.
closeDoc :: TextDocumentIdentifier -> Session () Source #
Closes a text document and sends a textDocument/didClose
notification to the server.
changeDoc :: TextDocumentIdentifier -> [TextDocumentContentChangeEvent] -> Session () Source #
Changes a text document and sends a textDocument/didChange
notification to the server.
getDocUri :: FilePath -> Session Uri Source #
Gets the Uri for the file relative to the session's root directory.
documentContents :: TextDocumentIdentifier -> Session (Maybe Rope) Source #
The current text contents of a document.
getVersionedDoc :: TextDocumentIdentifier -> Session VersionedTextDocumentIdentifier Source #
Adds the current version to the document, as tracked by the session.