diff --git a/paket.dependencies b/paket.dependencies index 8f91bff44..caabd44a8 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -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 diff --git a/paket.lock b/paket.lock index 888bf3b42..c000ebfbb 100644 --- a/paket.lock +++ b/paket.lock @@ -120,7 +120,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) diff --git a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs index 170cff38f..ebba809ec 100644 --- a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs +++ b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs @@ -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 @@ -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()