Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit cd039df

Browse files
committed
merge
2 parents 1a4d251 + d99a212 commit cd039df

File tree

55 files changed

+651
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+651
-217
lines changed

Classification/ClassificationDefinitions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

33
namespace Microsoft.VisualStudio.FSharp.Editor
44

Classification/ColorizationService.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

33
namespace Microsoft.VisualStudio.FSharp.Editor
44

CodeFix/AddNewKeywordToDisposableConstructorInvocation.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace rec Microsoft.VisualStudio.FSharp.Editor
3+
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System.Composition
66
open System.Collections.Immutable

CodeFix/AddOpenCodeFixProvider.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace rec Microsoft.VisualStudio.FSharp.Editor
3+
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System
66
open System.Composition

CodeFix/FixIndexerAccess.fs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace rec Microsoft.VisualStudio.FSharp.Editor
3+
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System
66
open System.Composition
77
open System.Collections.Immutable
8-
open System.Threading
98
open System.Threading.Tasks
109

1110
open Microsoft.CodeAnalysis
1211
open Microsoft.CodeAnalysis.Text
1312
open Microsoft.CodeAnalysis.CodeFixes
14-
open Microsoft.CodeAnalysis.CodeActions
13+
open SymbolHelpers
1514

1615
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "FixIndexerAccess"); Shared>]
1716
type internal FSharpFixIndexerAccessCodeFixProvider() =
1817
inherit CodeFixProvider()
1918
let fixableDiagnosticIds = set ["FS3217"]
2019

21-
let createCodeFix (title: string, context: CodeFixContext, textChange: TextChange) =
22-
CodeAction.Create(
23-
title,
24-
(fun (cancellationToken: CancellationToken) ->
25-
async {
26-
let! cancellationToken = Async.CancellationToken
27-
let! sourceText = context.Document.GetTextAsync(cancellationToken) |> Async.AwaitTask
28-
return context.Document.WithText(sourceText.WithChanges(textChange))
29-
} |> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
30-
title)
31-
3220
override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
3321

3422
override __.RegisterCodeFixesAsync context : Task =
@@ -60,9 +48,10 @@ type internal FSharpFixIndexerAccessCodeFixProvider() =
6048
| _ -> context.Span,sourceText.GetSubText(context.Span).ToString()
6149

6250
let codefix =
63-
createCodeFix(
51+
createTextChangeCodeFix(
6452
FSComp.SR.addIndexerDot(),
6553
context,
66-
TextChange(span, replacement.TrimEnd() + "."))
54+
(fun () -> asyncMaybe.Return [| TextChange(span, replacement.TrimEnd() + ".") |]))
55+
6756
context.RegisterCodeFix(codefix, diagnostics))
6857
} |> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)

CodeFix/ImplementInterfaceCodeFixProvider.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace rec Microsoft.VisualStudio.FSharp.Editor
3+
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System
66
open System.Composition

CodeFix/MissingReferenceCodeFixProvider.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace rec Microsoft.VisualStudio.FSharp.Editor
3+
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System
66
open System.Composition

CodeFix/ProposeUppercaseLabel.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace rec Microsoft.VisualStudio.FSharp.Editor
3+
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System.Composition
66
open System.Threading.Tasks

CodeFix/RemoveUnusedOpens.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

3-
namespace rec Microsoft.VisualStudio.FSharp.Editor
3+
namespace Microsoft.VisualStudio.FSharp.Editor
44

55
open System.Composition
66
open System.Threading
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace Microsoft.VisualStudio.FSharp.Editor
4+
5+
open System
6+
open System.Collections.Immutable
7+
open System.Composition
8+
open System.Threading.Tasks
9+
10+
open Microsoft.CodeAnalysis
11+
open Microsoft.CodeAnalysis.Text
12+
open Microsoft.CodeAnalysis.CodeFixes
13+
14+
open Microsoft.FSharp.Compiler
15+
open Microsoft.FSharp.Compiler.SourceCodeServices
16+
open Microsoft.VisualStudio.FSharp.Editor.SymbolHelpers
17+
open Microsoft.FSharp.Compiler.SourceCodeServices.Keywords
18+
19+
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "FSharpRenameParamToMatchSignature"); Shared>]
20+
type internal FSharpRenameParamToMatchSignature
21+
[<ImportingConstructor>]
22+
(
23+
checkerProvider: FSharpCheckerProvider,
24+
projectInfoManager: FSharpProjectOptionsManager
25+
) =
26+
27+
inherit CodeFixProvider()
28+
static let userOpName = "RenameParamToMatchSignature"
29+
let fixableDiagnosticIds = ["FS3218"]
30+
31+
32+
override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
33+
34+
override __.RegisterCodeFixesAsync context : Task =
35+
asyncMaybe {
36+
match context.Diagnostics |> Seq.filter (fun x -> fixableDiagnosticIds |> List.contains x.Id) |> Seq.toList with
37+
| [diagnostic] ->
38+
let message = diagnostic.GetMessage()
39+
let parts = System.Text.RegularExpressions.Regex.Match(message, ".+'(.+)'.+'(.+)'.+")
40+
if parts.Success then
41+
42+
let diagnostics = ImmutableArray.Create diagnostic
43+
let suggestion = parts.Groups.[1].Value
44+
let replacement = QuoteIdentifierIfNeeded suggestion
45+
let computeChanges() =
46+
asyncMaybe {
47+
let document = context.Document
48+
let! cancellationToken = Async.CancellationToken |> liftAsync
49+
let! sourceText = document.GetTextAsync(cancellationToken)
50+
let! symbolUses = getSymbolUsesOfSymbolAtLocationInDocument (document, context.Span.Start, projectInfoManager, checkerProvider.Checker, userOpName)
51+
let changes =
52+
[| for symbolUse in symbolUses do
53+
match RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, symbolUse.RangeAlternate) with
54+
| None -> ()
55+
| Some span ->
56+
let textSpan = Tokenizer.fixupSpan(sourceText, span)
57+
yield TextChange(textSpan, replacement) |]
58+
return changes
59+
}
60+
let title = FSComp.SR.replaceWithSuggestion suggestion
61+
let codefix = createTextChangeCodeFix(title, context, computeChanges)
62+
context.RegisterCodeFix(codefix, diagnostics)
63+
| _ -> ()
64+
} |> Async.Ignore |> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)

0 commit comments

Comments
 (0)