diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs similarity index 87% rename from src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs rename to src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs index acbb08789047f7f769d38cdb190f2dd7268d663d..513b6fa2b6ba99824986910f30c810f48ddeb86c 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs @@ -9,10 +9,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.ConditionalExpressionInStringInterpolation { - public class CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest + public class CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest { internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) - => (null, new CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProvider()); + => (null, new CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider()); private async Task TestInMethodAsync(string initialMethodBody, string expectedMethodBody) { @@ -29,7 +29,7 @@ public static M() string.Format(template, expectedMethodBody)).ConfigureAwait(false); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisSimpleConditionalExpression() { await TestInMethodAsync( @@ -37,7 +37,7 @@ public async Task TestAddParenthesisSimpleConditionalExpression() @"var s = $""{ (true ? 1 : 2)}"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisMultiLineConditionalExpression1() { await TestInMethodAsync(@" @@ -51,7 +51,7 @@ public async Task TestAddParenthesisMultiLineConditionalExpression1() "); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisMultiLineConditionalExpression2() { await TestInMethodAsync(@" @@ -73,7 +73,7 @@ public async Task TestAddParenthesisMultiLineConditionalExpression2() "); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWithTrivia() { await TestInMethodAsync( @@ -81,7 +81,7 @@ public async Task TestAddParenthesisWithTrivia() @"var s = $""{ /* Leading1 */ (true /* Leading2 */ ? /* TruePart1 */ 1 /* TruePart2 */: /* FalsePart1 */ 2 /* FalsePart2 */ )}"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisClosingBracketInFalseCondition() { await TestInMethodAsync( @@ -89,7 +89,7 @@ public async Task TestAddParenthesisClosingBracketInFalseCondition() @"var s = $""{ (true ? new int[0] : new int[] {})}"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisStringLiteralInFalseCondition() { await TestInMethodAsync( @@ -97,7 +97,7 @@ public async Task TestAddParenthesisStringLiteralInFalseCondition() @"var s = $""{ (true ? ""1"" : ""2"")}"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisVerbatimStringLiteralInFalseCondition() { await TestInMethodAsync( @@ -105,7 +105,7 @@ public async Task TestAddParenthesisVerbatimStringLiteralInFalseCondition() @"var s = $""{ (true ? ""1"" : @""""""2"""""")}"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisStringLiteralInFalseConditionWithClosingParenthesisInLiteral() { await TestInMethodAsync( @@ -113,7 +113,7 @@ public async Task TestAddParenthesisStringLiteralInFalseConditionWithClosingPare @"var s = $""{ (true ? ""1"" : ""2)"")}"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisStringLiteralInFalseConditionWithEscapedDoubleQuotes() { await TestInMethodAsync( @@ -121,7 +121,7 @@ public async Task TestAddParenthesisStringLiteralInFalseConditionWithEscapedDoub @"var s = $""{ (true ? ""1"" : ""2\"""")}"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisStringLiteralInFalseConditionWithCodeLikeContent() { await TestInMethodAsync( @@ -129,7 +129,7 @@ public async Task TestAddParenthesisStringLiteralInFalseConditionWithCodeLikeCon @"var s = $""{ (true ? ""1"" : ""M(new int[] {}, \""Parameter\"");"")}"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisNestedConditionalExpression1() { await TestInMethodAsync( @@ -137,7 +137,7 @@ public async Task TestAddParenthesisNestedConditionalExpression1() @"var s2 = $""{ (true ? ""1"" : (false ? ""2"" : ""3""))};"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisNestedConditionalExpression2() { await TestInMethodAsync( @@ -145,7 +145,7 @@ public async Task TestAddParenthesisNestedConditionalExpression2() @"var s2 = $""{ (true ? ""1"" : false ? ""2"" : ""3"")};"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisNestedConditionalWithNestedInterpolatedString() { await TestInMethodAsync( @@ -153,7 +153,7 @@ public async Task TestAddParenthesisNestedConditionalWithNestedInterpolatedStrin @"var s2 = $""{ (true ? ""1"" : false ? $""{ (true ? ""2"" : ""3"")}"" : ""4"") }"""); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisMultipleInterpolatedSections1() { await TestInMethodAsync( @@ -161,7 +161,7 @@ public async Task TestAddParenthesisMultipleInterpolatedSections1() @"var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"")} Text4 { (true ? ""Text5"" : ""Text6"")} Text7"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisMultipleInterpolatedSections2() { await TestInMethodAsync( @@ -169,7 +169,7 @@ public async Task TestAddParenthesisMultipleInterpolatedSections2() @"var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"")} Text4 { (true ? ""Text5"" : ""Text6"")} Text7"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisMultipleInterpolatedSections3() { await TestInMethodAsync( @@ -177,7 +177,7 @@ public async Task TestAddParenthesisMultipleInterpolatedSections3() @"var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"")} Text4 { true ? ""Text5"" : ""Text6""} Text7"";"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWhileTyping1() { await TestInMethodAsync( @@ -191,7 +191,7 @@ public async Task TestAddParenthesisWhileTyping1() NextLineOfCode();"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWhileTyping2() { await TestInMethodAsync( @@ -205,7 +205,7 @@ public async Task TestAddParenthesisWhileTyping2() NextLineOfCode();"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWhileTyping3() { await TestInMethodAsync( @@ -219,7 +219,7 @@ public async Task TestAddParenthesisWhileTyping3() NextLineOfCode();"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWhileTyping4() { await TestInMethodAsync( @@ -233,7 +233,7 @@ public async Task TestAddParenthesisWhileTyping4() NextLineOfCode();"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWhileTyping5() { await TestInMethodAsync( @@ -247,7 +247,7 @@ public async Task TestAddParenthesisWhileTyping5() NextLineOfCode();"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWithCS1026PresentBeforeFixIsApplied1() { await TestInMethodAsync( @@ -261,7 +261,7 @@ public async Task TestAddParenthesisWithCS1026PresentBeforeFixIsApplied1() NextLineOfCode();"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWithCS1026PresentBeforeFixIsApplied2() { await TestInMethodAsync( @@ -275,7 +275,7 @@ public async Task TestAddParenthesisWithCS1026PresentBeforeFixIsApplied2() NextLineOfCode("); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisWithCS1026PresentBeforeFixIsApplied3() { await TestInMethodAsync( @@ -289,7 +289,7 @@ public async Task TestAddParenthesisWithCS1026PresentBeforeFixIsApplied3() NextLineOfCode();"); } - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] public async Task TestAddParenthesisAddOpeningParenthesisOnly() { await TestInMethodAsync( diff --git a/src/EditorFeatures/TestUtilities/Traits.cs b/src/EditorFeatures/TestUtilities/Traits.cs index 60765f83f37688e2112d047765c658cae06ca774..8c6cab85256dd02dc7bed3be2a60034fd0da0f27 100644 --- a/src/EditorFeatures/TestUtilities/Traits.cs +++ b/src/EditorFeatures/TestUtilities/Traits.cs @@ -40,7 +40,7 @@ public static class Features public const string CodeActionsAddNew = "CodeActions.AddNew"; public const string CodeActionsAddOverload = "CodeActions.AddOverloads"; public const string CodeActionsAddParameter = "CodeActions.AddParameter"; - public const string CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString = "CodeActions.CodeActionsAddParenthesisAroundConditionalExpressionInInterpolatedString"; + public const string CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString = "CodeActions.AddParenthesesAroundConditionalExpressionInInterpolatedString"; public const string CodeActionsChangeToAsync = "CodeActions.ChangeToAsync"; public const string CodeActionsChangeToIEnumerable = "CodeActions.ChangeToIEnumerable"; public const string CodeActionsChangeToYield = "CodeActions.ChangeToYield"; diff --git a/src/Features/CSharp/Portable/CSharpFeaturesResources.Designer.cs b/src/Features/CSharp/Portable/CSharpFeaturesResources.Designer.cs index d80e6a9808adf7f16a1e96e5b49e5e44c82e85a0..1d7a4f1c93c7d12c33ac79400d4bfdf73cc45e31 100644 --- a/src/Features/CSharp/Portable/CSharpFeaturesResources.Designer.cs +++ b/src/Features/CSharp/Portable/CSharpFeaturesResources.Designer.cs @@ -71,20 +71,20 @@ internal class CSharpFeaturesResources { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Add 'this.' ähnelt. + /// Sucht eine lokalisierte Zeichenfolge, die Add parentheses ähnelt. /// - internal static string Add_this { + internal static string Add_parentheses_around_conditional_expression_in_interpolated_string { get { - return ResourceManager.GetString("Add_this", resourceCulture); + return ResourceManager.GetString("Add_parentheses_around_conditional_expression_in_interpolated_string", resourceCulture); } } /// - /// Sucht eine lokalisierte Zeichenfolge, die Add parenthesis ähnelt. + /// Sucht eine lokalisierte Zeichenfolge, die Add 'this.' ähnelt. /// - internal static string AddParenthesisAroundConditionalExpressionInInterpolatedString { + internal static string Add_this { get { - return ResourceManager.GetString("AddParenthesisAroundConditionalExpressionInInterpolatedString", resourceCulture); + return ResourceManager.GetString("Add_this", resourceCulture); } } diff --git a/src/Features/CSharp/Portable/CSharpFeaturesResources.resx b/src/Features/CSharp/Portable/CSharpFeaturesResources.resx index 0782bb389811f8467eab398968982a2724c524f1..86a50c4d9822ce47bcf85976807b470db4e61e7e 100644 --- a/src/Features/CSharp/Portable/CSharpFeaturesResources.resx +++ b/src/Features/CSharp/Portable/CSharpFeaturesResources.resx @@ -524,7 +524,7 @@ Use 'is null' check - - Add parenthesis + + Add parentheses \ No newline at end of file diff --git a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/AddParenthesisCodeAction.cs b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs similarity index 54% rename from src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/AddParenthesisCodeAction.cs rename to src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs index 41c729d257c84003ac61d084f802a99f87c01ac9..45df68cec097791af0217ffe0108ae420a323252 100644 --- a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/AddParenthesisCodeAction.cs +++ b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs @@ -1,14 +1,40 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Collections.Immutable; +using System.Composition; +using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeActions; +using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.ConditionalExpressionInStringInterpolation { - internal partial class CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProvider + [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddParenthesesAroundConditionalExpressionInInterpolatedString), Shared] + internal partial class CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider : CodeFixProvider { + private const string CS8361 = nameof(CS8361); //A conditional expression cannot be used directly in a string interpolation because the ':' ends the interpolation.Parenthesize the conditional expression. + + public override ImmutableArray FixableDiagnosticIds => ImmutableArray.Create(CS8361); + + public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) + { + var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); + var diagnostic = context.Diagnostics.First(); + var diagnosticSpan = diagnostic.Location.SourceSpan; + var token = root.FindToken(diagnosticSpan.Start); + var conditionalExpression = token.GetAncestor(); + if (conditionalExpression != null) + { + var documentChangeAction = new MyCodeAction( + cancellationToken => GetChangedDocumentAsync(context.Document, conditionalExpression.SpanStart, cancellationToken)); + context.RegisterCodeFix(documentChangeAction, diagnostic); + } + } private static async Task GetChangedDocumentAsync(Document document, int conditionalExpressionSyntaxStartPosition, CancellationToken cancellationToken) { @@ -39,5 +65,16 @@ private static async Task GetChangedDocumentAsync(Document document, i return documentWithOpenParenthesis; } + + private class MyCodeAction : CodeAction.DocumentChangeAction + { + public MyCodeAction(Func> createChangedDocument) + : base( + CSharpFeaturesResources.Add_parentheses_around_conditional_expression_in_interpolated_string, + createChangedDocument, + CSharpFeaturesResources.Add_parentheses_around_conditional_expression_in_interpolated_string) + { + } + } } } diff --git a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs deleted file mode 100644 index 6ab5c593ff19f04f9c12c8ff425b1f5396696a24..0000000000000000000000000000000000000000 --- a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Immutable; -using System.Composition; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeActions; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Shared.Extensions; - -namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.ConditionalExpressionInStringInterpolation -{ - [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.AddParenthesisAroundConditionalExpressionInInterpolatedString), Shared] - internal partial class CSharpAddParenthesisAroundConditionalExpressionInInterpolatedStringCodeFixProvider : CodeFixProvider - { - private const string CS8361 = nameof(CS8361); //A conditional expression cannot be used directly in a string interpolation because the ':' ends the interpolation.Parenthesize the conditional expression. - - public override ImmutableArray FixableDiagnosticIds => ImmutableArray.Create(CS8361); - - public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) - { - var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); - var diagnostic = context.Diagnostics.First(); - var diagnosticSpan = diagnostic.Location.SourceSpan; - var token = root.FindToken(diagnosticSpan.Start); - var conditionalExpression = token.GetAncestor(); - if (conditionalExpression != null) - { - var documentChangeAction = new CodeAction.DocumentChangeAction( - CSharpFeaturesResources.AddParenthesisAroundConditionalExpressionInInterpolatedString, - cancellationToken => GetChangedDocumentAsync(context.Document, conditionalExpression.SpanStart, cancellationToken)); - context.RegisterCodeFix(documentChangeAction, diagnostic); - } - } - } -} diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.cs.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.cs.xlf index 089102a84236f82c1158a37c35910ba932777a2d..41452422e4335f4ec9c8af793fcb017f6b35b639 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.cs.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.cs.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.de.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.de.xlf index cd3505377e9fb8301ec5852cf4f9476b8be22ef4..ecd5c99f589b377f6c8f1a399b0229282368a16c 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.de.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.de.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.es.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.es.xlf index f2172c4164620e4382fcf40b011073346a9fa529..6b1af612cf6209030ffce542e76fca2cad01f3fa 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.es.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.es.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.fr.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.fr.xlf index 6f57b1a4e1fa0746578165a8adf2a2e0f17d5edf..2ab4e520eaa2e4e4a8dbd9371f274f2551598651 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.fr.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.fr.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.it.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.it.xlf index e2efc61f30626439204a47768388ca243ccfde09..43292cb31e02a785d045a9dc9ee49725e08fb819 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.it.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.it.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ja.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ja.xlf index 0a1bd61d02b174ff26f8335b47768f88c0c58c84..0c29af84e5c718f90df0c4371ba4acb5da144187 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ja.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ja.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ko.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ko.xlf index 6e8d8d291b81a8e047f666dd7935b66411fc5257..5f7573bf73eb6bf9334cdbba78a14640c25cfdcb 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ko.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ko.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pl.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pl.xlf index 9803d89dd354e1b6775c0d37ef16af133e55a088..1bb12ba5563254c41241b916a9bcba6efd8abbec 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pl.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pl.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pt-BR.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pt-BR.xlf index ff0649547e41882e53bf398598868cd5cc20c5b3..89a79ab248570f381b27b75bf75b97577a8dccd0 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pt-BR.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pt-BR.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ru.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ru.xlf index 47a2908b78b1bd0b17846bd5de551193e66b6673..d20bee94cfab2d4cd87b7d0513daf5344680b369 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ru.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ru.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.tr.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.tr.xlf index d99e2b366a24cc34174e14d13c5a0cc3704a5b2b..8a566340f164e1c03a6426fe3eb97e03f8038163 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.tr.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.tr.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hans.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hans.xlf index 5577502f1589facd14d66c29a2833df19b6d644d..196d287439ec89ec08821c1687c9dc02b90bfa88 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hans.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hans.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hant.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hant.xlf index 6aca7057765056667b5e6743e0bddb3225174444..dfceae04de933695d1011bd8583fa7729efd82d9 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hant.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hant.xlf @@ -637,9 +637,9 @@ Use 'is null' check - - Add parenthesis - Add parenthesis + + Add parentheses + Add parentheses diff --git a/src/Features/Core/Portable/CodeFixes/PredefinedCodeFixProviderNames.cs b/src/Features/Core/Portable/CodeFixes/PredefinedCodeFixProviderNames.cs index a802596b7633182d23f0b0275bf7d33436647f73..69adbf08fd91ae3c36817c33cfcf9a5d043be1d8 100644 --- a/src/Features/Core/Portable/CodeFixes/PredefinedCodeFixProviderNames.cs +++ b/src/Features/Core/Portable/CodeFixes/PredefinedCodeFixProviderNames.cs @@ -8,7 +8,7 @@ internal static class PredefinedCodeFixProviderNames public const string AddAwait = nameof(AddAwait); public const string AddAsync = nameof(AddAsync); public const string AddParameter = nameof(AddParameter); - public const string AddParenthesisAroundConditionalExpressionInInterpolatedString = nameof(AddParenthesisAroundConditionalExpressionInInterpolatedString); + public const string AddParenthesesAroundConditionalExpressionInInterpolatedString = nameof(AddParenthesesAroundConditionalExpressionInInterpolatedString); public const string ApplyNamingStyle = nameof(ApplyNamingStyle); public const string AddBraces = nameof(AddBraces); public const string ChangeReturnType = nameof(ChangeReturnType);