forked from nosami/visualfsharp
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ChangeRefCellDerefToNotExpression code fixer (dotnet#10469)
* Add ChangeRefCellDerefToNotExpression code fixer * Area
- Loading branch information
Showing
16 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// 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.Text | ||
open Microsoft.CodeAnalysis.CodeFixes | ||
|
||
[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ChangeRefCellDerefToNotExpression"); Shared>] | ||
type internal FSharpChangeRefCellDerefToNotExpressionCodeFixProvider | ||
[<ImportingConstructor>] | ||
( | ||
checkerProvider: FSharpCheckerProvider, | ||
projectInfoManager: FSharpProjectOptionsManager | ||
) = | ||
inherit CodeFixProvider() | ||
|
||
static let userOpName = "FSharpChangeRefCellDerefToNotExpressionCodeFix" | ||
let fixableDiagnosticIds = set ["FS0001"] | ||
|
||
override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds | ||
|
||
override this.RegisterCodeFixesAsync context : Task = | ||
asyncMaybe { | ||
let document = context.Document | ||
let! parsingOptions, _ = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, context.CancellationToken, userOpName) | ||
let! sourceText = context.Document.GetTextAsync(context.CancellationToken) | ||
let! parseResults = checkerProvider.Checker.ParseFile(document.FilePath, sourceText.ToFSharpSourceText(), parsingOptions, userOpName) |> liftAsync | ||
|
||
let errorRange = RoslynHelpers.TextSpanToFSharpRange(document.FilePath, context.Span, sourceText) | ||
let! derefRange = parseResults.TryRangeOfRefCellDereferenceContainingPos errorRange.Start | ||
let! derefSpan = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, derefRange) | ||
|
||
let title = SR.UseNotForNegation() | ||
|
||
let diagnostics = | ||
context.Diagnostics | ||
|> Seq.filter (fun x -> fixableDiagnosticIds |> Set.contains x.Id) | ||
|> Seq.toImmutableArray | ||
|
||
let codeFix = | ||
CodeFixHelpers.createTextChangeCodeFix( | ||
title, | ||
context, | ||
(fun () -> asyncMaybe.Return [| TextChange(derefSpan, "not ") |])) | ||
|
||
context.RegisterCodeFix(codeFix, diagnostics) | ||
} | ||
|> Async.Ignore | ||
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters