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 #54178

Merged
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
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<MajorVersion>3</MajorVersion>
<MinorVersion>11</MinorVersion>
<PatchVersion>0</PatchVersion>
<PreReleaseVersionLabel>2</PreReleaseVersionLabel>
<PreReleaseVersionLabel>3</PreReleaseVersionLabel>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<!--
By default the assembly version in official builds is "$(MajorVersion).$(MinorVersion).0.0".
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ public InheritanceGlyphFactory(
var membersOnLine = inheritanceMarginTag.MembersOnLine;
Contract.ThrowIfTrue(membersOnLine.IsEmpty);

// ZoomLevel of textView is percentage based. (e.g. 20 -> 400 means 20% -> 400%)
// and the scaleFactor of CrispImage is 1 based. (e.g 1 means 100%)
var scaleFactor = _textView.ZoomLevel / 100;
return new MarginGlyph.InheritanceMargin(
_threadingContext,
_streamingFindUsagesPresenter,
_classificationTypeMap,
_classificationFormatMap,
_waitIndicator,
inheritanceMarginTag,
scaleFactor);
_textView);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Editor;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.InheritanceMargin.MarginGlyph
{
Expand All @@ -25,6 +26,7 @@ internal partial class InheritanceMargin
private readonly IStreamingFindUsagesPresenter _streamingFindUsagesPresenter;
private readonly IWaitIndicator _waitIndicator;
private readonly Workspace _workspace;
private readonly IWpfTextView _textView;

public InheritanceMargin(
IThreadingContext threadingContext,
Expand All @@ -33,14 +35,18 @@ public InheritanceMargin(
IClassificationFormatMap classificationFormatMap,
IWaitIndicator waitIndicator,
InheritanceMarginTag tag,
double scaleFactor)
IWpfTextView textView)
{
_threadingContext = threadingContext;
_streamingFindUsagesPresenter = streamingFindUsagesPresenter;
_workspace = tag.Workspace;
_waitIndicator = waitIndicator;
_textView = textView;
InitializeComponent();

// ZoomLevel of textView is percentage based. (e.g. 20 -> 400 means 20% -> 400%)
// and the scaleFactor of CrispImage is 1 based. (e.g 1 means 100%)
var scaleFactor = textView.ZoomLevel;
var viewModel = InheritanceMarginViewModel.Create(classificationTypeMap, classificationFormatMap, tag, scaleFactor);
DataContext = viewModel;
ContextMenu.DataContext = viewModel;
Expand Down Expand Up @@ -99,6 +105,9 @@ private void InheritanceMargin_OnMouseLeave(object sender, MouseEventArgs e)
private void ContextMenu_OnClose(object sender, RoutedEventArgs e)
{
ResetBorderToInitialColor();
// Move the focus back to textView when the context menu is closed.
// It ensures the focus won't be left at the margin
ResetFocus();
}

private void ContextMenu_OnOpen(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -131,5 +140,17 @@ private void ResetBorderToInitialColor()
this.Background = Brushes.Transparent;
this.BorderBrush = Brushes.Transparent;
}

private void ResetFocus()
{
if (!_textView.HasAggregateFocus)
{
var visualElement = _textView.VisualElement;
if (visualElement.Focusable)
{
Keyboard.Focus(visualElement);
}
}
}
}
}