diff --git a/vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs b/vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.fs new file mode 100644 index 00000000000..cc28cdc0a52 --- /dev/null +++ b/vsintegration/src/FSharp.Editor/CodeFix/ChangeToUpcast.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.Composition +open System.Threading.Tasks + +open Microsoft.CodeAnalysis.Text +open Microsoft.CodeAnalysis.CodeFixes + +[] +type internal FSharpChangeToUpcastCodeFixProvider() = + inherit CodeFixProvider() + + let fixableDiagnosticIds = set ["FS3198"] + + 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() + + // Only works if it's one or the other + let isDowncastOperator = text.Contains(":?>") + let isDowncastKeyword = text.Contains("downcast") + do! Option.guard ((isDowncastOperator || isDowncastKeyword) && not (isDowncastOperator && isDowncastKeyword)) + + let replacement = + if isDowncastOperator then + text.Replace(":?>", ":>") + else + text.Replace("downcast", "upcast") + + let title = + if isDowncastOperator then + SR.UseUpcastOperator() + else + SR.UseUpcastKeyword() + + 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, replacement) |])) + + context.RegisterCodeFix(codeFix, diagnostics) + } + |> Async.Ignore + |> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken) diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj index 761e97ccd5c..8c4f8778573 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 62497078788..fbfd462a09e 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx @@ -219,6 +219,12 @@ F# Dispostable Values (top-level) + + Use 'upcast' + + + Use ':>' operator + Add missing '=' to type definition diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf index 14b804cc247..cfc92dc856e 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf @@ -187,6 +187,16 @@ Formátování + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf index 4aa11aa5540..18b949208c7 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf @@ -187,6 +187,16 @@ Formatierung + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf index d2adca7d01a..78f2b99a234 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf @@ -187,6 +187,16 @@ Formato + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf index ae54a946ed6..9c18b60164b 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf @@ -187,6 +187,16 @@ Mise en forme + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf index 9df3852f0cd..560bb871c5c 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf @@ -187,6 +187,16 @@ Formattazione + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf index d141030be81..0a6e6dc43c5 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf @@ -187,6 +187,16 @@ 書式設定 + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf index b2e8082b7fc..1951db13fab 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf @@ -187,6 +187,16 @@ 서식 + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf index 4acc383f4bb..7b903f93fa3 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf @@ -187,6 +187,16 @@ Formatowanie + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression 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 8256c04823f..30a5191c9d9 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf @@ -187,6 +187,16 @@ Formatação + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf index 4df93cd671a..29fb73ca1bd 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf @@ -187,6 +187,16 @@ Форматирование + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf index c42645b2e76..10b88fe3681 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf @@ -187,6 +187,16 @@ Biçimlendirme + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression 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 ec5e69bca10..c17436ace25 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf @@ -187,6 +187,16 @@ 正在格式化 + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression 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 acccd1d14d4..29a418e0050 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf @@ -187,6 +187,16 @@ 格式化 + + Use 'upcast' + Use 'upcast' + + + + Use ':>' operator + Use ':>' operator + + Use 'not' to negate expression Use 'not' to negate expression