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 @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.UnitTests.Structure;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure;
Expand All @@ -11,4 +13,9 @@ public abstract class AbstractCSharpSyntaxNodeStructureTests<TSyntaxNode> :
where TSyntaxNode : SyntaxNode
{
protected sealed override string LanguageName => LanguageNames.CSharp;

private protected new Task VerifyBlockSpansAsync(
[StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string markupCode,
params RegionData[] expectedRegionData)
=> base.VerifyBlockSpansAsync(markupCode, expectedRegionData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,22 @@ public Task TestTypeDeclarationNoBraces2()
""",
Region("comment", "// comment ...", autoCollapse: true),
Region("textspan1", "hint1", CSharpStructureHelpers.Ellipsis, autoCollapse: false));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81662")]
public Task TestExtension1()
=> VerifyBlockSpansAsync("""
{|hint:$$extension{|textspan:(string s)
{
}|}|}
""",
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: false));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81662")]
public Task TestExtension2()
=> VerifyBlockSpansAsync("""
{|hint:$$extension<T>{|textspan:(string s)
{
}|}|}
""",
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: false));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;

namespace Microsoft.CodeAnalysis.CSharp.Structure;

internal sealed class CSharpBlockStructureProvider : AbstractBlockStructureProvider
internal sealed class CSharpBlockStructureProvider()
: AbstractBlockStructureProvider(CreateDefaultNodeProviderMap(), CreateDefaultTriviaProviderMap())
{
private static ImmutableDictionary<Type, ImmutableArray<AbstractSyntaxStructureProvider>> CreateDefaultNodeProviderMap()
{
Expand All @@ -32,6 +31,7 @@ private static ImmutableDictionary<Type, ImmutableArray<AbstractSyntaxStructureP
builder.Add<EnumMemberDeclarationSyntax, EnumMemberDeclarationStructureProvider>();
builder.Add<EventDeclarationSyntax, EventDeclarationStructureProvider>();
builder.Add<EventFieldDeclarationSyntax, EventFieldDeclarationStructureProvider>();
builder.Add<ExtensionBlockDeclarationSyntax, TypeDeclarationStructureProvider>();
builder.Add<FieldDeclarationSyntax, FieldDeclarationStructureProvider>();
builder.Add<FileScopedNamespaceDeclarationSyntax, FileScopedNamespaceDeclarationStructureProvider>();
builder.Add<IndexerDeclarationSyntax, IndexerDeclarationStructureProvider>();
Expand Down Expand Up @@ -68,9 +68,4 @@ private static ImmutableDictionary<int, ImmutableArray<AbstractSyntaxStructurePr

return builder.ToImmutable();
}

internal CSharpBlockStructureProvider()
: base(CreateDefaultNodeProviderMap(), CreateDefaultTriviaProviderMap())
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.PooledObjects;
Expand All @@ -25,9 +23,11 @@ protected override void CollectBlockSpans(
if (!typeDeclaration.OpenBraceToken.IsMissing &&
!typeDeclaration.CloseBraceToken.IsMissing)
{
var lastToken = typeDeclaration.TypeParameterList == null
? typeDeclaration.Identifier
: typeDeclaration.TypeParameterList.GetLastToken(includeZeroWidth: true);
var lastToken = typeDeclaration.TypeParameterList != null
? typeDeclaration.TypeParameterList.GetLastToken(includeZeroWidth: true)
: typeDeclaration is ExtensionBlockDeclarationSyntax extensionBlock
? extensionBlock.Keyword
: typeDeclaration.Identifier;

SyntaxNodeOrToken current = typeDeclaration;
var nextSibling = current.GetNextSibling();
Expand Down
Loading