Skip to content

Commit

Permalink
1186 json serializer crash server (#1189)
Browse files Browse the repository at this point in the history
* Update LSP library

* Port JsonSerializationException for JsonRpc overrides
  • Loading branch information
TheAngryByrd committed Oct 28, 2023
1 parent be075d8 commit 6c27a03
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion paket.dependencies
Expand Up @@ -53,7 +53,7 @@ nuget Expecto.Diff
nuget YoloDev.Expecto.TestSdk
nuget AltCover
nuget GitHubActionsTestLogger
nuget Ionide.LanguageServerProtocol >= 0.4.18
nuget Ionide.LanguageServerProtocol >= 0.4.19
nuget Microsoft.Extensions.Caching.Memory
nuget OpenTelemetry.Api >= 1.3.2
nuget OpenTelemetry.Exporter.OpenTelemetryProtocol >= 1.3.2 # 1.4 bumps to 7.0 versions of System.Diagnostics libs, so can't use it
Expand Down
2 changes: 1 addition & 1 deletion paket.lock
Expand Up @@ -130,7 +130,7 @@ NUGET
System.Collections.Immutable (>= 5.0)
System.Reflection.Metadata (>= 5.0)
Ionide.KeepAChangelog.Tasks (0.1.8) - copy_local: true
Ionide.LanguageServerProtocol (0.4.18)
Ionide.LanguageServerProtocol (0.4.19)
FSharp.Core (>= 6.0)
Newtonsoft.Json (>= 13.0.1)
StreamJsonRpc (>= 2.10.44)
Expand Down
35 changes: 34 additions & 1 deletion src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
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,43 @@ 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 6c27a03

Please sign in to comment.