未验证 提交 d0741400 编写于 作者: J Jinu 提交者: GitHub

Merge pull request #32706 from alrz/string-collapse

 Add structure provider for interpolated strings
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Structure;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure
{
public class InterpolatedStringExpressionStructureTests : AbstractCSharpSyntaxNodeStructureTests<InterpolatedStringExpressionSyntax>
{
internal override AbstractSyntaxStructureProvider CreateProvider()
=> new InterpolatedStringExpressionStructureProvider();
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
public async Task TestMultiLineStringLiteral()
{
await VerifyBlockSpansAsync(
@"
class C
{
void M()
{
var v =
{|hint:{|textspan:$$$@""
{123}
""|}|};
}
}",
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
public async Task TestMissingOnIncompleteStringLiteral()
{
await VerifyNoBlockSpansAsync(
@"
class C
{
void M()
{
var v = $$$"";
}
}");
}
}
}
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining
Public Class InterpolatedStringExpressionStructureTests
Inherits AbstractVisualBasicSyntaxNodeStructureProviderTests(Of InterpolatedStringExpressionSyntax)
Friend Overrides Function CreateProvider() As AbstractSyntaxStructureProvider
Return New InterpolatedStringExpressionStructureProvider()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Outlining)>
Public Async Function TestMultiLineStringLiteral() As Task
Const code = "
Class C
Sub M()
Dim v =
{|hint:{|textspan:$$$""
{123}
""|}|}
End Sub
End Class
"
Await VerifyBlockSpansAsync(code,
Region("textspan", "hint", "...", autoCollapse:=True))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Outlining)>
Public Async Function TestMissingOnIncompleteStringLiteral() As Task
Const code = "
Class C
Sub M()
Dim v =
$$$""
End Sub
End Class
"
Await VerifyNoBlockSpansAsync(code)
End Function
End Class
End Namespace
......@@ -42,6 +42,7 @@ internal class CSharpBlockStructureProvider : AbstractBlockStructureProvider
builder.Add<StructDeclarationSyntax, TypeDeclarationStructureProvider, MetadataAsSource.MetadataTypeDeclarationStructureProvider>();
builder.Add<SwitchStatementSyntax, SwitchStatementStructureProvider>();
builder.Add<LiteralExpressionSyntax, StringLiteralExpressionStructureProvider>();
builder.Add<InterpolatedStringExpressionSyntax, InterpolatedStringExpressionStructureProvider>();
return builder.ToImmutable();
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Structure;
namespace Microsoft.CodeAnalysis.CSharp.Structure
{
internal sealed class InterpolatedStringExpressionStructureProvider : AbstractSyntaxNodeStructureProvider<InterpolatedStringExpressionSyntax>
{
protected override void CollectBlockSpans(InterpolatedStringExpressionSyntax node, ArrayBuilder<BlockSpan> spans, OptionSet options, CancellationToken cancellationToken)
{
if (node.StringStartToken.IsMissing ||
node.StringEndToken.IsMissing)
{
return;
}
spans.Add(new BlockSpan(
isCollapsible: true,
textSpan: node.Span,
hintSpan: node.Span,
type: BlockTypes.Expression,
autoCollapse: true,
isDefaultCollapsed: false));
}
}
}
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Threading
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.PooledObjects
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Friend Class InterpolatedStringExpressionStructureProvider
Inherits AbstractSyntaxNodeStructureProvider(Of InterpolatedStringExpressionSyntax)
Protected Overrides Sub CollectBlockSpans(node As InterpolatedStringExpressionSyntax, spans As ArrayBuilder(Of BlockSpan), options As OptionSet, cancellationToken As CancellationToken)
If node.DollarSignDoubleQuoteToken.IsMissing OrElse
node.DoubleQuoteToken.IsMissing Then
Return
End If
spans.Add(New BlockSpan(
type:=BlockTypes.Expression,
isCollapsible:=True,
textSpan:=node.Span,
autoCollapse:=True,
isDefaultCollapsed:=False))
End Sub
End Class
End Namespace
......@@ -80,6 +80,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
builder.Add(Of XmlElementSyntax, XmlExpressionStructureProvider)()
builder.Add(Of XmlProcessingInstructionSyntax, XmlExpressionStructureProvider)()
builder.Add(Of LiteralExpressionSyntax, StringLiteralExpressionStructureProvider)()
builder.Add(Of InterpolatedStringExpressionSyntax, InterpolatedStringExpressionStructureProvider)()
Return builder.ToImmutable()
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册