Skip to content

Commit

Permalink
Don't hook up SerilogTraceListener in FantomasDaemon. (#2777)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Mar 27, 2023
1 parent e49b20b commit 13e2a51
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Compile Include="Integration\WriteTests.fs" />
<Compile Include="Integration\DaemonTests.fs" />
<Compile Include="Integration\ForceTests.fs" />
<Compile Include="ToolLocatorTests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="$(FSharpCoreVersion)" />
Expand Down
25 changes: 25 additions & 0 deletions src/Fantomas.Tests/ToolLocatorTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Fantomas.CoreGlobalTool.Tests.ToolLocatorTests

open Fantomas.Client
open Fantomas.Client.LSPFantomasServiceTypes
open Fantomas.Client.Contracts
open NUnit.Framework

[<Explicit "This is meant to troubleshoot local problems">]
[<Test>]
let ``locate fantomas tool`` () =
let pwd = @"C:\Users\nojaf\Projects"
let result = FantomasToolLocator.findFantomasTool (Folder pwd)

match result with
| Error error -> Assert.Fail $"Could not locate tool: %A{error}"
| Ok(FantomasToolFound(FantomasVersion(version), startInfo)) ->
let result = FantomasToolLocator.createFor startInfo

match result with
| Error error -> Assert.Fail $"Could not start tool: %A{error}"
| Ok runningFantomasTool ->
let version2 =
runningFantomasTool.RpcClient.InvokeAsync<string>(Methods.Version).Result

Assert.AreEqual(version, $"v{version2}")
9 changes: 5 additions & 4 deletions src/Fantomas/Daemon.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ open Fantomas.EditorConfig

type FantomasDaemon(sender: Stream, reader: Stream) as this =
let rpc: JsonRpc = JsonRpc.Attach(sender, reader, this)
let traceListener = new DefaultTraceListener()

do
// hook up request/response logging for debugging
rpc.TraceSource <- TraceSource(typeof<FantomasDaemon>.Name, SourceLevels.Verbose)

rpc.TraceSource.Listeners.Add(new SerilogTraceListener.SerilogTraceListener(typeof<FantomasDaemon>.Name))
|> ignore<int>
rpc.TraceSource.Listeners.Add traceListener |> ignore<int>

let disconnectEvent = new ManualResetEvent(false)

Expand All @@ -33,7 +32,9 @@ type FantomasDaemon(sender: Stream, reader: Stream) as this =
do rpc.Disconnected.Add(fun _ -> exit ())

interface IDisposable with
member this.Dispose() = disconnectEvent.Dispose()
member this.Dispose() =
traceListener.Dispose()
disconnectEvent.Dispose()

/// returns a hot task that resolves when the stream has terminated
member this.WaitForClose = rpc.Completion
Expand Down

0 comments on commit 13e2a51

Please sign in to comment.