diff --git a/src/EditorFeatures/CSharp/Outlining/CSharpOutliningService.cs b/src/EditorFeatures/CSharp/Outlining/CSharpOutliningService.cs index 93f504dda8a07f66f2ba857777daaa085ffc32df..382a3e2af38c0a12400f895340806b2f4f17f905 100644 --- a/src/EditorFeatures/CSharp/Outlining/CSharpOutliningService.cs +++ b/src/EditorFeatures/CSharp/Outlining/CSharpOutliningService.cs @@ -40,6 +40,7 @@ internal class CSharpOutliningService : AbstractOutliningService builder.Add(); builder.Add(); builder.Add(); + builder.Add(); builder.Add(); builder.Add(); builder.Add(); diff --git a/src/EditorFeatures/Test/EditorServicesTest.csproj b/src/EditorFeatures/Test/EditorServicesTest.csproj index c3e43dff6820510680912ceaba9f83ffb610031f..5bd13774359871c68ebdafa4e74152d381e6ca94 100644 --- a/src/EditorFeatures/Test/EditorServicesTest.csproj +++ b/src/EditorFeatures/Test/EditorServicesTest.csproj @@ -256,6 +256,7 @@ + @@ -374,4 +375,4 @@ - + \ No newline at end of file diff --git a/src/EditorFeatures/Test/Outlining/OutliningServiceTests.cs b/src/EditorFeatures/Test/Outlining/OutliningServiceTests.cs new file mode 100644 index 0000000000000000000000000000000000000000..7cb43a81652286bcdd325b342ebad524b3535f6b --- /dev/null +++ b/src/EditorFeatures/Test/Outlining/OutliningServiceTests.cs @@ -0,0 +1,103 @@ +// 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.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; +using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; +using Roslyn.Test.Utilities; +using Xunit; + +namespace Microsoft.CodeAnalysis.Editor.UnitTests.Outlining +{ + public class OutliningServiceTests + { + [Fact, Trait(Traits.Feature, Traits.Features.Outlining)] + public async Task TestSimpleLambda() + { + var code = +@"using System.Linq; +class C +{ + static void Foo() + { + var q = Enumerable.Range(1, 100).Where(x => + { + return x % 2 == 0; + }); + } +} +"; + + using (var workspace = await TestWorkspace.CreateCSharpAsync(code)) + { + var spans = await GetSpansFromWorkspaceAsync(workspace); + + // ensure all 4 outlining region tags were found (usings, class, method, lambda) + Assert.Equal(4, spans.Count); + } + } + + [Fact, Trait(Traits.Feature, Traits.Features.Outlining)] + public async Task TestParenthesizedLambda() + { + var code = +@"using System.Linq; +class C +{ + static void Foo() + { + var q = Enumerable.Range(1, 100).Where((x) => + { + return x % 2 == 0; + }); + } +} +"; + + using (var workspace = await TestWorkspace.CreateCSharpAsync(code)) + { + var spans = await GetSpansFromWorkspaceAsync(workspace); + + // ensure all 4 outlining region tags were found (usings, class, method, lambda) + Assert.Equal(4, spans.Count); + } + } + + [Fact, Trait(Traits.Feature, Traits.Features.Outlining)] + public async Task TestAnonymousDelegate() + { + var code = +@"using System.Linq; +class C +{ + static void Foo() + { + var q = Enumerable.Range(1, 100).Where(delegate (int x) + { + return x % 2 == 0; + }); + } +} +"; + + using (var workspace = await TestWorkspace.CreateCSharpAsync(code)) + { + var spans = await GetSpansFromWorkspaceAsync(workspace); + + // ensure all 4 outlining region tags were found (usings, class, method, anonymous delegate) + Assert.Equal(4, spans.Count); + } + } + + private static async Task> GetSpansFromWorkspaceAsync(TestWorkspace workspace) + { + var hostDocument = workspace.Documents.First(); + var document = workspace.CurrentSolution.GetDocument(hostDocument.Id); + var outliningService = document.Project.LanguageServices.GetService(); + + return await outliningService.GetOutliningSpansAsync(document, CancellationToken.None); + } + } +}