Skip to content
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 @@ -7,6 +7,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure;
Expand Down Expand Up @@ -231,4 +232,21 @@ public Task TestStructWithNestedComments()
""",
Region("textspan1", "hint1", CSharpStructureHelpers.Ellipsis, autoCollapse: false),
Region("span2", "// Goo ...", autoCollapse: true));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/62506")]
public Task TestTypeDeclarationNoBraces1()
=> VerifyBlockSpansAsync("""
{|comment:// comment|}
$$struct S
""",
Region("comment", "// comment ...", autoCollapse: true));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/62506")]
public Task TestTypeDeclarationNoBraces2()
=> VerifyBlockSpansAsync("""
{|comment:// comment|}
{|hint1:$$struct S{|textspan1:;|}|}
""",
Region("comment", "// comment ...", autoCollapse: true),
Region("textspan1", "hint1", CSharpStructureHelpers.Ellipsis, autoCollapse: false));
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,12 @@ static SyntaxToken GetEndToken(SyntaxNode node)
static SyntaxToken GetHintTextEndToken(SyntaxNode node)
=> node switch
{
EnumDeclarationSyntax enumDeclaration => enumDeclaration.OpenBraceToken.GetPreviousToken(),
TypeDeclarationSyntax typeDeclaration => typeDeclaration.OpenBraceToken.GetPreviousToken(),
EnumDeclarationSyntax enumDeclaration
=> enumDeclaration.OpenBraceToken.GetPreviousToken(),
TypeDeclarationSyntax typeDeclaration
=> typeDeclaration.OpenBraceToken != default
? typeDeclaration.OpenBraceToken.GetPreviousToken()
: typeDeclaration.SemicolonToken.GetPreviousToken(),
_ => node.GetLastToken()
};
}
Expand Down
Loading