-
Notifications
You must be signed in to change notification settings - Fork 763
/
ProposeUppercaseLabel.fs
31 lines (26 loc) · 1.58 KB
/
ProposeUppercaseLabel.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace Microsoft.VisualStudio.FSharp.Editor
open System.Composition
open System.Threading.Tasks
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ProposeUpperCaseLabel"); Shared>]
type internal FSharpProposeUpperCaseLabelCodeFixProvider
[<ImportingConstructor>]
(
checkerProvider: FSharpCheckerProvider,
projectInfoManager: FSharpProjectOptionsManager
) =
inherit CodeFixProvider()
let fixableDiagnosticIds = ["FS0053"]
static let userOpName = "ProposeUpperCaseLabel"
override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override __.RegisterCodeFixesAsync context : Task =
asyncMaybe {
let textChanger (originalText: string) = originalText.[0].ToString().ToUpper() + originalText.Substring(1)
let! solutionChanger, originalText = SymbolHelpers.changeAllSymbolReferences(context.Document, context.Span, textChanger, projectInfoManager, checkerProvider.Checker, userOpName)
let title = FSComp.SR.replaceWithSuggestion (textChanger originalText)
context.RegisterCodeFix(
CodeAction.Create(title, solutionChanger, title),
context.Diagnostics |> Seq.filter (fun x -> fixableDiagnosticIds |> List.contains x.Id) |> Seq.toImmutableArray)
} |> Async.Ignore |> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)