diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs b/vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs new file mode 100644 index 00000000000..79d41ccbf16 --- /dev/null +++ b/vsintegration/src/FSharp.Editor/CodeFix/ChangePrefixNegationToInfixSubtraction.fs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace Microsoft.VisualStudio.FSharp.Editor + +open System +open System.Composition +open System.Threading.Tasks + +open Microsoft.CodeAnalysis.Text +open Microsoft.CodeAnalysis.CodeFixes + +[] +type internal FSharpChangePrefixNegationToInfixSubtractionodeFixProvider() = + inherit CodeFixProvider() + + let fixableDiagnosticIds = set ["FS0003"] + + override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds + + override _.RegisterCodeFixesAsync context : Task = + asyncMaybe { + let diagnostics = + context.Diagnostics + |> Seq.filter (fun x -> fixableDiagnosticIds |> Set.contains x.Id) + |> Seq.toImmutableArray + + let! sourceText = context.Document.GetTextAsync(context.CancellationToken) + + let mutable pos = context.Span.End + 1 + + // This won't ever actually happen, but eh why not + do! Option.guard (pos < sourceText.Length) + + let mutable ch = sourceText.GetSubText(TextSpan(pos, 1)).ToString().[0] + + while pos < sourceText.Length && Char.IsWhiteSpace(ch) do + pos <- pos + 1 + let text = sourceText.GetSubText(TextSpan(pos, 1)) + ch <- text.ToString().[0] + + // Bail if this isn't a negation + do! Option.guard (ch = '-') + + let title = SR.ChangePrefixNegationToInfixSubtraction() + + let codeFix = + CodeFixHelpers.createTextChangeCodeFix( + title, + context, + (fun () -> asyncMaybe.Return [| TextChange(TextSpan(pos, 1), "- ") |])) + + context.RegisterCodeFix(codeFix, diagnostics) + } + |> Async.Ignore + |> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken) \ No newline at end of file diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj index 8bc59c35a19..78cc9a5d518 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj @@ -89,6 +89,7 @@ + diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx index 8440136cf33..13709945ce2 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx @@ -219,4 +219,7 @@ F# Dispostable Values (top-level) + + Use subtraction instead of negation + \ No newline at end of file diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf index acac2c13bf4..466de025831 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf @@ -7,6 +7,11 @@ Přidejte klíčové slovo new. + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf index 639a34858b9..51ecf031079 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf @@ -7,6 +7,11 @@ Schlüsselwort "new" hinzufügen + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf index 5f1297eab36..353d0e1bf05 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf @@ -7,6 +7,11 @@ Agregar "nueva" palabra clave + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf index 3ae9d25817a..354a1c6dcce 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf @@ -7,6 +7,11 @@ Ajouter le mot clé 'new' + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf index 8457ca172b1..b9be9cd7563 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf @@ -7,6 +7,11 @@ Aggiungi la parola chiave 'new' + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf index 614fdea4a51..fff01521357 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf @@ -7,6 +7,11 @@ 'new' キーワードを追加する + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf index 832aaa80b5c..a64643814cd 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf @@ -7,6 +7,11 @@ 'new' 키워드 추가 + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf index 785230a56bb..4400e8d1ec6 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf @@ -7,6 +7,11 @@ Dodaj słowo kluczowe „new” + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf index 98636e84fd4..a3f63596b7a 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf @@ -7,6 +7,11 @@ Adicionar a palavra-chave 'new' + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf index 04891b9acea..0e0243fa64f 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf @@ -7,6 +7,11 @@ Добавить ключевое слово "new" + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf index 0cbe170c6d7..33d68ff209d 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf @@ -7,6 +7,11 @@ 'new' anahtar sözcüğünü ekleme + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf index dd827dbfd65..190686cbb1b 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf @@ -7,6 +7,11 @@ 添加“新”关键字 + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals) diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf index a59aa79970f..6ba4510aa5d 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf @@ -7,6 +7,11 @@ 新增 'new' 關鍵字 + + Use subtraction instead of negation + Use subtraction instead of negation + + F# Disposable Values (locals) F# Disposable Values (locals)