Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release/dev16.11 to release/dev16.11-vs-deps #54122

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static string ConvertType(string type)
BlockTypes.Loop => PredefinedStructureTagTypes.Loop,
BlockTypes.Member => PredefinedStructureTagTypes.Member,
BlockTypes.Namespace => PredefinedStructureTagTypes.Namespace,
BlockTypes.Nonstructural => PredefinedStructureTagTypes.Nonstructural,
BlockTypes.PreprocessorRegion => PredefinedStructureTagTypes.PreprocessorRegion,
BlockTypes.Statement => PredefinedStructureTagTypes.Statement,
BlockTypes.Type => PredefinedStructureTagTypes.Type,
Expand Down
72 changes: 59 additions & 13 deletions src/EditorFeatures/Test/Structure/StructureTaggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.Text.Adornments;
using Microsoft.VisualStudio.Text.Tagging;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
Expand All @@ -25,7 +26,10 @@ public class StructureTaggerTests
{
[WpfTheory, Trait(Traits.Feature, Traits.Features.Outlining)]
[CombinatorialData]
public async Task CSharpOutliningTagger(bool collapseRegionsWhenCollapsingToDefinitions)
public async Task CSharpOutliningTagger(
bool collapseRegionsWhenCollapsingToDefinitions,
bool showBlockStructureGuidesForDeclarationLevelConstructs,
bool showBlockStructureGuidesForCodeLevelConstructs)
{
var code =
@"using System;
Expand All @@ -36,6 +40,11 @@ public class MyClass
{
static void Main(string[] args)
{
if (false)
{
return;
}

int x = 5;
}
}
Expand All @@ -44,78 +53,115 @@ static void Main(string[] args)

using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf);
workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options
.WithChangedOption(BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions)));
.WithChangedOption(BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions)
.WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs)
.WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs)));

var tags = await GetTagsFromWorkspaceAsync(workspace);

Assert.Collection(tags,
namespaceTag =>
{
Assert.False(namespaceTag.IsImplementation);
Assert.Equal(12, GetCollapsedHintLineCount(namespaceTag));
Assert.Equal(17, GetCollapsedHintLineCount(namespaceTag));
Assert.Equal(showBlockStructureGuidesForDeclarationLevelConstructs ? PredefinedStructureTagTypes.Namespace : PredefinedStructureTagTypes.Nonstructural, namespaceTag.Type);
Assert.Equal("namespace MyNamespace", GetHeaderText(namespaceTag));
},
regionTag =>
{
Assert.Equal(collapseRegionsWhenCollapsingToDefinitions, regionTag.IsImplementation);
Assert.Equal(9, GetCollapsedHintLineCount(regionTag));
Assert.Equal(14, GetCollapsedHintLineCount(regionTag));
Assert.Equal(PredefinedStructureTagTypes.Nonstructural, regionTag.Type);
Assert.Equal("#region MyRegion", GetHeaderText(regionTag));
},
classTag =>
{
Assert.False(classTag.IsImplementation);
Assert.Equal(7, GetCollapsedHintLineCount(classTag));
Assert.Equal(12, GetCollapsedHintLineCount(classTag));
Assert.Equal(showBlockStructureGuidesForDeclarationLevelConstructs ? PredefinedStructureTagTypes.Type : PredefinedStructureTagTypes.Nonstructural, classTag.Type);
Assert.Equal("public class MyClass", GetHeaderText(classTag));
},
methodTag =>
{
Assert.True(methodTag.IsImplementation);
Assert.Equal(4, GetCollapsedHintLineCount(methodTag));
Assert.Equal(9, GetCollapsedHintLineCount(methodTag));
Assert.Equal(showBlockStructureGuidesForDeclarationLevelConstructs ? PredefinedStructureTagTypes.Member : PredefinedStructureTagTypes.Nonstructural, methodTag.Type);
Assert.Equal("static void Main(string[] args)", GetHeaderText(methodTag));
},
ifTag =>
{
Assert.False(ifTag.IsImplementation);
Assert.Equal(4, GetCollapsedHintLineCount(ifTag));
Assert.Equal(showBlockStructureGuidesForCodeLevelConstructs ? PredefinedStructureTagTypes.Conditional : PredefinedStructureTagTypes.Nonstructural, ifTag.Type);
Assert.Equal("if (false)", GetHeaderText(ifTag));
});
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)]
public async Task VisualBasicOutliningTagger()
[WpfTheory, Trait(Traits.Feature, Traits.Features.Outlining)]
[CombinatorialData]
public async Task VisualBasicOutliningTagger(
bool collapseRegionsWhenCollapsingToDefinitions,
bool showBlockStructureGuidesForDeclarationLevelConstructs,
bool showBlockStructureGuidesForCodeLevelConstructs)
{
var code = @"Imports System
Namespace MyNamespace
#Region ""MyRegion""
Module M
Sub Main(args As String())
If False Then
Return
End If

Dim x As Integer = 5
End Sub
End Module
#End Region
End Namespace";

using var workspace = TestWorkspace.CreateVisualBasic(code, composition: EditorTestCompositions.EditorFeaturesWpf);
workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options
.WithChangedOption(BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic, collapseRegionsWhenCollapsingToDefinitions)
.WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic, showBlockStructureGuidesForDeclarationLevelConstructs)
.WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic, showBlockStructureGuidesForCodeLevelConstructs)));

