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

17.10 : Also checking line end when block structure is filtered #74477

Merged
merged 2 commits into from
Jul 22, 2024
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 @@ -72,6 +72,7 @@ public async Task IdentifierThatLooksLikeCode()

await VerifyBlockSpansAsync(code,
Region("textspan3", "/* now everything is commented (); ...", autoCollapse: true),
Region("textspan2", "hint2", CSharpStructureHelpers.Ellipsis, autoCollapse: false),
Region("textspan1", "hint1", CSharpStructureHelpers.Ellipsis, autoCollapse: false));
}
}
34 changes: 34 additions & 0 deletions src/EditorFeatures/Test/Structure/StructureTaggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Implementation.Structure;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
Expand Down Expand Up @@ -325,6 +326,39 @@ End Sub
hints.Do(v => v.TextView_TestOnly.Close());
}

[WpfFact]
[WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2094051")]
public async Task IfShouldBeCollapsed()
{
var code = @"
Module Program
Sub Main(args As String())
Dim str = """"
If str.Contains(""foo"") Then

End If
End Sub
End Module";

using var workspace = EditorTestWorkspace.CreateVisualBasic(code, composition: EditorTestCompositions.EditorFeaturesWpf);
var tags = await GetTagsFromWorkspaceAsync(workspace);
Assert.Collection(tags, programTag =>
{
Assert.Equal("Module Program", GetHeaderText(programTag));
Assert.Equal(8, GetCollapsedHintLineCount(programTag));
},
mainTag =>
{
Assert.Equal("Sub Main(args As String())", GetHeaderText(mainTag));
Assert.Equal(6, GetCollapsedHintLineCount(mainTag));
},
IfTag =>
{
Assert.Equal("If str.Contains(\"foo\") Then", GetHeaderText(IfTag));
Assert.Equal(3, GetCollapsedHintLineCount(IfTag));
});
}

#pragma warning disable CS0618 // Type or member is obsolete
private static async Task<List<IContainerStructureTag>> GetTagsFromWorkspaceAsync(EditorTestWorkspace workspace)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,19 @@ public override void ProvideBlockStructure(in BlockStructureContext context)
// We only collapse the "inner" span which has larger start.
spans.Sort(static (x, y) => y.TextSpan.Start.CompareTo(x.TextSpan.Start));

var lastAddedLine = -1;
var lastAddedLineStart = -1;
var lastAddedLineEnd = -1;
var text = context.SyntaxTree.GetText(context.CancellationToken);

foreach (var span in spans)
{
var line = text.Lines.GetLinePosition(span.TextSpan.Start).Line;
if (line == lastAddedLine)
var lineStart = text.Lines.GetLinePosition(span.TextSpan.Start).Line;
var lineEnd = text.Lines.GetLinePosition(span.TextSpan.End).Line;
if (lineStart == lastAddedLineStart && lastAddedLineEnd == lineEnd)
continue;

lastAddedLine = line;
lastAddedLineStart = lineStart;
lastAddedLineEnd = lineEnd;
context.Spans.Add(span);
}
}
Expand Down
Loading