From 362af9ee8a313a66028a54eb28416c480f5ae3f4 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 5 Apr 2023 17:47:37 +0200 Subject: [PATCH] Extra telemetry for codefixes --- .../CodeFix/AddInstanceMemberParameter.fs | 3 +- .../AddMissingEqualsToTypeDefinition.fs | 5 +- .../CodeFix/AddMissingFunKeyword.fs | 3 +- ...eywordToDisposableConstructorInvocation.fs | 3 +- .../CodeFix/AddOpenCodeFixProvider.fs | 3 +- .../ChangePrefixNegationToInfixSubtraction.fs | 3 +- .../ChangeRefCellDerefToNotExpression.fs | 9 +- .../FSharp.Editor/CodeFix/ChangeToUpcast.fs | 3 +- .../FSharp.Editor/CodeFix/CodeFixHelpers.fs | 19 ++++- .../ConvertCSharpLambdaToFSharpLambda.fs | 9 +- .../CodeFix/ConvertCSharpUsingToFSharpOpen.fs | 9 +- .../ConvertToNotEqualsEqualityExpression.fs | 9 +- ...ConvertToSingleEqualsEqualityExpression.fs | 9 +- .../FSharp.Editor/CodeFix/FixIndexerAccess.fs | 9 +- .../CodeFix/MakeDeclarationMutable.fs | 6 +- .../CodeFix/MakeOuterBindingRecursive.fs | 3 +- .../CodeFix/RemoveReturnOrYield.fs | 3 +- ...SuperflousCaptureForUnionCaseWithNoData.fs | 9 +- .../CodeFix/RemoveUnusedBinding.fs | 9 +- .../CodeFix/RemoveUnusedOpens.fs | 4 +- .../CodeFix/RenameParamToMatchSignature.fs | 4 +- .../CodeFix/RenameUnusedValue.fs | 4 +- .../CodeFix/ReplaceWithSuggestion.fs | 3 +- .../src/FSharp.Editor/CodeFix/SimplifyName.fs | 3 +- .../CodeFix/UseMutationWhenValueIsMutable.fs | 6 +- .../CodeFix/UseTripleQuotedInterpolation.fs | 9 +- .../src/FSharp.Editor/Common/Constants.fs | 83 +++++++++++++++++++ 27 files changed, 188 insertions(+), 54 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/AddInstanceMemberParameter.fs b/vsintegration/src/FSharp.Editor/CodeFix/AddInstanceMemberParameter.fs index 292fbc1592a..e3180651f9b 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/AddInstanceMemberParameter.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/AddInstanceMemberParameter.fs @@ -8,7 +8,7 @@ open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpAddInstanceMemberParameterCodeFixProvider() = inherit CodeFixProvider() @@ -27,6 +27,7 @@ type internal FSharpAddInstanceMemberParameterCodeFixProvider() = let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.AddInstanceMemberParameter, title, context, (fun () -> asyncMaybe.Return [| TextChange(TextSpan(context.Span.Start, 0), "x.") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/AddMissingEqualsToTypeDefinition.fs b/vsintegration/src/FSharp.Editor/CodeFix/AddMissingEqualsToTypeDefinition.fs index 5b7360320ea..f667c624e3b 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/AddMissingEqualsToTypeDefinition.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/AddMissingEqualsToTypeDefinition.fs @@ -6,12 +6,10 @@ open System open System.Composition open System.Threading.Tasks -open Microsoft.VisualStudio.FSharp.Editor.Logging - open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpAddMissingEqualsToTypeDefinitionCodeFixProvider() = inherit CodeFixProvider() @@ -43,6 +41,7 @@ type internal FSharpAddMissingEqualsToTypeDefinitionCodeFixProvider() = let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.AddMissingEqualsToTypeDefinition, title, context, // 'pos + 1' is here because 'pos' is now the position of the first non-whitespace character. diff --git a/vsintegration/src/FSharp.Editor/CodeFix/AddMissingFunKeyword.fs b/vsintegration/src/FSharp.Editor/CodeFix/AddMissingFunKeyword.fs index 8f1a286f1a5..234c4bd0594 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/AddMissingFunKeyword.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/AddMissingFunKeyword.fs @@ -11,7 +11,7 @@ open Microsoft.CodeAnalysis.CodeFixes open FSharp.Compiler open FSharp.Compiler.CodeAnalysis -[] +[] type internal FSharpAddMissingFunKeywordCodeFixProvider [] () = inherit CodeFixProvider() @@ -65,6 +65,7 @@ type internal FSharpAddMissingFunKeywordCodeFixProvider [] let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.AddMissingFunKeyword, title, context, (fun () -> asyncMaybe.Return [| TextChange(TextSpan(intendedArgSpan.Start, 0), "fun ") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/AddNewKeywordToDisposableConstructorInvocation.fs b/vsintegration/src/FSharp.Editor/CodeFix/AddNewKeywordToDisposableConstructorInvocation.fs index adbb5290f91..d6dcfd30d34 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/AddNewKeywordToDisposableConstructorInvocation.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/AddNewKeywordToDisposableConstructorInvocation.fs @@ -8,7 +8,7 @@ open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpAddNewKeywordCodeFixProvider() = inherit CodeFixProvider() @@ -27,6 +27,7 @@ type internal FSharpAddNewKeywordCodeFixProvider() = let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.AddNewKeyword, title, context, (fun () -> asyncMaybe.Return [| TextChange(TextSpan(context.Span.Start, 0), "new ") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs b/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs index cf709d695cd..dcb40c4cb6c 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs @@ -17,7 +17,7 @@ open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.EditorServices open FSharp.Compiler.Text -[] +[] type internal FSharpAddOpenCodeFixProvider [] (assemblyContentProvider: AssemblyContentProvider) = inherit CodeFixProvider() @@ -27,6 +27,7 @@ type internal FSharpAddOpenCodeFixProvider [] (assemblyCon let qualifySymbolFix (context: CodeFixContext) (fullName, qualifier) = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.AddOpen, fixUnderscoresInMenuText fullName, context, (fun () -> asyncMaybe.Return [| TextChange(context.Span, qualifier) |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs b/vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs index b734cdc0ae7..12296f0bd67 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs @@ -9,7 +9,7 @@ open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpChangePrefixNegationToInfixSubtractionodeFixProvider() = inherit CodeFixProvider() @@ -44,6 +44,7 @@ type internal FSharpChangePrefixNegationToInfixSubtractionodeFixProvider() = let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.ChangePrefixNegationToInfixSubtraction, title, context, (fun () -> asyncMaybe.Return [| TextChange(TextSpan(pos, 1), "- ") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ChangeRefCellDerefToNotExpression.fs b/vsintegration/src/FSharp.Editor/CodeFix/ChangeRefCellDerefToNotExpression.fs index f8019fe16a4..04b40ec52be 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/ChangeRefCellDerefToNotExpression.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/ChangeRefCellDerefToNotExpression.fs @@ -8,7 +8,7 @@ open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpChangeRefCellDerefToNotExpressionCodeFixProvider [] () = inherit CodeFixProvider() @@ -40,7 +40,12 @@ type internal FSharpChangeRefCellDerefToNotExpressionCodeFixProvider [ Seq.toImmutableArray let codeFix = - CodeFixHelpers.createTextChangeCodeFix (title, context, (fun () -> asyncMaybe.Return [| TextChange(derefSpan, "not ") |])) + CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.ChangeRefCellDerefToNotExpression, + title, + context, + (fun () -> asyncMaybe.Return [| TextChange(derefSpan, "not ") |]) + ) context.RegisterCodeFix(codeFix, diagnostics) } diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs b/vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs index d205d320a68..d2e7faedc3c 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs @@ -8,7 +8,7 @@ open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpChangeToUpcastCodeFixProvider() = inherit CodeFixProvider() @@ -50,6 +50,7 @@ type internal FSharpChangeToUpcastCodeFixProvider() = let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.ChangeToUpcast, title, context, (fun () -> asyncMaybe.Return [| TextChange(context.Span, replacement) |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs b/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs index 643b48a30e2..10c9f760adf 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs @@ -11,9 +11,22 @@ open Microsoft.VisualStudio.FSharp.Editor.Telemetry [] module internal CodeFixHelpers = - let createTextChangeCodeFix (title: string, context: CodeFixContext, computeTextChanges: unit -> Async) = + let createTextChangeCodeFix + ( + name: string, + title: string, + context: CodeFixContext, + computeTextChanges: unit -> Async + ) = + + // I don't understand how we can get anything but a single diagnostic here - as we get a single "title" here. + // But since we don't have proper testing yet, keeping it like this to verify this theory in telemetry. + let ids = context.Diagnostics |> Seq.map (fun d -> d.Id) |> String.concat "," + let props: (string * obj) list = [ + "name", name + "ids", ids "title", title // The following can help building a unique but anonymized codefix target: @@ -53,8 +66,8 @@ module internal CodeFixExtensions = member this.GetPrunedDiagnostics(context: CodeFixContext) = context.Diagnostics.RemoveAll(fun x -> this.FixableDiagnosticIds.Contains(x.Id) |> not) - member this.RegisterFix(context: CodeFixContext, fixName, fixChange) = + member this.RegisterFix(name, title, context: CodeFixContext, fixChange) = let replaceCodeFix = - CodeFixHelpers.createTextChangeCodeFix (fixName, context, (fun () -> asyncMaybe.Return [| fixChange |])) + CodeFixHelpers.createTextChangeCodeFix (name, title, context, (fun () -> asyncMaybe.Return [| fixChange |])) context.RegisterCodeFix(replaceCodeFix, this.GetPrunedDiagnostics(context)) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpLambdaToFSharpLambda.fs b/vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpLambdaToFSharpLambda.fs index 7f88b123aa9..1c38dc2e021 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpLambdaToFSharpLambda.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpLambdaToFSharpLambda.fs @@ -7,7 +7,7 @@ open System.Composition open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpConvertCSharpLambdaToFSharpLambdaCodeFixProvider [] () = inherit CodeFixProvider() @@ -46,7 +46,12 @@ type internal FSharpConvertCSharpLambdaToFSharpLambdaCodeFixProvider [ asyncMaybe.Return [| replacement |])) + CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.ConvertCSharpLambdaToFSharpLambda, + title, + context, + (fun () -> asyncMaybe.Return [| replacement |]) + ) context.RegisterCodeFix(codeFix, diagnostics) } diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpUsingToFSharpOpen.fs b/vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpUsingToFSharpOpen.fs index 9181d6b5cd7..d92eea460a2 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpUsingToFSharpOpen.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/ConvertCSharpUsingToFSharpOpen.fs @@ -10,7 +10,7 @@ open Microsoft.CodeAnalysis open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpConvertCSharpUsingToFSharpOpen [] () = inherit CodeFixProvider() @@ -47,7 +47,12 @@ type internal FSharpConvertCSharpUsingToFSharpOpen [] () = let title = SR.ConvertCSharpUsingToFSharpOpen() let codeFix = - CodeFixHelpers.createTextChangeCodeFix (title, context, (fun () -> asyncMaybe.Return [| replacement |])) + CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.ConvertCSharpUsingToFSharpOpen, + title, + context, + (fun () -> asyncMaybe.Return [| replacement |]) + ) context.RegisterCodeFix(codeFix, diagnostics) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ConvertToNotEqualsEqualityExpression.fs b/vsintegration/src/FSharp.Editor/CodeFix/ConvertToNotEqualsEqualityExpression.fs index 58ec9348d44..f1304f3996f 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/ConvertToNotEqualsEqualityExpression.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/ConvertToNotEqualsEqualityExpression.fs @@ -8,7 +8,7 @@ open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpConvertToNotEqualsEqualityExpressionCodeFixProvider() = inherit CodeFixProvider() @@ -33,7 +33,12 @@ type internal FSharpConvertToNotEqualsEqualityExpressionCodeFixProvider() = |> Seq.toImmutableArray let codeFix = - CodeFixHelpers.createTextChangeCodeFix (title, context, (fun () -> asyncMaybe.Return [| TextChange(context.Span, "<>") |])) + CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.ConvertToNotEqualsEqualityExpression, + title, + context, + (fun () -> asyncMaybe.Return [| TextChange(context.Span, "<>") |]) + ) context.RegisterCodeFix(codeFix, diagnostics) } diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ConvertToSingleEqualsEqualityExpression.fs b/vsintegration/src/FSharp.Editor/CodeFix/ConvertToSingleEqualsEqualityExpression.fs index c06b6e5bbd4..6832851a189 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/ConvertToSingleEqualsEqualityExpression.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/ConvertToSingleEqualsEqualityExpression.fs @@ -8,7 +8,7 @@ open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpConvertToSingleEqualsEqualityExpressionCodeFixProvider() = inherit CodeFixProvider() @@ -33,7 +33,12 @@ type internal FSharpConvertToSingleEqualsEqualityExpressionCodeFixProvider() = |> Seq.toImmutableArray let codeFix = - CodeFixHelpers.createTextChangeCodeFix (title, context, (fun () -> asyncMaybe.Return [| TextChange(context.Span, "=") |])) + CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.ConvertToSingleEqualsEqualityExpression, + title, + context, + (fun () -> asyncMaybe.Return [| TextChange(context.Span, "=") |]) + ) context.RegisterCodeFix(codeFix, diagnostics) } diff --git a/vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs b/vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs index bc6d1bfb820..c594e86afd6 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/FixIndexerAccess.fs @@ -10,7 +10,7 @@ open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes open FSharp.Compiler.Diagnostics -[] +[] type internal LegacyFsharpFixAddDotToIndexerAccess() = inherit CodeFixProvider() let fixableDiagnosticIds = set [ "FS3217" ] @@ -49,6 +49,7 @@ type internal LegacyFsharpFixAddDotToIndexerAccess() = let codefix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.FixIndexerAccess, CompilerDiagnostics.GetErrorMessage FSharpDiagnosticKind.AddIndexerDot, context, (fun () -> asyncMaybe.Return [| TextChange(span, replacement.TrimEnd() + ".") |]) @@ -58,12 +59,12 @@ type internal LegacyFsharpFixAddDotToIndexerAccess() = } |> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken) -[] +[] type internal FsharpFixRemoveDotFromIndexerAccessOptIn() as this = inherit CodeFixProvider() let fixableDiagnosticIds = set [ "FS3366" ] - static let fixName = + static let title = CompilerDiagnostics.GetErrorMessage FSharpDiagnosticKind.RemoveIndexerDot override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds @@ -73,5 +74,5 @@ type internal FsharpFixRemoveDotFromIndexerAccessOptIn() as this = let relevantDiagnostics = this.GetPrunedDiagnostics(context) if not relevantDiagnostics.IsEmpty then - this.RegisterFix(context, fixName, TextChange(context.Span, "")) + this.RegisterFix(CodeFix.RemoveIndexerDotBeforeBracket, title, context, TextChange(context.Span, "")) } diff --git a/vsintegration/src/FSharp.Editor/CodeFix/MakeDeclarationMutable.fs b/vsintegration/src/FSharp.Editor/CodeFix/MakeDeclarationMutable.fs index 2095a91762a..aefbc74be70 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/MakeDeclarationMutable.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/MakeDeclarationMutable.fs @@ -3,18 +3,15 @@ namespace Microsoft.VisualStudio.FSharp.Editor open System.Composition -open System.Threading open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -open FSharp.Compiler -open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.EditorServices open FSharp.Compiler.Text -[] +[] type internal FSharpMakeDeclarationMutableFixProvider [] () = inherit CodeFixProvider() @@ -73,6 +70,7 @@ type internal FSharpMakeDeclarationMutableFixProvider [] ( let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.MakeDeclarationMutable, title, context, (fun () -> asyncMaybe.Return [| TextChange(TextSpan(span.Start, 0), "mutable ") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/MakeOuterBindingRecursive.fs b/vsintegration/src/FSharp.Editor/CodeFix/MakeOuterBindingRecursive.fs index dd64ca93fa9..bae864afebb 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/MakeOuterBindingRecursive.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/MakeOuterBindingRecursive.fs @@ -8,7 +8,7 @@ open System.Composition open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpMakeOuterBindingRecursiveCodeFixProvider [] () = inherit CodeFixProvider() @@ -50,6 +50,7 @@ type internal FSharpMakeOuterBindingRecursiveCodeFixProvider [ asyncMaybe.Return [| TextChange(TextSpan(outerBindingNameSpan.Start, 0), "rec ") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/RemoveReturnOrYield.fs b/vsintegration/src/FSharp.Editor/CodeFix/RemoveReturnOrYield.fs index 04c8d8e2fe2..a002916639d 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/RemoveReturnOrYield.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/RemoveReturnOrYield.fs @@ -7,7 +7,7 @@ open System.Composition open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpRemoveReturnOrYieldCodeFixProvider [] () = inherit CodeFixProvider() @@ -44,6 +44,7 @@ type internal FSharpRemoveReturnOrYieldCodeFixProvider [] let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.RemoveReturnOrYield, title, context, (fun () -> asyncMaybe.Return [| TextChange(context.Span, sourceText.GetSubText(exprSpan).ToString()) |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/RemoveSuperflousCaptureForUnionCaseWithNoData.fs b/vsintegration/src/FSharp.Editor/CodeFix/RemoveSuperflousCaptureForUnionCaseWithNoData.fs index 2de05866fef..bc49d1f13d3 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/RemoveSuperflousCaptureForUnionCaseWithNoData.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/RemoveSuperflousCaptureForUnionCaseWithNoData.fs @@ -2,20 +2,15 @@ namespace Microsoft.VisualStudio.FSharp.Editor -open System open System.Composition open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -open FSharp.Compiler -open FSharp.Compiler.CodeAnalysis -open FSharp.Compiler.Symbols -open FSharp.Compiler.Syntax open FSharp.Compiler.EditorServices -[] +[] type internal RemoveSuperflousCaptureForUnionCaseWithNoDataProvider [] () = inherit CodeFixProvider() @@ -51,7 +46,7 @@ type internal RemoveSuperflousCaptureForUnionCaseWithNoDataProvider [ Async.Ignore |> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedBinding.fs b/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedBinding.fs index ff900a049dd..e290cb7173e 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedBinding.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedBinding.fs @@ -9,7 +9,7 @@ open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpRemoveUnusedBindingCodeFixProvider [] () = inherit CodeFixProvider() @@ -57,7 +57,12 @@ type internal FSharpRemoveUnusedBindingCodeFixProvider [] let prefixTitle = SR.RemoveUnusedBinding() let removalCodeFix = - CodeFixHelpers.createTextChangeCodeFix (prefixTitle, context, (fun () -> asyncMaybe.Return [| TextChange(fullSpan, "") |])) + CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.RemoveUnusedBinding, + prefixTitle, + context, + (fun () -> asyncMaybe.Return [| TextChange(fullSpan, "") |]) + ) context.RegisterCodeFix(removalCodeFix, diagnostics) } diff --git a/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedOpens.fs b/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedOpens.fs index e748c3e168b..f46e1018f49 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedOpens.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedOpens.fs @@ -11,7 +11,7 @@ open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics open FSharp.Compiler.Text -[] +[] type internal FSharpRemoveUnusedOpensCodeFixProvider [] () = inherit CodeFixProvider() @@ -41,7 +41,7 @@ type internal FSharpRemoveUnusedOpensCodeFixProvider [] () let title = SR.RemoveUnusedOpens() let codefix = - CodeFixHelpers.createTextChangeCodeFix (title, context, (fun () -> asyncMaybe.Return changes)) + CodeFixHelpers.createTextChangeCodeFix (CodeFix.RemoveUnusedOpens, title, context, (fun () -> asyncMaybe.Return changes)) context.RegisterCodeFix(codefix, diagnostics) } diff --git a/vsintegration/src/FSharp.Editor/CodeFix/RenameParamToMatchSignature.fs b/vsintegration/src/FSharp.Editor/CodeFix/RenameParamToMatchSignature.fs index f7429fe99d4..68ca143aef5 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/RenameParamToMatchSignature.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/RenameParamToMatchSignature.fs @@ -13,7 +13,7 @@ open Microsoft.VisualStudio.FSharp.Editor.SymbolHelpers open FSharp.Compiler.Diagnostics open FSharp.Compiler.Tokenization.FSharpKeywords -[] +[] type internal FSharpRenameParamToMatchSignature [] () = inherit CodeFixProvider() @@ -65,7 +65,7 @@ type internal FSharpRenameParamToMatchSignature [] () = CompilerDiagnostics.GetErrorMessage(FSharpDiagnosticKind.ReplaceWithSuggestion suggestion) let codefix = - CodeFixHelpers.createTextChangeCodeFix (title, context, computeChanges) + CodeFixHelpers.createTextChangeCodeFix (CodeFix.FSharpRenameParamToMatchSignature, title, context, computeChanges) context.RegisterCodeFix(codefix, diagnostics) | _ -> () diff --git a/vsintegration/src/FSharp.Editor/CodeFix/RenameUnusedValue.fs b/vsintegration/src/FSharp.Editor/CodeFix/RenameUnusedValue.fs index acbdf900dc2..06a99d9538f 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/RenameUnusedValue.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/RenameUnusedValue.fs @@ -14,7 +14,7 @@ open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.Symbols open FSharp.Compiler.Syntax -[] +[] type internal FSharpRenameUnusedValueCodeFixProvider [] () = inherit CodeFixProvider() @@ -67,6 +67,7 @@ type internal FSharpRenameUnusedValueCodeFixProvider [] () let prefixCodeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.RenameUnusedValue, prefixTitle, context, (fun () -> asyncMaybe.Return [| TextChange(TextSpan(context.Span.Start, 0), "_") |]) @@ -79,6 +80,7 @@ type internal FSharpRenameUnusedValueCodeFixProvider [] () let replaceCodeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.RenameUnusedValue, replaceTitle, context, (fun () -> asyncMaybe.Return [| TextChange(context.Span, "_") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs b/vsintegration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs index a01869b9cfd..b6c53999150 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs @@ -14,7 +14,7 @@ open FSharp.Compiler.Syntax open FSharp.Compiler.Text open FSharp.Compiler.Tokenization -[] +[] type internal FSharpReplaceWithSuggestionCodeFixProvider [] (settings: EditorOptions) = inherit CodeFixProvider() @@ -61,6 +61,7 @@ type internal FSharpReplaceWithSuggestionCodeFixProvider [ let codeFix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.ReplaceWithSuggestion, CompilerDiagnostics.GetErrorMessage(FSharpDiagnosticKind.ReplaceWithSuggestion suggestion), context, (fun () -> asyncMaybe.Return [| TextChange(context.Span, replacement) |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/SimplifyName.fs b/vsintegration/src/FSharp.Editor/CodeFix/SimplifyName.fs index ee613f4171e..34bbfab9d93 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/SimplifyName.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/SimplifyName.fs @@ -10,7 +10,7 @@ open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics -[] +[] type internal FSharpSimplifyNameCodeFixProvider() = inherit CodeFixProvider() let fixableDiagnosticId = FSharpIDEDiagnosticIds.SimplifyNamesDiagnosticId @@ -27,6 +27,7 @@ type internal FSharpSimplifyNameCodeFixProvider() = let codefix = CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.SimplifyName, title, context, (fun () -> asyncMaybe.Return [| TextChange(context.Span, "") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/UseMutationWhenValueIsMutable.fs b/vsintegration/src/FSharp.Editor/CodeFix/UseMutationWhenValueIsMutable.fs index 71d2ab27ad8..f1358f569dc 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/UseMutationWhenValueIsMutable.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/UseMutationWhenValueIsMutable.fs @@ -4,18 +4,15 @@ namespace Microsoft.VisualStudio.FSharp.Editor open System open System.Composition -open System.Threading open System.Threading.Tasks open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -open FSharp.Compiler -open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.Symbols open FSharp.Compiler.Text -[] +[] type internal FSharpUseMutationWhenValueIsMutableFixProvider [] () = inherit CodeFixProvider() @@ -83,6 +80,7 @@ type internal FSharpUseMutationWhenValueIsMutableFixProvider [ asyncMaybe.Return [| TextChange(TextSpan(pos + 1, 1), "<-") |]) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/UseTripleQuotedInterpolation.fs b/vsintegration/src/FSharp.Editor/CodeFix/UseTripleQuotedInterpolation.fs index 4dca06ea3bc..9249c01088f 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/UseTripleQuotedInterpolation.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/UseTripleQuotedInterpolation.fs @@ -7,7 +7,7 @@ open System.Composition open Microsoft.CodeAnalysis.Text open Microsoft.CodeAnalysis.CodeFixes -[] +[] type internal FSharpUseTripleQuotedInterpolationCodeFixProvider [] () = inherit CodeFixProvider() @@ -41,7 +41,12 @@ type internal FSharpUseTripleQuotedInterpolationCodeFixProvider [ asyncMaybe.Return [| replacement |])) + CodeFixHelpers.createTextChangeCodeFix ( + CodeFix.UseTripleQuotedInterpolation, + title, + context, + (fun () -> asyncMaybe.Return [| replacement |]) + ) context.RegisterCodeFix(codeFix, diagnostics) } diff --git a/vsintegration/src/FSharp.Editor/Common/Constants.fs b/vsintegration/src/FSharp.Editor/Common/Constants.fs index f1bacf63cc1..b2585dc3272 100644 --- a/vsintegration/src/FSharp.Editor/Common/Constants.fs +++ b/vsintegration/src/FSharp.Editor/Common/Constants.fs @@ -94,3 +94,86 @@ module internal Guids = let formattingOptionPageIdString = "9EBEBCE8-A79B-46B0-A8C5-A9818AEED17D" let blueHighContrastThemeId = Guid "{ce94d289-8481-498b-8ca9-9b6191a315b9}" + +[] +module internal CodeFix = + + [] + let AddInstanceMemberParameter = "AddInstanceMemberParameter" + + [] + let ConvertCSharpLambdaToFSharpLambda = "ConvertCSharpLambdaToFSharpLambda" + + [] + let ConvertToNotEqualsEqualityExpression = "ConvertToNotEqualsEqualityExpression" + + [] + let UseTripleQuotedInterpolation = "UseTripleQuotedInterpolation" + + [] + let SimplifyName = "SimplifyName" + + [] + let RemoveUnusedBinding = "RemoveUnusedBinding" + + [] + let ChangeToUpcast = "ChangeToUpcast" + + [] + let UseMutationWhenValueIsMutable = "UseMutationWhenValueIsMutable" + + [] + let RenameUnusedValue = "RenameUnusedValue" + + [] + let FixIndexerAccess = "FixIndexerAccess" + + [] + let RemoveReturnOrYield = "RemoveReturnOrYield" + + [] + let ReplaceWithSuggestion = "ReplaceWithSuggestion" + + [] + let MakeOuterBindingRecursive = "MakeOuterBindingRecursive" + + [] + let ConvertToSingleEqualsEqualityExpression = + "ConvertToSingleEqualsEqualityExpression" + + [] + let MakeDeclarationMutable = "MakeDeclarationMutable" + + [] + let ChangePrefixNegationToInfixSubtraction = + "ChangePrefixNegationToInfixSubtraction" + + [] + let AddMissingFunKeyword = "AddMissingFunKeyword" + + [] + let AddNewKeyword = "AddNewKeyword" + + [] + let RemoveUnusedOpens = "RemoveUnusedOpens" + + [] + let AddOpen = "AddOpen" + + [] + let ConvertCSharpUsingToFSharpOpen = "ConvertCSharpUsingToFSharpOpen" + + [] + let ChangeRefCellDerefToNotExpression = "ChangeRefCellDerefToNotExpression" + + [] + let AddMissingEqualsToTypeDefinition = "AddMissingEqualsToTypeDefinition" + + [] + let FSharpRenameParamToMatchSignature = "FSharpRenameParamToMatchSignature" + + [] + let RemoveIndexerDotBeforeBracket = "RemoveIndexerDotBeforeBracket" + + [] + let RemoveSuperfluousCapture = "RemoveSuperfluousCapture"