Skip to content

Commit 70fc793

Browse files
committed
allow users to inject their own jsonRpc customizations
1 parent 669f323 commit 70fc793

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/LanguageServerProtocol.fs

+12-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Server =
1212
open Newtonsoft.Json
1313
open Ionide.LanguageServerProtocol.JsonUtils
1414
open Newtonsoft.Json.Linq
15+
open StreamJsonRpc
1516

1617
let logger = LogProvider.getLoggerByName "LSP Server"
1718

@@ -77,23 +78,28 @@ module Server =
7778
| ErrorExitWithoutShutdown = 1
7879
| ErrorStreamClosed = 2
7980

81+
82+
/// The default RPC logic shipped with this library. All this does is mark LocalRpcExceptions as non-fatal
83+
let defaultRpc (handler: IJsonRpcMessageHandler) =
84+
{ new JsonRpc(handler) with
85+
member this.IsFatalException(ex: Exception) =
86+
match ex with
87+
| :? LocalRpcException -> false
88+
| _ -> true }
89+
8090
let startWithSetup<'client when 'client :> Ionide.LanguageServerProtocol.ILspClient>
8191
(setupRequestHandlings: 'client -> Map<string, Delegate>)
8292
(input: Stream)
8393
(output: Stream)
8494
(clientCreator: (ClientNotificationSender * ClientRequestSender) -> 'client)
95+
(customizeRpc: IJsonRpcMessageHandler -> JsonRpc)
8596
=
8697

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

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

0 commit comments

Comments
 (0)