From 97598905a29e0229ec6571cd80d0cd4c774cc55d Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 28 Mar 2023 17:28:00 +0200 Subject: [PATCH 1/2] Telemetry for codefixes --- .../FSharp.Editor/CodeFix/CodeFixHelpers.fs | 21 ++++++++++++++++++- .../Telemetry/TelemetryReporter.fs | 10 ++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs b/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs index 37b05589e9c..e4593335d9f 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs @@ -7,10 +7,24 @@ open System.Threading open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes open Microsoft.CodeAnalysis.CodeActions +open Microsoft.VisualStudio.FSharp.Editor.Telemetry [] module internal CodeFixHelpers = let createTextChangeCodeFix (title: string, context: CodeFixContext, computeTextChanges: unit -> Async) = + let props: (string * obj) list = [ + "title", title + + // The following can help building a unique but anonymized codefix target: + // #projectid#documentid#span + // Then we can check if the codefix was actually activated after its creation. + "context.document.project.id", context.Document.Project.Id.Id.ToString() + "context.document.id", context.Document.Id.Id.ToString() + "context.span", context.Span.ToString() + ] + + TelemetryReporter.reportEvent "codefixregistered" props + CodeAction.Create( title, (fun (cancellationToken: CancellationToken) -> @@ -20,7 +34,12 @@ module internal CodeFixHelpers = match changesOpt with | None -> return context.Document - | Some textChanges -> return context.Document.WithText(sourceText.WithChanges(textChanges)) + | Some textChanges -> + // Note: "activated" doesn't mean "applied". + // It's one step prior to that: + // e.g. when one clicks (Ctrl + .) and looks at the potential change. + TelemetryReporter.reportEvent "codefixactivated" props + return context.Document.WithText(sourceText.WithChanges(textChanges)) } |> RoslynHelpers.StartAsyncAsTask(cancellationToken)), title diff --git a/vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs b/vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs index d8228092ae6..1cfe1c42d6f 100644 --- a/vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs +++ b/vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs @@ -6,13 +6,13 @@ open Microsoft.VisualStudio.Telemetry module TelemetryReporter = - let eventPrefix = "dotnet/fsharp/" - let propPrefix = "dotnet.fsharp." + let private eventPrefix = "dotnet/fsharp/" + let private propPrefix = "dotnet.fsharp." - let getFullEventName name = eventPrefix + name - let getFullPropName name = propPrefix + name + let private getFullEventName name = eventPrefix + name + let private getFullPropName name = propPrefix + name - let createEvent name (props: (string * obj) list) = + let private createEvent name (props: (string * obj) list) = let event = TelemetryEvent(getFullEventName name) props From f5f695d8571c88b539fb135a4eb4522a427d2786 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 28 Mar 2023 19:06:32 +0200 Subject: [PATCH 2/2] fantomas --- .../FSharp.Editor/CodeFix/CodeFixHelpers.fs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs b/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs index e4593335d9f..643b48a30e2 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs @@ -12,16 +12,17 @@ open Microsoft.VisualStudio.FSharp.Editor.Telemetry [] module internal CodeFixHelpers = let createTextChangeCodeFix (title: string, context: CodeFixContext, computeTextChanges: unit -> Async) = - let props: (string * obj) list = [ - "title", title - - // The following can help building a unique but anonymized codefix target: - // #projectid#documentid#span - // Then we can check if the codefix was actually activated after its creation. - "context.document.project.id", context.Document.Project.Id.Id.ToString() - "context.document.id", context.Document.Id.Id.ToString() - "context.span", context.Span.ToString() - ] + let props: (string * obj) list = + [ + "title", title + + // The following can help building a unique but anonymized codefix target: + // #projectid#documentid#span + // Then we can check if the codefix was actually activated after its creation. + "context.document.project.id", context.Document.Project.Id.Id.ToString() + "context.document.id", context.Document.Id.Id.ToString() + "context.span", context.Span.ToString() + ] TelemetryReporter.reportEvent "codefixregistered" props @@ -36,7 +37,7 @@ module internal CodeFixHelpers = | None -> return context.Document | Some textChanges -> // Note: "activated" doesn't mean "applied". - // It's one step prior to that: + // It's one step prior to that: // e.g. when one clicks (Ctrl + .) and looks at the potential change. TelemetryReporter.reportEvent "codefixactivated" props return context.Document.WithText(sourceText.WithChanges(textChanges))