@@ -12,6 +12,7 @@ module Server =
12
12
open Newtonsoft.Json
13
13
open Ionide.LanguageServerProtocol .JsonUtils
14
14
open Newtonsoft.Json .Linq
15
+ open StreamJsonRpc
15
16
16
17
let logger = LogProvider.getLoggerByName " LSP Server"
17
18
@@ -77,23 +78,28 @@ module Server =
77
78
| ErrorExitWithoutShutdown = 1
78
79
| ErrorStreamClosed = 2
79
80
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
+
80
90
let startWithSetup < 'client when 'client :> Ionide.LanguageServerProtocol.ILspClient >
81
91
( setupRequestHandlings : 'client -> Map < string , Delegate >)
82
92
( input : Stream )
83
93
( output : Stream )
84
94
( clientCreator : ( ClientNotificationSender * ClientRequestSender ) -> 'client )
95
+ ( customizeRpc : IJsonRpcMessageHandler -> JsonRpc )
85
96
=
86
97
87
98
use jsonRpcHandler = new HeaderDelimitedMessageHandler( output, input, jsonRpcFormatter)
88
99
// Without overriding isFatalException, JsonRpc serializes exceptions and sends them to the client.
89
100
// This is particularly bad for notifications such as textDocument/didChange which don't require a response,
90
101
// 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
97
103
98
104
/// When the server wants to send a notification to the client
99
105
let sendServerNotification ( rpcMethod : string ) ( notificationObj : obj ) : AsyncLspResult < unit > =
0 commit comments