From fde0ae075585bf0632c06e0a8dc65262e1010b6f Mon Sep 17 00:00:00 2001 From: majocha Date: Sat, 1 Apr 2023 16:36:59 +0200 Subject: [PATCH 1/6] dump activities to output pane --- .../src/FSharp.Editor/Common/Logging.fs | 8 +-- .../src/FSharp.Editor/FSharp.Editor.fsproj | 1 + .../LanguageService/ActivityLogger.fs | 55 +++++++++++++++++++ .../LanguageService/LanguageService.fs | 2 + 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 vsintegration/src/FSharp.Editor/LanguageService/ActivityLogger.fs diff --git a/vsintegration/src/FSharp.Editor/Common/Logging.fs b/vsintegration/src/FSharp.Editor/Common/Logging.fs index 4800b012779..ca9e6a93c0b 100644 --- a/vsintegration/src/FSharp.Editor/Common/Logging.fs +++ b/vsintegration/src/FSharp.Editor/Common/Logging.fs @@ -71,19 +71,19 @@ type Logger [] ([)>] ser match self.FSharpLoggingPane, msgType with | None, _ -> () | Some pane, LogType.Message -> - String.Format("[F#][{0}{1}] {2}{3}", "", time, msg, Environment.NewLine) + String.Format("[{0}{1}] {2}{3}", "", time, msg, Environment.NewLine) |> pane.OutputString |> ignore | Some pane, LogType.Info -> - String.Format("[F#][{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine) + String.Format("[{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine) |> pane.OutputString |> ignore | Some pane, LogType.Warn -> - String.Format("[F#][{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine) + String.Format("[{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine) |> pane.OutputString |> ignore | Some pane, LogType.Error -> - String.Format("[F#][{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine) + String.Format("[{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine) |> pane.OutputString |> ignore diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj index 6ba152f9233..2894c3d9d43 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj @@ -58,6 +58,7 @@ + diff --git a/vsintegration/src/FSharp.Editor/LanguageService/ActivityLogger.fs b/vsintegration/src/FSharp.Editor/LanguageService/ActivityLogger.fs new file mode 100644 index 00000000000..e0907c02224 --- /dev/null +++ b/vsintegration/src/FSharp.Editor/LanguageService/ActivityLogger.fs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace rec Microsoft.VisualStudio.FSharp.Editor + +open System +open System.ComponentModel.Design +open System.Runtime.InteropServices +open System.Threading +open System.IO +open System.Collections.Immutable +open Microsoft.CodeAnalysis +open Microsoft.CodeAnalysis.Options +open FSharp.Compiler +open FSharp.Compiler.CodeAnalysis +open FSharp.NativeInterop +open Microsoft.VisualStudio +open Microsoft.VisualStudio.Editor +open Microsoft.VisualStudio.FSharp.Editor +open Microsoft.VisualStudio.LanguageServices +open Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService +open Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem +open Microsoft.VisualStudio.LanguageServices.ProjectSystem +open Microsoft.VisualStudio.Shell +open Microsoft.VisualStudio.Shell.Interop +open Microsoft.VisualStudio.Text.Outlining +open Microsoft.CodeAnalysis.ExternalAccess.FSharp +open Microsoft.CodeAnalysis.Host +open Microsoft.CodeAnalysis.Host.Mef +open Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions +open Microsoft.VisualStudio.FSharp.Editor.Telemetry +open System.Threading.Tasks + +open System.Diagnostics +open Microsoft.VisualStudio.FSharp.Editor.Logging + +module ActivityLogger = + let startListening() = + + let indent (activity: Activity) = + let rec loop (activity: Activity) n = + if activity.Parent <> null then loop (activity.Parent) (n + 1) else n + String.replicate (loop activity 0) " " + let collectTags (activity: Activity) = + match [ for tag in activity.Tags -> $"{tag.Key}: {tag.Value.ToString()}" ] with + | [] -> "" + | tags -> "| " + String.concat ", " tags + + let listener = new ActivityListener( + ShouldListenTo = (fun source -> source.Name = "fsc"), + Sample = (fun _ -> ActivitySamplingResult.AllDataAndRecorded), + //ActivityStarted = (fun a -> logMsg $"{indent a}{a.OperationName}"), + ActivityStopped = (fun a -> logMsg $"{indent a}{a.OperationName} {collectTags a}") + ) + ActivitySource.AddActivityListener(listener) + diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index 0b51e1c7818..631af5507ff 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -321,6 +321,8 @@ type internal FSharpPackage() as this = let mutable solutionEventsOpt = None + let _logger = ActivityLogger.startListening() + // FSI-LINKAGE-POINT: unsited init do Microsoft.VisualStudio.FSharp.Interactive.Hooks.fsiConsoleWindowPackageCtorUnsited (this :> Package) From c7b604a97019f3d15dcec3b28496ab42fd73dca0 Mon Sep 17 00:00:00 2001 From: majocha Date: Sat, 1 Apr 2023 17:15:30 +0200 Subject: [PATCH 2/6] filter --- .../src/FSharp.Editor/Common/Logging.fs | 32 +++++++++++ .../src/FSharp.Editor/FSharp.Editor.fsproj | 1 - .../LanguageService/ActivityLogger.fs | 55 ------------------- .../LanguageService/LanguageService.fs | 6 +- 4 files changed, 37 insertions(+), 57 deletions(-) delete mode 100644 vsintegration/src/FSharp.Editor/LanguageService/ActivityLogger.fs diff --git a/vsintegration/src/FSharp.Editor/Common/Logging.fs b/vsintegration/src/FSharp.Editor/Common/Logging.fs index ca9e6a93c0b..c524b5b2160 100644 --- a/vsintegration/src/FSharp.Editor/Common/Logging.fs +++ b/vsintegration/src/FSharp.Editor/Common/Logging.fs @@ -112,3 +112,35 @@ module Logging = let logExceptionWithContext (ex: Exception, context) = logErrorf "Context: %s\nException Message: %s\nStack Trace: %s" context ex.Message ex.StackTrace + +module Activity = + let listen filter = + + let indent (activity: Activity) = + let rec loop (activity: Activity) n = + if activity.Parent <> null then + loop (activity.Parent) (n + 1) + else + n + + String.replicate (loop activity 0) " " + + let collectTags (activity: Activity) = + [ for tag in activity.Tags -> $"{tag.Key}: %A{tag.Value}" ] + |> String.concat ", " + + let listener = + new ActivityListener( + ShouldListenTo = (fun source -> source.Name = FSharp.Compiler.Diagnostics.ActivityNames.FscSourceName), + Sample = + (fun context -> + if context.Name.Contains(filter) then + ActivitySamplingResult.AllDataAndRecorded + else + ActivitySamplingResult.None), + ActivityStarted = (fun a -> logMsg $"{indent a}{a.OperationName} {collectTags a}") + ) + + ActivitySource.AddActivityListener(listener) + + let listenToAll () = listen "" diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj index 2894c3d9d43..6ba152f9233 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj @@ -58,7 +58,6 @@ - diff --git a/vsintegration/src/FSharp.Editor/LanguageService/ActivityLogger.fs b/vsintegration/src/FSharp.Editor/LanguageService/ActivityLogger.fs deleted file mode 100644 index e0907c02224..00000000000 --- a/vsintegration/src/FSharp.Editor/LanguageService/ActivityLogger.fs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. - -namespace rec Microsoft.VisualStudio.FSharp.Editor - -open System -open System.ComponentModel.Design -open System.Runtime.InteropServices -open System.Threading -open System.IO -open System.Collections.Immutable -open Microsoft.CodeAnalysis -open Microsoft.CodeAnalysis.Options -open FSharp.Compiler -open FSharp.Compiler.CodeAnalysis -open FSharp.NativeInterop -open Microsoft.VisualStudio -open Microsoft.VisualStudio.Editor -open Microsoft.VisualStudio.FSharp.Editor -open Microsoft.VisualStudio.LanguageServices -open Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService -open Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem -open Microsoft.VisualStudio.LanguageServices.ProjectSystem -open Microsoft.VisualStudio.Shell -open Microsoft.VisualStudio.Shell.Interop -open Microsoft.VisualStudio.Text.Outlining -open Microsoft.CodeAnalysis.ExternalAccess.FSharp -open Microsoft.CodeAnalysis.Host -open Microsoft.CodeAnalysis.Host.Mef -open Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions -open Microsoft.VisualStudio.FSharp.Editor.Telemetry -open System.Threading.Tasks - -open System.Diagnostics -open Microsoft.VisualStudio.FSharp.Editor.Logging - -module ActivityLogger = - let startListening() = - - let indent (activity: Activity) = - let rec loop (activity: Activity) n = - if activity.Parent <> null then loop (activity.Parent) (n + 1) else n - String.replicate (loop activity 0) " " - let collectTags (activity: Activity) = - match [ for tag in activity.Tags -> $"{tag.Key}: {tag.Value.ToString()}" ] with - | [] -> "" - | tags -> "| " + String.concat ", " tags - - let listener = new ActivityListener( - ShouldListenTo = (fun source -> source.Name = "fsc"), - Sample = (fun _ -> ActivitySamplingResult.AllDataAndRecorded), - //ActivityStarted = (fun a -> logMsg $"{indent a}{a.OperationName}"), - ActivityStopped = (fun a -> logMsg $"{indent a}{a.OperationName} {collectTags a}") - ) - ActivitySource.AddActivityListener(listener) - diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index 631af5507ff..454ee0e9f5c 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -321,7 +321,11 @@ type internal FSharpPackage() as this = let mutable solutionEventsOpt = None - let _logger = ActivityLogger.startListening() +#if DEBUG + let _logger = + // Logging.Activity.listen "IncrementalBuildSyntaxTree" + Logging.Activity.listen "IncrementalBuild" +#endif // FSI-LINKAGE-POINT: unsited init do Microsoft.VisualStudio.FSharp.Interactive.Hooks.fsiConsoleWindowPackageCtorUnsited (this :> Package) From f20c44f737d0f4a1c9c32c31ef7a28188cca7300 Mon Sep 17 00:00:00 2001 From: majocha Date: Wed, 5 Apr 2023 09:02:07 +0200 Subject: [PATCH 3/6] ok --- .../src/FSharp.Editor/LanguageService/LanguageService.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index 454ee0e9f5c..50c35a844a7 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -323,8 +323,8 @@ type internal FSharpPackage() as this = #if DEBUG let _logger = - // Logging.Activity.listen "IncrementalBuildSyntaxTree" - Logging.Activity.listen "IncrementalBuild" + Logging.Activity.listenToAll () + // Logging.Activity.listen "IncrementalBuild" #endif // FSI-LINKAGE-POINT: unsited init From 8724346bfdde242aed059413d81bf0c5bf5519f5 Mon Sep 17 00:00:00 2001 From: majocha Date: Wed, 5 Apr 2023 09:05:08 +0200 Subject: [PATCH 4/6] format --- vsintegration/src/FSharp.Editor/Common/Logging.fs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/Common/Logging.fs b/vsintegration/src/FSharp.Editor/Common/Logging.fs index c524b5b2160..3214da5e21e 100644 --- a/vsintegration/src/FSharp.Editor/Common/Logging.fs +++ b/vsintegration/src/FSharp.Editor/Common/Logging.fs @@ -96,7 +96,7 @@ module Logging = let private log logType msg = logger.Value.Log(logType, msg) let logMsg msg = log LogType.Message msg - let logInfo msg = log LogType.Info msg + //let logInfo msg = log LogType.Info msg let logWarning msg = log LogType.Warn msg let logError msg = log LogType.Error msg @@ -115,14 +115,12 @@ module Logging = module Activity = let listen filter = - let indent (activity: Activity) = let rec loop (activity: Activity) n = if activity.Parent <> null then loop (activity.Parent) (n + 1) else n - String.replicate (loop activity 0) " " let collectTags (activity: Activity) = From c544e00a708445d2f61cabae16bb6cf89be40938 Mon Sep 17 00:00:00 2001 From: majocha Date: Wed, 5 Apr 2023 09:12:29 +0200 Subject: [PATCH 5/6] what --- vsintegration/src/FSharp.Editor/Common/Logging.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vsintegration/src/FSharp.Editor/Common/Logging.fs b/vsintegration/src/FSharp.Editor/Common/Logging.fs index 3214da5e21e..db961a883ae 100644 --- a/vsintegration/src/FSharp.Editor/Common/Logging.fs +++ b/vsintegration/src/FSharp.Editor/Common/Logging.fs @@ -96,7 +96,7 @@ module Logging = let private log logType msg = logger.Value.Log(logType, msg) let logMsg msg = log LogType.Message msg - //let logInfo msg = log LogType.Info msg + let logInfo msg = log LogType.Info msg let logWarning msg = log LogType.Warn msg let logError msg = log LogType.Error msg @@ -121,6 +121,7 @@ module Activity = loop (activity.Parent) (n + 1) else n + String.replicate (loop activity 0) " " let collectTags (activity: Activity) = From acad6cc9d7877d848abb4c8cf50a3d9e041676eb Mon Sep 17 00:00:00 2001 From: majocha Date: Wed, 5 Apr 2023 09:21:25 +0200 Subject: [PATCH 6/6] fantomas --- .../src/FSharp.Editor/LanguageService/LanguageService.fs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index 50c35a844a7..6f63b565f0e 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -322,9 +322,8 @@ type internal FSharpPackage() as this = let mutable solutionEventsOpt = None #if DEBUG - let _logger = - Logging.Activity.listenToAll () - // Logging.Activity.listen "IncrementalBuild" + let _logger = Logging.Activity.listenToAll () + // Logging.Activity.listen "IncrementalBuild" #endif // FSI-LINKAGE-POINT: unsited init