未验证 提交 c2f78593 编写于 作者: T Tomas Grosup 提交者: GitHub

Codefixes cleanup - cleanup fixableDiagnosticIds, unify more CodeFix registration calls (#15110)

* codefix simplification
上级 74fda07f
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -12,10 +13,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpAddInstanceMemberParameterCodeFixProvider() =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0673" ]
static let title = SR.AddMissingInstanceMemberParameter()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0673")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -13,9 +14,8 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpAddMissingEqualsToTypeDefinitionCodeFixProvider() =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS3360" ]
static let title = SR.AddMissingEqualsToTypeDefinition()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS3360")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System
open System.Composition
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -16,9 +17,7 @@ type internal FSharpAddMissingFunKeywordCodeFixProvider [<ImportingConstructor>]
inherit CodeFixProvider()
static let title = SR.AddMissingFunKeyword()
let fixableDiagnosticIds = set [ "FS0010" ]
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0010")
override _.RegisterCodeFixesAsync context =
asyncMaybe {
......
......@@ -16,38 +16,13 @@ open FSharp.Compiler.CodeAnalysis
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CodeActions
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "AddMissingRecToMutuallyRecFunctions"); Shared>]
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.AddMissingRecToMutuallyRecFunctions); Shared>]
type internal FSharpAddMissingRecToMutuallyRecFunctionsCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0576" ]
static let titleFormat = SR.MakeOuterBindingRecursive()
let createCodeFix
(
context: CodeFixContext,
symbolName: string,
titleFormat: string,
textChange: TextChange,
diagnostics: ImmutableArray<Diagnostic>
) =
let title = String.Format(titleFormat, symbolName)
let codeAction =
CodeAction.Create(
title,
(fun (cancellationToken: CancellationToken) ->
async {
let cancellationToken = context.CancellationToken
let! sourceText = context.Document.GetTextAsync(cancellationToken) |> Async.AwaitTask
return context.Document.WithText(sourceText.WithChanges(textChange))
}
|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
title
)
context.RegisterCodeFix(codeAction, diagnostics)
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0576")
override _.RegisterCodeFixesAsync context =
asyncMaybe {
......@@ -82,18 +57,12 @@ type internal FSharpAddMissingRecToMutuallyRecFunctionsCodeFixProvider [<Importi
let! funcNameSpan = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, funcLexerSymbol.Range)
let funcName = sourceText.GetSubText(funcNameSpan).ToString()
let diagnostics =
context.Diagnostics
|> Seq.filter (fun x -> fixableDiagnosticIds |> Set.contains x.Id)
|> Seq.toImmutableArray
createCodeFix (
context,
funcName,
SR.MakeOuterBindingRecursive(),
TextChange(TextSpan(context.Span.End, 0), " rec"),
diagnostics
)
do
context.RegisterFsharpFix(
CodeFix.AddMissingRecToMutuallyRecFunctions,
String.Format(titleFormat, funcName),
[| TextChange(TextSpan(context.Span.End, 0), " rec") |]
)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
......@@ -6,6 +6,7 @@ open System
open System.Composition
open System.Threading
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Text
......@@ -21,35 +22,24 @@ open FSharp.Compiler.Text
type internal FSharpAddOpenCodeFixProvider [<ImportingConstructor>] (assemblyContentProvider: AssemblyContentProvider) =
inherit CodeFixProvider()
let fixableDiagnosticIds = [ "FS0039"; "FS0043" ]
let fixUnderscoresInMenuText (text: string) = text.Replace("_", "__")
let qualifySymbolFix (context: CodeFixContext) (fullName, qualifier) =
CodeFixHelpers.createTextChangeCodeFix (
CodeFix.AddOpen,
fixUnderscoresInMenuText fullName,
context,
[| TextChange(context.Span, qualifier) |]
)
let openNamespaceFix (context: CodeFixContext) ctx name ns multipleNames =
context.RegisterFsharpFix(CodeFix.AddOpen, fixUnderscoresInMenuText fullName, [| TextChange(context.Span, qualifier) |])
let openNamespaceFix (context: CodeFixContext) ctx name ns multipleNames sourceText =
let displayText = "open " + ns + (if multipleNames then " (" + name + ")" else "")
let newText, _ = OpenDeclarationHelper.insertOpenDeclaration sourceText ctx ns
let changes = newText.GetTextChanges(sourceText)
CodeAction.Create(
fixUnderscoresInMenuText displayText,
(fun (cancellationToken: CancellationToken) ->
async {
let! sourceText = context.Document.GetTextAsync(cancellationToken) |> Async.AwaitTask
let changedText, _ = OpenDeclarationHelper.insertOpenDeclaration sourceText ctx ns
return context.Document.WithText(changedText)
}
|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
displayText
)
context.RegisterFsharpFix(CodeFix.AddOpen, fixUnderscoresInMenuText displayText, changes)
let addSuggestionsAsCodeFixes (context: CodeFixContext) (candidates: (InsertionContextEntity * InsertionContext) list) =
let openNamespaceFixes =
let addSuggestionsAsCodeFixes
(context: CodeFixContext)
(sourceText: SourceText)
(candidates: (InsertionContextEntity * InsertionContext) list)
=
do
candidates
|> Seq.choose (fun (entity, ctx) -> entity.Namespace |> Option.map (fun ns -> ns, entity.FullDisplayName, ctx))
|> Seq.groupBy (fun (ns, _, _) -> ns)
......@@ -64,22 +54,17 @@ type internal FSharpAddOpenCodeFixProvider [<ImportingConstructor>] (assemblyCon
let multipleNames = names |> Array.length > 1
names |> Seq.map (fun (name, ctx) -> ns, name, ctx, multipleNames))
|> Seq.concat
|> Seq.map (fun (ns, name, ctx, multipleNames) -> openNamespaceFix context ctx name ns multipleNames)
|> Seq.toList
|> Seq.iter (fun (ns, name, ctx, multipleNames) -> openNamespaceFix context ctx name ns multipleNames sourceText)
let qualifiedSymbolFixes =
do
candidates
|> Seq.filter (fun (entity, _) -> not (entity.LastIdent.StartsWith "op_")) // Don't include qualified operator names. The resultant codefix won't compile because it won't be an infix operator anymore.
|> Seq.map (fun (entity, _) -> entity.FullRelativeName, entity.Qualifier)
|> Seq.distinct
|> Seq.sort
|> Seq.map (qualifySymbolFix context)
|> Seq.toList
for codeFix in openNamespaceFixes @ qualifiedSymbolFixes do
context.RegisterCodeFix(codeFix, context.Diagnostics)
|> Seq.iter (qualifySymbolFix context)
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0039", "FS0043")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......@@ -186,7 +171,7 @@ type internal FSharpAddOpenCodeFixProvider [<ImportingConstructor>] (assemblyCon
|> Seq.map createEntity
|> Seq.concat
|> Seq.toList
|> addSuggestionsAsCodeFixes context
|> addSuggestionsAsCodeFixes context sourceText
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
......@@ -6,6 +6,7 @@ open System
open System.Composition
open System.Threading
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -16,20 +17,16 @@ open FSharp.Compiler.Text
open FSharp.Compiler.Symbols
open Microsoft.CodeAnalysis.CodeActions
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "AddTypeAnnotationToObjectOfIndeterminateType"); Shared>]
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.AddTypeAnnotationToObjectOfIndeterminateType); Shared>]
type internal FSharpAddTypeAnnotationToObjectOfIndeterminateTypeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0072"; "FS3245" ]
static let title = SR.AddTypeAnnotation()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0072", "FS3245")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
let diagnostics =
context.Diagnostics
|> Seq.filter (fun x -> fixableDiagnosticIds |> Set.contains x.Id)
|> Seq.toImmutableArray
let document = context.Document
let position = context.Span.Start
......@@ -95,29 +92,17 @@ type internal FSharpAddTypeAnnotationToObjectOfIndeterminateTypeFixProvider [<Im
let hasRightParen = rightLoop sourceText.[declSpan.End] declSpan.End
hasLeftParen && hasRightParen
let getChangedText (sourceText: SourceText) =
if alreadyWrappedInParens then
sourceText.WithChanges(TextChange(TextSpan(declSpan.End, 0), ": " + typeString))
else
sourceText
.WithChanges(TextChange(TextSpan(declSpan.Start, 0), "("))
.WithChanges(TextChange(TextSpan(declSpan.End + 1, 0), ": " + typeString + ")"))
let title = SR.AddTypeAnnotation()
let codeAction =
CodeAction.Create(
title,
(fun (cancellationToken: CancellationToken) ->
async {
let! sourceText = context.Document.GetTextAsync(cancellationToken) |> Async.AwaitTask
return context.Document.WithText(getChangedText sourceText)
}
|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
title
)
context.RegisterCodeFix(codeAction, diagnostics)
let changes =
[
if alreadyWrappedInParens then
TextChange(TextSpan(declSpan.End, 0), ": " + typeString)
else
TextChange(TextSpan(declSpan.Start, 0), "(")
TextChange(TextSpan(declSpan.End + 1, 0), ": " + typeString + ")")
]
context.RegisterFsharpFix(CodeFix.AddTypeAnnotationToObjectOfIndeterminateType, title, changes)
| _ -> ()
| _ -> ()
}
......
......@@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -13,10 +14,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpChangePrefixNegationToInfixSubtractionodeFixProvider() =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0003" ]
static let title = SR.ChangePrefixNegationToInfixSubtraction()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0003")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -12,10 +13,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpChangeRefCellDerefToNotExpressionCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0001" ]
static let title = SR.UseNotForNegation()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0001")
override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -12,9 +13,7 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpChangeToUpcastCodeFixProvider() =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS3198" ]
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS3198")
override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -3,6 +3,7 @@
namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -11,9 +12,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpConvertCSharpLambdaToFSharpLambdaCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0039"; "FS0043" ]
static let title = SR.UseFSharpLambda()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0039", "FS0043")
override _.RegisterCodeFixesAsync context =
asyncMaybe {
......
......@@ -14,7 +14,6 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpConvertCSharpUsingToFSharpOpen [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0039"; "FS0201" ]
static let title = SR.ConvertCSharpUsingToFSharpOpen()
let usingLength = "using".Length
......@@ -47,7 +46,7 @@ type internal FSharpConvertCSharpUsingToFSharpOpen [<ImportingConstructor>] () =
do context.RegisterFsharpFix(CodeFix.ConvertCSharpUsingToFSharpOpen, title, [| replacement |])
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0039", "FS0201")
override _.RegisterCodeFixesAsync context =
asyncMaybe {
......
......@@ -5,18 +5,19 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ConvertToAnonymousRecord"); Shared>]
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.ConvertToAnonymousRecord); Shared>]
type internal FSharpConvertToAnonymousRecordCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0039" ]
static let title = SR.ConvertToAnonymousRecord()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0039")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......@@ -34,28 +35,13 @@ type internal FSharpConvertToAnonymousRecordCodeFixProvider [<ImportingConstruct
let! recordRange = parseResults.TryRangeOfRecordExpressionContainingPos errorRange.Start
let! recordSpan = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, recordRange)
let getChangedText () =
sourceText
.WithChanges(TextChange(TextSpan(recordSpan.Start + 1, 0), "|"))
.WithChanges(TextChange(TextSpan(recordSpan.End, 0), "|"))
let changes =
[
TextChange(TextSpan(recordSpan.Start + 1, 0), "|")
TextChange(TextSpan(recordSpan.End, 0), "|")
]
let diagnostics =
context.Diagnostics
|> Seq.filter (fun x -> fixableDiagnosticIds |> Set.contains x.Id)
|> Seq.toImmutableArray
let title = SR.ConvertToAnonymousRecord()
let codeFix =
CodeAction.Create(
title,
(fun (cancellationToken: CancellationToken) ->
async { return context.Document.WithText(getChangedText ()) }
|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
title
)
context.RegisterCodeFix(codeFix, diagnostics)
context.RegisterFsharpFix(CodeFix.ConvertToAnonymousRecord, title, changes)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -12,10 +13,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpConvertToNotEqualsEqualityExpressionCodeFixProvider() =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0043" ]
static let title = SR.ConvertToNotEqualsEqualityExpression()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0043")
override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -12,10 +13,9 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpConvertToSingleEqualsEqualityExpressionCodeFixProvider() =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0043" ]
static let title = SR.ConvertToSingleEqualsEqualityExpression()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0043")
override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -15,10 +15,10 @@ open FSharp.Compiler.Diagnostics
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.FixIndexerAccess); Shared>]
type internal LegacyFsharpFixAddDotToIndexerAccess() =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS3217" ]
static let title = CompilerDiagnostics.GetErrorMessage FSharpDiagnosticKind.AddIndexerDot
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS3217")
override _.RegisterCodeFixesAsync context : Task =
async {
......@@ -56,7 +56,6 @@ type internal LegacyFsharpFixAddDotToIndexerAccess() =
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.RemoveIndexerDotBeforeBracket); Shared>]
type internal FsharpFixRemoveDotFromIndexerAccessOptIn() as this =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS3366" ]
static let title =
CompilerDiagnostics.GetErrorMessage FSharpDiagnosticKind.RemoveIndexerDot
......@@ -69,7 +68,7 @@ type internal FsharpFixRemoveDotFromIndexerAccessOptIn() as this =
return changes
}
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS3366")
override _.RegisterCodeFixesAsync ctx : Task =
backgroundTask {
......
......@@ -6,6 +6,7 @@ open System
open System.Composition
open System.Threading
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Formatting
open Microsoft.CodeAnalysis.Text
......@@ -33,7 +34,6 @@ type internal InterfaceState =
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ImplementInterface"); Shared>]
type internal FSharpImplementInterfaceCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = [ "FS0366" ]
let queryInterfaceState appendBracketAt (pos: pos) (tokens: Tokenizer.SavedTokenInfo[]) (ast: ParsedInput) =
asyncMaybe {
......@@ -143,10 +143,6 @@ type internal FSharpImplementInterfaceCodeFixProvider [<ImportingConstructor>] (
|> Array.exists (fun e -> e.Severity = FSharpDiagnosticSeverity.Error)
// This comparison is a bit expensive
if hasTypeCheckError && List.length membersAndRanges <> Seq.length interfaceMembers then
let diagnostics =
context.Diagnostics
|> Seq.filter (fun x -> fixableDiagnosticIds |> List.contains x.Id)
|> Seq.toImmutableArray
let registerCodeFix title verboseMode =
let codeAction =
......@@ -182,14 +178,14 @@ type internal FSharpImplementInterfaceCodeFixProvider [<ImportingConstructor>] (
title
)
context.RegisterCodeFix(codeAction, diagnostics)
context.RegisterCodeFix(codeAction, context.Diagnostics)
registerCodeFix (SR.ImplementInterface()) true
registerCodeFix (SR.ImplementInterfaceWithoutTypeAnnotation()) false
else
()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0366")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -15,10 +16,9 @@ open FSharp.Compiler.Text
type internal FSharpMakeDeclarationMutableFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0027" ]
static let title = SR.MakeDeclarationMutable()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0027")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System
open System.Composition
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -12,9 +13,7 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpMakeOuterBindingRecursiveCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0039" ]
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0039")
override _.RegisterCodeFixesAsync context =
asyncMaybe {
......
......@@ -4,16 +4,18 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions
open FSharp.Compiler.Diagnostics
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ProposeUpperCaseLabel"); Shared>]
type internal FSharpProposeUpperCaseLabelCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = [ "FS0053" ]
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0053")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......@@ -25,12 +27,7 @@ type internal FSharpProposeUpperCaseLabelCodeFixProvider [<ImportingConstructor>
let title =
CompilerDiagnostics.GetErrorMessage(FSharpDiagnosticKind.ReplaceWithSuggestion <| textChanger originalText)
context.RegisterCodeFix(
CodeAction.Create(title, solutionChanger, title),
context.Diagnostics
|> Seq.filter (fun x -> fixableDiagnosticIds |> List.contains x.Id)
|> Seq.toImmutableArray
)
context.RegisterCodeFix(CodeAction.Create(title, solutionChanger, title), context.Diagnostics)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
......@@ -3,6 +3,7 @@
namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -11,9 +12,7 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpRemoveReturnOrYieldCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0748"; "FS0747" ]
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0748", "FS0747")
override _.RegisterCodeFixesAsync context =
asyncMaybe {
......
......@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -18,9 +19,7 @@ open FSharp.Compiler.Tokenization
type internal FSharpReplaceWithSuggestionCodeFixProvider [<ImportingConstructor>] (settings: EditorOptions) =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0039"; "FS1129"; "FS0495" ]
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0039", "FS1129", "FS0495")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System
open System.Composition
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -16,9 +17,8 @@ open FSharp.Compiler.Text
type internal FSharpUseMutationWhenValueIsMutableFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0020" ]
static let title = SR.UseMutationWhenValueIsMutable()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0020")
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
......
......@@ -3,6 +3,7 @@
namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
......@@ -11,9 +12,8 @@ open Microsoft.CodeAnalysis.CodeFixes
type internal FSharpUseTripleQuotedInterpolationCodeFixProvider [<ImportingConstructor>] () =
inherit CodeFixProvider()
let fixableDiagnosticIds = [ "FS3373" ]
static let title = SR.UseTripleQuotedInterpolation()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS3373")
override _.RegisterCodeFixesAsync context =
asyncMaybe {
......
......@@ -5,42 +5,27 @@ namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading
open System.Threading.Tasks
open System.Collections.Immutable
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "AddParentheses"); Shared>]
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = CodeFix.AddParentheses); Shared>]
type internal FSharpWrapExpressionInParenthesesFixProvider() =
inherit CodeFixProvider()
let fixableDiagnosticIds = set [ "FS0597" ]
static let title = SR.WrapExpressionInParentheses()
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = ImmutableArray.Create("FS0597")
override this.RegisterCodeFixesAsync context : Task =
async {
let title = SR.WrapExpressionInParentheses()
let getChangedText (sourceText: SourceText) =
sourceText
.WithChanges(TextChange(TextSpan(context.Span.Start, 0), "("))
.WithChanges(TextChange(TextSpan(context.Span.End + 1, 0), ")"))
context.RegisterCodeFix(
CodeAction.Create(
title,
(fun (cancellationToken: CancellationToken) ->
async {
let! sourceText = context.Document.GetTextAsync(cancellationToken) |> Async.AwaitTask
return context.Document.WithText(getChangedText sourceText)
}
|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
title
),
context.Diagnostics
|> Seq.filter (fun x -> this.FixableDiagnosticIds.Contains x.Id)
|> Seq.toImmutableArray
)
backgroundTask {
let changes =
[
TextChange(TextSpan(context.Span.Start, 0), "(")
TextChange(TextSpan(context.Span.End + 1, 0), ")")
]
context.RegisterFsharpFix(CodeFix.AddParentheses, title, changes)
}
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
......@@ -98,6 +98,19 @@ module internal Guids =
[<RequireQualifiedAccess>]
module internal CodeFix =
[<Literal>]
let AddParentheses = "AddParentheses"
[<Literal>]
let AddTypeAnnotationToObjectOfIndeterminateType =
"AddTypeAnnotationToObjectOfIndeterminateType"
[<Literal>]
let AddMissingRecToMutuallyRecFunctions = "AddMissingRecToMutuallyRecFunctions"
[<Literal>]
let ConvertToAnonymousRecord = "ConvertToAnonymousRecord"
[<Literal>]
let AddInstanceMemberParameter = "AddInstanceMemberParameter"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册