3
3
namespace Microsoft.VisualStudio.FSharp.Editor
4
4
5
5
open System.Composition
6
- open System.Threading
7
- open System.Threading .Tasks
8
6
open System.Collections .Immutable
9
7
open System.Text .RegularExpressions
10
8
@@ -13,11 +11,13 @@ open Microsoft.CodeAnalysis.Text
13
11
open Microsoft.CodeAnalysis .CodeFixes
14
12
open Microsoft.VisualStudio .FSharp .Editor .SymbolHelpers
15
13
14
+ open FSharp.Compiler .Diagnostics
16
15
open FSharp.Compiler .Tokenization .FSharpKeywords
17
16
17
+ open CancellableTasks
18
+
18
19
[<ExportCodeFixProvider( FSharpConstants.FSharpLanguageName, Name = CodeFix.FSharpRenameParamToMatchSignature); Shared>]
19
20
type internal RenameParamToMatchSignatureCodeFixProvider [<ImportingConstructor>] () =
20
-
21
21
inherit CodeFixProvider()
22
22
23
23
let getSuggestion ( d : Diagnostic ) =
@@ -28,53 +28,41 @@ type internal RenameParamToMatchSignatureCodeFixProvider [<ImportingConstructor>
28
28
else
29
29
ValueNone
30
30
31
- override _.FixableDiagnosticIds = ImmutableArray.Create( " FS3218" )
31
+ override _.FixableDiagnosticIds = ImmutableArray.Create " FS3218"
32
+
33
+ override this.RegisterCodeFixesAsync context = context.RegisterFsharpFix this
32
34
33
- member this.GetChanges ( document : Document , diagnostics : ImmutableArray < Diagnostic >, ct : CancellationToken ) =
34
- backgroundTask {
35
- let! sourceText = document.GetTextAsync( ct)
35
+ override this.GetFixAllProvider () = this.RegisterFsharpFixAll()
36
36
37
- let! changes =
38
- seq {
39
- for d in diagnostics do
40
- let suggestionOpt = getSuggestion d
37
+ interface IFSharpCodeFixProvider with
38
+ member _.GetCodeFixIfAppliesAsync context =
39
+ cancellableTask {
40
+ let! sourceText = context.GetSourceTextAsync ()
41
41
42
- match suggestionOpt with
43
- | ValueSome suggestion ->
44
- let replacement = NormalizeIdentifierBackticks suggestion
42
+ let suggestionOpt = getSuggestion context.Diagnostics[ 0 ]
45
43
46
- async {
47
- let! symbolUses = getSymbolUsesOfSymbolAtLocationInDocument ( document , d.Location.SourceSpan.Start )
48
- let symbolUses = symbolUses |> Option.defaultValue [||]
44
+ match suggestionOpt with
45
+ | ValueSome suggestion ->
46
+ let replacement = NormalizeIdentifierBackticks suggestion
49
47
50
- return
51
- [|
52
- for symbolUse in symbolUses do
53
- match RoslynHelpers.TryFSharpRangeToTextSpan( sourceText, symbolUse.Range) with
54
- | None -> ()
55
- | Some span ->
56
- let textSpan = Tokenizer.fixupSpan ( sourceText, span)
57
- yield TextChange( textSpan, replacement)
58
- |]
48
+ let! symbolUses = getSymbolUsesOfSymbolAtLocationInDocument ( context.Document, context.Span.Start)
49
+ let symbolUses = symbolUses |> Option.defaultValue [||]
59
50
51
+ let changes =
52
+ [
53
+ for symbolUse in symbolUses do
54
+ let span = RoslynHelpers.FSharpRangeToTextSpan( sourceText, symbolUse.Range)
55
+ let textSpan = Tokenizer.fixupSpan ( sourceText, span)
56
+ yield TextChange( textSpan, replacement)
57
+ ]
58
+
59
+ return
60
+ ValueSome
61
+ {
62
+ Name = CodeFix.FSharpRenameParamToMatchSignature
63
+ Message = CompilerDiagnostics.GetErrorMessage( FSharpDiagnosticKind.ReplaceWithSuggestion suggestion)
64
+ Changes = changes
60
65
}
61
- | ValueNone -> ()
62
- }
63
- |> Async.Parallel
64
-
65
- return ( changes |> Seq.concat)
66
- }
67
-
68
- override this.RegisterCodeFixesAsync ctx : Task =
69
- backgroundTask {
70
- let title = ctx.Diagnostics |> Seq.head |> getSuggestion
71
-
72
- match title with
73
- | ValueSome title ->
74
- let! changes = this.GetChanges( ctx.Document, ctx.Diagnostics, ctx.CancellationToken)
75
- ctx.RegisterFsharpFix( CodeFix.FSharpRenameParamToMatchSignature, title, changes)
76
- | ValueNone -> ()
77
- }
78
-
79
- override this.GetFixAllProvider () =
80
- CodeFixHelpers.createFixAllProvider CodeFix.FSharpRenameParamToMatchSignature this.GetChanges
66
+
67
+ | ValueNone -> return ValueNone
68
+ }
0 commit comments