Skip to content

Commit

Permalink
Merge pull request #74477 from dotnet/dev/arkalyan/missingcollapse17.10
Browse files Browse the repository at this point in the history
17.10 : Also checking line end when block structure is filtered
  • Loading branch information
arunchndr authored Jul 22, 2024
2 parents b21b471 + b60326a commit 1c55995
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
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)
{

Check failure on line 364 in src/EditorFeatures/Test/Structure/StructureTaggerTests.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs#L364

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs(364,27): error CS0111: (NETCORE_ENGINEERING_TELEMETRY=Build) Type 'StructureTaggerTests' already defines a member called 'IfShouldBeCollapsed' with the same parameter types

Check failure on line 364 in src/EditorFeatures/Test/Structure/StructureTaggerTests.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs#L364

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs(364,27): error CS0111: (NETCORE_ENGINEERING_TELEMETRY=Build) Type 'StructureTaggerTests' already defines a member called 'IfShouldBeCollapsed' with the same parameter types
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

0 comments on commit 1c55995

Please sign in to comment.