Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow users to inject their own jsonRpc customizations #40

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/LanguageServerProtocol.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Server =
open Newtonsoft.Json
open Ionide.LanguageServerProtocol.JsonUtils
open Newtonsoft.Json.Linq
open StreamJsonRpc

let logger = LogProvider.getLoggerByName "LSP Server"

Expand Down Expand Up @@ -77,23 +78,28 @@ module Server =
| ErrorExitWithoutShutdown = 1
| ErrorStreamClosed = 2


/// The default RPC logic shipped with this library. All this does is mark LocalRpcExceptions as non-fatal
let defaultRpc (handler: IJsonRpcMessageHandler) =
{ new JsonRpc(handler) with
member this.IsFatalException(ex: Exception) =
match ex with
| :? LocalRpcException -> false
| _ -> true }

let startWithSetup<'client when 'client :> Ionide.LanguageServerProtocol.ILspClient>
(setupRequestHandlings: 'client -> Map<string, Delegate>)
(input: Stream)
(output: Stream)
(clientCreator: (ClientNotificationSender * ClientRequestSender) -> 'client)
(customizeRpc: IJsonRpcMessageHandler -> JsonRpc)
=

use jsonRpcHandler = new HeaderDelimitedMessageHandler(output, input, jsonRpcFormatter)
// Without overriding isFatalException, JsonRpc serializes exceptions and sends them to the client.
// This is particularly bad for notifications such as textDocument/didChange which don't require a response,
// and thus any exception that happens during e.g. text sync gets swallowed.
use jsonRpc =
{ new JsonRpc(jsonRpcHandler) with
member this.IsFatalException(ex: Exception) =
match ex with
| :? LocalRpcException -> false
| _ -> true }
use jsonRpc = customizeRpc jsonRpcHandler

/// When the server wants to send a notification to the client
let sendServerNotification (rpcMethod: string) (notificationObj: obj) : AsyncLspResult<unit> =
Expand Down