Skip to content

Commit

Permalink
Port JsonSerializationException for JsonRpc overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Oct 28, 2023
1 parent 6711fae commit 1f36429
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3107,11 +3107,42 @@ module AdaptiveFSharpLspServer =

let strategy = StreamJsonRpcTracingStrategy(Tracing.fsacActivitySource)

let (|Flatten|_|) (e : exn) =
match e with
| :? AggregateException as aex ->
let aex = aex.Flatten()
if aex.InnerExceptions.Count = 1 then
Some aex.InnerException
else
Some e
| _ -> Some e

let strategy = StreamJsonRpcTracingStrategy(Tracing.fsacActivitySource)

{ new JsonRpc(handler, ActivityTracingStrategy = strategy) with
member this.IsFatalException(ex: Exception) =
match ex with
| HandleableException -> false
| _ -> true }
| _ -> true

member this.CreateErrorDetails(request: Protocol.JsonRpcRequest, ex: Exception) =
let isSerializable = this.ExceptionStrategy = ExceptionProcessing.ISerializable

match ex with
| Flatten(:? Newtonsoft.Json.JsonSerializationException as ex) ->

let data: obj = if isSerializable then ex else Protocol.CommonErrorData(ex)

Protocol.JsonRpcError.ErrorDetail(
Code = Protocol.JsonRpcErrorCode.ParseError,
Message = ex.Message,
Data = data
)
| _ -> base.CreateErrorDetails(request, ex)

}



let startCore toolsPath workspaceLoaderFactory sourceTextFactory =
use input = Console.OpenStandardInput()
Expand Down

0 comments on commit 1f36429

Please sign in to comment.