提交 efbc71c9 编写于 作者: C CyrusNajmabadi

Add support for VB collectoin types.

上级 c3da8cdb
......@@ -190,6 +190,8 @@
<Compile Include="Diagnostics\OverloadBase\OverloadBaseTests.vb" />
<Compile Include="Diagnostics\PreferFrameworkType\PreferFrameworkTypeTests.vb" />
<Compile Include="Diagnostics\PreferFrameworkType\PreferFrameworkTypeTests_FixAllTests.vb" />
<Compile Include="Structure\ObjectCollectionInitializerStructureProviderTests.vb" />
<Compile Include="Structure\ObjectMemberInitializerStructureProviderTests.vb" />
<Compile Include="QualifyMemberAccess\QualifyMemberAccessTests.vb" />
<Compile Include="QualifyMemberAccess\QualifyMemberAccessTests_FixAllTests.vb" />
<Compile Include="Diagnostics\RemoveUnnecessaryCast\RemoveUnnecessaryCastTests.vb" />
......
' 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 ObjectCollectionInitializerStructureProviderTests
Inherits AbstractVisualBasicSyntaxNodeStructureProviderTests(Of ObjectCollectionInitializerSyntax)
Friend Overrides Function CreateProvider() As AbstractSyntaxStructureProvider
Return New ObjectCreationInitializerStructureProvider()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Outlining)>
Public Async Function TestOuterInitializer() As Task
Const code = "
Class C
Sub M()
dim d = {|hintspan:new Dictionary(of integer, string){|textspan: $$From {
{ 1, ""foo"" }
}|}|}
End Sub
End Class
"
Await VerifyBlockSpansAsync(code,
Region("textspan", "hintspan", bannerText:="...", autoCollapse:=False))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Outlining)>
Public Async Function TestInnerInitializer() As Task
Const code = "
Class C
Sub M()
dim d = new Dictionary(of integer, string) From {
{|hintspan:{|textspan:$${
1, ""foo""
},|}|}
{
1, ""foo""
}
}
End Sub
End Class
"
Await VerifyBlockSpansAsync(code,
Region("textspan", "hintspan", bannerText:="...", autoCollapse:=False))
End Function
End Class
End Namespace
\ No newline at end of file
' 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 ObjectMemberInitializerStructureProviderTests
Inherits AbstractVisualBasicSyntaxNodeStructureProviderTests(Of ObjectMemberInitializerSyntax)
Friend Overrides Function CreateProvider() As AbstractSyntaxStructureProvider
Return New ObjectCreationInitializerStructureProvider()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Outlining)>
Public Async Function TestOuterInitializer() As Task
Const code = "
Class C
private i as integer
Sub M()
dim d = {|hintspan:new C{|textspan: $$With {
.i = 1
}|}|}
End Sub
End Class
"
Await VerifyBlockSpansAsync(code,
Region("textspan", "hintspan", bannerText:="...", autoCollapse:=False))
End Function
End Class
End Namespace
\ No newline at end of file
......@@ -5,7 +5,8 @@
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<ProjectGuid>{A1BCD0CE-6C2F-4F8C-9A48-D9D93928E26D}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace></RootNamespace>
<RootNamespace>
</RootNamespace>
<AssemblyName>Microsoft.CodeAnalysis.VisualBasic.Features</AssemblyName>
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
......@@ -112,6 +113,8 @@
<Compile Include="CodeFixes\NamingStyles\VisualBasicNamingStyleCodeFixProvider.vb" />
<Compile Include="CodeFixes\OverloadBase\OverloadBaseCodeFixProvider.AddOverloads.vb" />
<Compile Include="CodeFixes\OverloadBase\OverloadBaseCodeFixProvider.vb" />
<Compile Include="Structure\Providers\CollectionInitializerStructureProvider.vb" />
<Compile Include="Structure\Providers\ObjectCreationInitializerStructureProvider.vb" />
<Compile Include="QualifyMemberAccess\VisualBasicQualifyMemberAccessCodeFixProvider.vb" />
<Compile Include="CodeFixes\RemoveUnnecessaryCast\RemoveUnnecessaryCastCodeFixProvider.RemoveUnnecessaryCastFixAllProvider.vb" />
<Compile Include="CodeFixes\RemoveUnnecessaryCast\RemoveUnnecessaryCastCodeFixProvider.Rewriter.vb" />
......
' 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.Structure
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Friend Class CollectionInitializerStructureProvider
Inherits AbstractSyntaxNodeStructureProvider(Of CollectionInitializerSyntax)
Protected Overrides Sub CollectBlockSpans(node As CollectionInitializerSyntax,
spans As ArrayBuilder(Of BlockSpan),
cancellationToken As CancellationToken)
' We don't want to make a span for the "{ ... }" in "From { ... }". The latter
' is already handled by ObjectCreationInitializerStructureProvider
If TypeOf node.Parent IsNot ObjectCollectionInitializerSyntax Then
' We have something Like:
'
' New Dictionary(Of int, string) From {
' ...
' {
' ...
' },
' ...
' }
'
' In this case, we want to collapse the "{ ... }," (including the comma).
Dim nextToken = node.CloseBraceToken.GetNextToken()
Dim endPos = If(nextToken.Kind() = SyntaxKind.CommaToken,
nextToken.Span.End,
node.Span.End)
spans.Add(New BlockSpan(
isCollapsible:=True,
textSpan:=TextSpan.FromBounds(node.SpanStart, endPos),
hintSpan:=TextSpan.FromBounds(node.SpanStart, endPos),
type:=BlockTypes.Expression))
End If
End Sub
End Class
End Namespace
\ No newline at end of file
' 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.Structure
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Friend Class ObjectCreationInitializerStructureProvider
Inherits AbstractSyntaxNodeStructureProvider(Of ObjectCreationInitializerSyntax)
Protected Overrides Sub CollectBlockSpans(node As ObjectCreationInitializerSyntax,
spans As ArrayBuilder(Of BlockSpan),
cancellationToken As CancellationToken)
' ObjectCreationInitializerSyntax is either "With { ... }" or "From { ... }"
' Parent Is something Like
'
' New Dictionary(Of int, string) From {
' ...
' }
'
' The collapsed textspan should be from the ) to the }
'
' However, the hint span should be the entire object creation.
Dim previousToken = node.GetFirstToken().GetPreviousToken()
spans.Add(New BlockSpan(
isCollapsible:=True,
textSpan:=TextSpan.FromBounds(previousToken.Span.End, node.Span.End),
hintSpan:=node.Parent.Span,
type:=BlockTypes.Expression))
End Sub
End Class
End Namespace
\ No newline at end of file
......@@ -43,6 +43,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
builder.Add(Of AccessorStatementSyntax, AccessorDeclarationStructureProvider)()
builder.Add(Of ClassStatementSyntax, TypeDeclarationStructureProvider, MetadataAsSource.MetadataTypeDeclarationStructureProvider)()
builder.Add(Of CollectionInitializerSyntax, CollectionInitializerStructureProvider)
builder.Add(Of CompilationUnitSyntax, CompilationUnitStructureProvider)()
builder.Add(Of SubNewStatementSyntax, ConstructorDeclarationStructureProvider, MetadataAsSource.MetadataConstructorDeclarationStructureProvider)()
builder.Add(Of DelegateStatementSyntax, DelegateDeclarationStructureProvider, MetadataAsSource.MetadataDelegateDeclarationStructureProvider)()
......@@ -61,6 +62,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
builder.Add(Of MultiLineIfBlockSyntax, MultiLineIfBlockStructureProvider)()
builder.Add(Of MultiLineLambdaExpressionSyntax, MultilineLambdaStructureProvider)()
builder.Add(Of NamespaceStatementSyntax, NamespaceDeclarationStructureProvider)()
builder.Add(Of ObjectCollectionInitializerSyntax, ObjectCreationInitializerStructureProvider)
builder.Add(Of ObjectMemberInitializerSyntax, ObjectCreationInitializerStructureProvider)
builder.Add(Of OperatorStatementSyntax, OperatorDeclarationStructureProvider, MetadataAsSource.MetadataOperatorDeclarationStructureProvider)()
builder.Add(Of PropertyStatementSyntax, PropertyDeclarationStructureProvider, MetadataAsSource.MetadataPropertyDeclarationStructureProvider)()
builder.Add(Of RegionDirectiveTriviaSyntax, RegionDirectiveStructureProvider, MetadataAsSource.MetadataRegionDirectiveStructureProvider)()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册