Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove old eventlistener #1134

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 0 additions & 96 deletions src/FsAutoComplete.Core/Debug.fs
Original file line number Diff line number Diff line change
Expand Up @@ -80,99 +80,3 @@ module Debug =
#else
()
#endif


type LogCompilerFunctionId =
| Service_ParseAndCheckFileInProject = 1
| Service_CheckOneFile = 2
| Service_IncrementalBuildersCache_BuildingNewCache = 3
| Service_IncrementalBuildersCache_GettingCache = 4
| CompileOps_TypeCheckOneInputAndFinishEventually = 5
| IncrementalBuild_CreateItemKeyStoreAndSemanticClassification = 6
| IncrementalBuild_TypeCheck = 7

let logFunctionName (payload: obj) =
Log.addContextDestructured "function" (payload :?> int |> enum<LogCompilerFunctionId>)


module FSharpCompilerEventLogger =
open System.Diagnostics.Tracing

let logger = LogProvider.getLoggerByName "Compiler"

/// listener for the the events generated by the `FSharp.Compiler.FSharpCompilerEventSource`
type Listener() =
inherit EventListener()

let mutable source = null

let inflightEvents = ConcurrentDictionary<_, DateTimeOffset>()

let eventLevelToLogLevel (e: EventLevel) =
match e with
| EventLevel.Critical -> logger.fatal
| EventLevel.Error -> logger.error
| EventLevel.Informational -> logger.info
| EventLevel.LogAlways -> logger.fatal
| EventLevel.Verbose -> logger.debug
| EventLevel.Warning -> logger.warn
| _ -> logger.info

override __.OnEventSourceCreated newSource =
if newSource.Name = "FSharpCompiler" then
``base``.EnableEvents(newSource, EventLevel.LogAlways, EventKeywords.All)
source <- newSource

override __.OnEventWritten eventArgs =

let message =
match eventArgs.EventId with
| 0 -> Log.setMessage (string eventArgs.Payload.[0])
| 1 -> Log.setMessage "In {function}" >> logFunctionName eventArgs.Payload.[0]
| 2 ->
Log.setMessage "{function}: {message}"
>> logFunctionName eventArgs.Payload.[1]
>> Log.addContextDestructured "message" eventArgs.Payload.[0]
| 3 ->
inflightEvents.TryAdd(eventArgs.Task, DateTimeOffset.UtcNow) |> ignore

Log.setMessage "Started {function}" >> logFunctionName eventArgs.Payload.[0]
| 4 ->
match inflightEvents.TryRemove(eventArgs.Task) with
| true, startTime ->
let delta = DateTimeOffset.UtcNow - startTime

Log.setMessage "Finished {function} in {seconds}"
>> logFunctionName eventArgs.Payload.[0]
>> Log.addContextDestructured "seconds" delta.TotalSeconds
| false, _ -> Log.setMessage "Finished {function}" >> logFunctionName eventArgs.Payload.[0]
| 5 ->
inflightEvents.TryAdd(eventArgs.Task, DateTimeOffset.UtcNow) |> ignore

Log.setMessage "Started {function}: {message}"
>> logFunctionName eventArgs.Payload.[1]
>> Log.addContextDestructured "message" eventArgs.Payload.[0]
| 6 ->
match inflightEvents.TryRemove(eventArgs.Task) with
| true, startTime ->
let delta = DateTimeOffset.UtcNow - startTime

Log.setMessage "Finished {function}: {message} ({seconds} seconds)"
>> logFunctionName eventArgs.Payload.[1]
>> Log.addContextDestructured "seconds" delta.TotalSeconds
>> Log.addContextDestructured "message" (eventArgs.Payload.[0])
| false, _ ->
Log.setMessage "Finished {function}: {message}"
>> logFunctionName eventArgs.Payload.[1]
>> Log.addContextDestructured "message" eventArgs.Payload.[0]
| other ->
Log.setMessage "Unknown event {name}({id}) with payload {payload}"
>> Log.addContext "id" other
>> Log.addContextDestructured "name" eventArgs.EventName
>> Log.addContextDestructured "payload" (eventArgs.Payload |> Seq.toList)

eventLevelToLogLevel eventArgs.Level message

interface System.IDisposable with
member __.Dispose() =
if isNull source then () else ``base``.DisableEvents(source)
2 changes: 0 additions & 2 deletions src/FsAutoComplete/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ module Parser =
else
fun () -> FSharpLspServer.startCore toolsPath stateDirectory workspaceLoaderFactory sourceTextFactory

use _compilerEventListener = new Debug.FSharpCompilerEventLogger.Listener()

let result = FSharpLspServer.start lspFactory

Task.FromResult result),
Expand Down