From 0aa8da7d5fd6808b13e848d3026750dd730660b7 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 19 Dec 2023 08:43:17 -0600 Subject: [PATCH] Support CodeAction.NestedActions via light-up Closes #1136 --- .../CodeActionTest`1.cs | 2 +- .../Extensions/CodeActionExtensions.cs | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/CodeActionTest`1.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/CodeActionTest`1.cs index de1637ef..73f4b731 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/CodeActionTest`1.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/CodeActionTest`1.cs @@ -164,7 +164,7 @@ namespace Microsoft.CodeAnalysis.Testing for (var i = builder.Count - 1; i >= 0; i--) { var action = builder[i]; - var nestedActions = action.NestedCodeActions(); + var nestedActions = action.NestedActions(); if (!nestedActions.IsEmpty) { builder.RemoveAt(i); diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/Extensions/CodeActionExtensions.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/Extensions/CodeActionExtensions.cs index 101da1ce..a40ca377 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/Extensions/CodeActionExtensions.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/Extensions/CodeActionExtensions.cs @@ -11,13 +11,29 @@ namespace Microsoft.CodeAnalysis.Testing { internal static class CodeActionExtensions { + private static readonly Func> s_nestedActions = + LightupHelpers.CreatePropertyAccessor>( + typeof(CodeAction), + nameof(NestedActions), + defaultValue: default); + private static readonly Func> s_nestedCodeActions = LightupHelpers.CreatePropertyAccessor>( typeof(CodeAction), - nameof(NestedCodeActions), + "NestedCodeActions", defaultValue: ImmutableArray.Empty); - public static ImmutableArray NestedCodeActions(this CodeAction action) - => s_nestedCodeActions(action); + public static ImmutableArray NestedActions(this CodeAction action) + { + // CodeAction.NestedCodeActions was renamed to CodeAction.NestedActions in + // https://github.com/dotnet/roslyn/pull/71327 + var nestedActions = s_nestedActions(action); + if (nestedActions.IsDefault) + { + nestedActions = s_nestedCodeActions(action); + } + + return nestedActions; + } } }