Skip to content

Commit

Permalink
Merge pull request #74413 from Cosifne/dev/shech/FixMissingCollapse
Browse files Browse the repository at this point in the history
Also checking line end when block structure is filtered
  • Loading branch information
Cosifne authored and arunchndr committed Jul 22, 2024
1 parent b21b471 commit ad2afad
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]

Check failure on line 329 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#L329

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs(329,5): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
[WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2094051")]

Check failure on line 330 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#L330

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs(330,5): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
public async Task IfShouldBeCollapsed()

Check failure on line 331 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#L331

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs(331,5): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
{

Check failure on line 332 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#L332

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs(332,5): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
var code = @"

Check failure on line 333 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#L333

src/EditorFeatures/Test/Structure/StructureTaggerTests.cs(333,9): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
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

0 comments on commit ad2afad

Please sign in to comment.