From 1f364297d0d9414145ccee6d40c0c4b2617e7d3b Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Sat, 28 Oct 2023 14:03:36 -0400 Subject: [PATCH] Port JsonSerializationException for JsonRpc overrides --- .../LspServers/AdaptiveFSharpLspServer.fs | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs index 170cff38f..4fdac5435 100644 --- a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs +++ b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs @@ -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()