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 a41df62
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3098,6 +3098,7 @@ module AdaptiveFSharpLspServer =
| :? LocalRpcException -> Some()
| :? TaskCanceledException -> Some()
| :? OperationCanceledException -> Some()
| :? Newtonsoft.Json.JsonSerializationException -> Some()
| :? System.AggregateException as aex ->
if aex.InnerExceptions.Count = 1 then
(|HandleableException|_|) aex.InnerException
Expand All @@ -3107,11 +3108,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 a41df62

Please sign in to comment.