var tags = await GetTagsFromWorkspaceAsync(workspace);

Assert.Collection(tags,
namespaceTag =>
{
Assert.False(namespaceTag.IsImplementation);
Assert.Equal(9, GetCollapsedHintLineCount(namespaceTag));
Assert.Equal(13, GetCollapsedHintLineCount(namespaceTag));
Assert.Equal(showBlockStructureGuidesForDeclarationLevelConstructs ? PredefinedStructureTagTypes.Namespace : PredefinedStructureTagTypes.Nonstructural, namespaceTag.Type);
Assert.Equal("Namespace MyNamespace", GetHeaderText(namespaceTag));
},
regionTag =>
{
Assert.False(regionTag.IsImplementation);
Assert.Equal(7, GetCollapsedHintLineCount(regionTag));
Assert.Equal(collapseRegionsWhenCollapsingToDefinitions, regionTag.IsImplementation);
Assert.Equal(11, GetCollapsedHintLineCount(regionTag));
Assert.Equal(PredefinedStructureTagTypes.Nonstructural, regionTag.Type);
Assert.Equal(@"#Region ""MyRegion""", GetHeaderText(regionTag));
},
moduleTag =>
{
Assert.False(moduleTag.IsImplementation);
Assert.Equal(5, GetCollapsedHintLineCount(moduleTag));
Assert.Equal(9, GetCollapsedHintLineCount(moduleTag));
Assert.Equal(showBlockStructureGuidesForDeclarationLevelConstructs ? PredefinedStructureTagTypes.Type : PredefinedStructureTagTypes.Nonstructural, moduleTag.Type);
Assert.Equal("Module M", GetHeaderText(moduleTag));
},
methodTag =>
{
Assert.True(methodTag.IsImplementation);
Assert.Equal(3, GetCollapsedHintLineCount(methodTag));
Assert.Equal(7, GetCollapsedHintLineCount(methodTag));
Assert.Equal(showBlockStructureGuidesForDeclarationLevelConstructs ? PredefinedStructureTagTypes.Member : PredefinedStructureTagTypes.Nonstructural, methodTag.Type);
Assert.Equal("Sub Main(args As String())", GetHeaderText(methodTag));
},
ifTag =>
{
Assert.False(ifTag.IsImplementation);
Assert.Equal(3, GetCollapsedHintLineCount(ifTag));
Assert.Equal(showBlockStructureGuidesForCodeLevelConstructs ? PredefinedStructureTagTypes.Conditional : PredefinedStructureTagTypes.Nonstructural, ifTag.Type);
Assert.Equal("If False Then", GetHeaderText(ifTag));
});

}
Expand Down