From 95ef78c4cc2fc69de5edc35202e2bc31f61f9266 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 11 May 2021 20:12:22 +0200 Subject: [PATCH] Fix collapse to definitions for top-level statements --- .../Structure/BlockSyntaxStructureTests.cs | 19 +++++++++++++++++++ .../Providers/BlockSyntaxStructureProvider.cs | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/EditorFeatures/CSharpTest/Structure/BlockSyntaxStructureTests.cs b/src/EditorFeatures/CSharpTest/Structure/BlockSyntaxStructureTests.cs index d85aa19c7815d..587b9dbf3c3f3 100644 --- a/src/EditorFeatures/CSharpTest/Structure/BlockSyntaxStructureTests.cs +++ b/src/EditorFeatures/CSharpTest/Structure/BlockSyntaxStructureTests.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Structure; using Microsoft.CodeAnalysis.Test.Utilities; +using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure @@ -412,5 +413,23 @@ void M() await VerifyBlockSpansAsync(code, Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: false)); } + + [WorkItem(52493, "https://github.com/dotnet/roslyn/issues/")] + [Fact, Trait(Traits.Feature, Traits.Features.Outlining)] + public async Task LocalFunctionInTopLevelStatement_AutoCollapse() + { + const string code = @" +Foo(); +Bar(); + +{|hint:static void Foo(){|textspan: +{$$ + // ... +}|}|} +"; + + await VerifyBlockSpansAsync(code, + Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true)); + } } } diff --git a/src/Features/CSharp/Portable/Structure/Providers/BlockSyntaxStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/BlockSyntaxStructureProvider.cs index 4bb512f474cbb..90e13b6c821ec 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/BlockSyntaxStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/BlockSyntaxStructureProvider.cs @@ -40,7 +40,8 @@ protected override void CollectBlockSpans( isCollapsible: true, textSpan: GetTextSpan(node), hintSpan: GetHintSpan(node), - type: type)); + type: type, + autoCollapse: parentKind == SyntaxKind.LocalFunctionStatement && node.Parent.IsParentKind(SyntaxKind.GlobalStatement))); } }