Skip to content

Commit

Permalink
Add ConvertToSingleEqualsEqualityExpression code fix (dotnet#10462)
Browse files Browse the repository at this point in the history
* Add ConvertToSingleEqualsEqualityExpression code fix

* Fix type
  • Loading branch information
cartermp authored and nosami committed Feb 22, 2021
1 parent 72374ca commit f86ff30
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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
open System.Threading.Tasks

open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions

[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ConvertToSingleEqualsEqualityExpression"); Shared>]
type internal FSharpConvertToSingleEqualsEqualityExpressionCodeFixProvider() =
inherit CodeFixProvider()

let fixableDiagnosticIds = set ["FS0043"]

override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds

override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
let text = sourceText.GetSubText(context.Span).ToString()

// We're converting '==' into '=', a common new user mistake.
// If this is an FS00043 that is anything other than that, bail out
do! Option.guard (text = "==")

let title = SR.ConvertToSingleEqualsEqualityExpression()

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(context.Span, "=") |]))

context.RegisterCodeFix(codeFix, diagnostics)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<Import Project="$(ReferencesVSEditor)" />
<Import Project="$(ReferencesGtk)" />
<Import Project="VSMac\templates\templates.targets" />
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -->
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -180,6 +184,7 @@
<Compile Include="Commands\FsiCommandService.fs" />
<Compile Include="Commands\XmlDocCommandService.fs" />
<Compile Include="CodeFix\CodeFixHelpers.fs" />
<Compile Include="CodeFix\ConvertToSingleEqualsEqualityExpression.fs" />
<Compile Include="CodeFix\ChangeRefCellDerefToNotExpression.fs" />
<Compile Include="CodeFix\WrapExpressionInParentheses.fs" />
<Compile Include="CodeFix\ChangePrefixNegationToInfixSubtraction.fs" />
Expand Down
3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.resx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
<data name="FSharpDisposableTopLevelValuesClassificationType" xml:space="preserve">
<value>F# Dispostable Values (top-level)</value>
</data>
<data name="ConvertToSingleEqualsEqualityExpression" xml:space="preserve">
<value>Use '=' for equality check</value>
</data>
<data name="UseNotForNegation" xml:space="preserve">
<value>Use 'not' to negate expression</value>
</data>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Přidejte klíčové slovo new.</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Schlüsselwort "new" hinzufügen</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Agregar "nueva" palabra clave</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Ajouter le mot clé 'new'</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Aggiungi la parola chiave 'new'</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">'new' キーワードを追加する</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">'new' 키워드 추가</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Dodaj słowo kluczowe „new”</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Adicionar a palavra-chave 'new'</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Добавить ключевое слово "new"</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">'new' anahtar sözcüğünü ekleme</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">添加“新”关键字</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">新增 'new' 關鍵字</target>
<note />
</trans-unit>
<trans-unit id="ConvertToSingleEqualsEqualityExpression">
<source>Use '=' for equality check</source>
<target state="new">Use '=' for equality check</target>
<note />
</trans-unit>
<trans-unit id="ChangePrefixNegationToInfixSubtraction">
<source>Use subtraction instead of negation</source>
<target state="new">Use subtraction instead of negation</target>
Expand Down

0 comments on commit f86ff30

Please sign in to comment.