diff --git a/CodeFix/MakeOuterBindingRecursive.fs b/CodeFix/MakeOuterBindingRecursive.fs new file mode 100644 index 00000000000..581380d2c23 --- /dev/null +++ b/CodeFix/MakeOuterBindingRecursive.fs @@ -0,0 +1,56 @@ +// 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 Microsoft.CodeAnalysis.Text +open Microsoft.CodeAnalysis.CodeFixes + +[] +type internal FSharpMakeOuterBindingRecursiveCodeFixProvider + [] + ( + checkerProvider: FSharpCheckerProvider, + projectInfoManager: FSharpProjectOptionsManager + ) = + inherit CodeFixProvider() + + static let userOpName = "MakeOuterBindingRecursive" + let fixableDiagnosticIds = set ["FS0039"] + + override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds + + override _.RegisterCodeFixesAsync context = + asyncMaybe { + let! sourceText = context.Document.GetTextAsync(context.CancellationToken) + let! parsingOptions, _ = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(context.Document, context.CancellationToken, userOpName) + let! parseResults = checkerProvider.Checker.ParseFile(context.Document.FilePath, sourceText.ToFSharpSourceText(), parsingOptions, userOpName) |> liftAsync + + let diagnosticRange = RoslynHelpers.TextSpanToFSharpRange(context.Document.FilePath, context.Span, sourceText) + do! Option.guard (parseResults.IsPosContainedInApplication diagnosticRange.Start) + + let! outerBindingRange = parseResults.TryRangeOfNameOfNearestOuterBindingContainingPos diagnosticRange.Start + let! outerBindingNameSpan = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, outerBindingRange) + + // One last check to verify the names are the same + do! Option.guard (sourceText.GetSubText(outerBindingNameSpan).ContentEquals(sourceText.GetSubText(context.Span))) + + let diagnostics = + context.Diagnostics + |> Seq.filter (fun x -> fixableDiagnosticIds |> Set.contains x.Id) + |> Seq.toImmutableArray + + let title = String.Format(SR.MakeOuterBindingRecursive(), sourceText.GetSubText(outerBindingNameSpan).ToString()) + + let codeFix = + CodeFixHelpers.createTextChangeCodeFix( + title, + context, + (fun () -> asyncMaybe.Return [| TextChange(TextSpan(outerBindingNameSpan.Start, 0), "rec ") |])) + + context.RegisterCodeFix(codeFix, diagnostics) + } + |> Async.Ignore + |> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken) diff --git a/FSharp.Editor.fsproj b/FSharp.Editor.fsproj index a102f56eaa9..466b15a8256 100644 --- a/FSharp.Editor.fsproj +++ b/FSharp.Editor.fsproj @@ -90,6 +90,7 @@ + diff --git a/FSharp.Editor.resx b/FSharp.Editor.resx index 596442035df..87076943ea0 100644 --- a/FSharp.Editor.resx +++ b/FSharp.Editor.resx @@ -264,4 +264,7 @@ Use F# lambda syntax + + Make '{0}' recursive + \ No newline at end of file diff --git a/xlf/FSharp.Editor.cs.xlf b/xlf/FSharp.Editor.cs.xlf index 5ab8eca94be..5c069ffbd7e 100644 --- a/xlf/FSharp.Editor.cs.xlf +++ b/xlf/FSharp.Editor.cs.xlf @@ -62,6 +62,11 @@ Nastavte deklaraci jako mutable. + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore Před {0} vložte podtržítko. diff --git a/xlf/FSharp.Editor.de.xlf b/xlf/FSharp.Editor.de.xlf index d7248fcd49f..e538846342d 100644 --- a/xlf/FSharp.Editor.de.xlf +++ b/xlf/FSharp.Editor.de.xlf @@ -62,6 +62,11 @@ Deklaration "änderbar" machen + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore "{0}" einen Unterstrich voranstellen diff --git a/xlf/FSharp.Editor.es.xlf b/xlf/FSharp.Editor.es.xlf index 947b067884a..c0b21f5978a 100644 --- a/xlf/FSharp.Editor.es.xlf +++ b/xlf/FSharp.Editor.es.xlf @@ -62,6 +62,11 @@ Convertir la declaración en "mutable" + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore Colocar un carácter de subrayado delante de "{0}" diff --git a/xlf/FSharp.Editor.fr.xlf b/xlf/FSharp.Editor.fr.xlf index 2a0e7f9307e..c3279ecdcc3 100644 --- a/xlf/FSharp.Editor.fr.xlf +++ b/xlf/FSharp.Editor.fr.xlf @@ -62,6 +62,11 @@ Rendre la déclaration 'mutable' + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore Faire précéder '{0}' d'un trait de soulignement diff --git a/xlf/FSharp.Editor.it.xlf b/xlf/FSharp.Editor.it.xlf index f0f9ca41537..4eb00f6e453 100644 --- a/xlf/FSharp.Editor.it.xlf +++ b/xlf/FSharp.Editor.it.xlf @@ -62,6 +62,11 @@ Impostare la dichiarazione come 'mutable' + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore Anteponi a '{0}' un carattere di sottolineatura diff --git a/xlf/FSharp.Editor.ja.xlf b/xlf/FSharp.Editor.ja.xlf index 4bc3db3ca72..997fdbb34c2 100644 --- a/xlf/FSharp.Editor.ja.xlf +++ b/xlf/FSharp.Editor.ja.xlf @@ -62,6 +62,11 @@ 'mutable' を宣言する + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore アンダースコアが含まれているプレフィックス '{0}' diff --git a/xlf/FSharp.Editor.ko.xlf b/xlf/FSharp.Editor.ko.xlf index af33c0404c2..296fdd04ce7 100644 --- a/xlf/FSharp.Editor.ko.xlf +++ b/xlf/FSharp.Editor.ko.xlf @@ -62,6 +62,11 @@ 선언을 '변경 가능'으로 지정 + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore 밑줄이 있는 '{0}' 접두사 diff --git a/xlf/FSharp.Editor.pl.xlf b/xlf/FSharp.Editor.pl.xlf index 4046f1adabb..0422c21b5bc 100644 --- a/xlf/FSharp.Editor.pl.xlf +++ b/xlf/FSharp.Editor.pl.xlf @@ -62,6 +62,11 @@ Nadaj deklaracji właściwość „mutable” + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore Prefiks „{0}” ze znakiem podkreślenia diff --git a/xlf/FSharp.Editor.pt-BR.xlf b/xlf/FSharp.Editor.pt-BR.xlf index 52f4aec741d..6085b32124d 100644 --- a/xlf/FSharp.Editor.pt-BR.xlf +++ b/xlf/FSharp.Editor.pt-BR.xlf @@ -62,6 +62,11 @@ Fazer com que a declaração seja 'mutable' + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore Prefixo '{0}' sem sublinhado diff --git a/xlf/FSharp.Editor.ru.xlf b/xlf/FSharp.Editor.ru.xlf index 21b44abfe58..f6dd2c6f6ad 100644 --- a/xlf/FSharp.Editor.ru.xlf +++ b/xlf/FSharp.Editor.ru.xlf @@ -62,6 +62,11 @@ Сделайте объявление "изменяемым" + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore Добавить символ подчеркивания как префикс "{0}" diff --git a/xlf/FSharp.Editor.tr.xlf b/xlf/FSharp.Editor.tr.xlf index a16a7d29a7e..e78dffc69a7 100644 --- a/xlf/FSharp.Editor.tr.xlf +++ b/xlf/FSharp.Editor.tr.xlf @@ -62,6 +62,11 @@ Bildirimi 'mutable' yapın + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore '{0}' öğesinin önüne alt çizgi ekleme diff --git a/xlf/FSharp.Editor.zh-Hans.xlf b/xlf/FSharp.Editor.zh-Hans.xlf index c6317c2d83d..ce0669b423a 100644 --- a/xlf/FSharp.Editor.zh-Hans.xlf +++ b/xlf/FSharp.Editor.zh-Hans.xlf @@ -62,6 +62,11 @@ 将声明设为“可变” + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore 带下划线的前缀“{0}” diff --git a/xlf/FSharp.Editor.zh-Hant.xlf b/xlf/FSharp.Editor.zh-Hant.xlf index 2956b6b65a5..063176df13e 100644 --- a/xlf/FSharp.Editor.zh-Hant.xlf +++ b/xlf/FSharp.Editor.zh-Hant.xlf @@ -62,6 +62,11 @@ 將宣告設定為「可變動」 + + Make '{0}' recursive + Make '{0}' recursive + + Prefix '{0}' with underscore 有底線的前置詞 '{0}'