Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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