提交 3ee91ad7 编写于 作者: C CyrusNajmabadi

Make BlockSpan a struct type.

上级 a249bf74
......@@ -142,5 +142,14 @@ public static ImmutableArray<T> ToImmutableOrEmptyAndFree<T>(this ArrayBuilder<T
{
return builderOpt?.ToImmutableAndFree() ?? ImmutableArray<T>.Empty;
}
public static void AddIfNotNull<T> (this ArrayBuilder<T> builder, T? value)
where T : struct
{
if (value != null)
{
builder.Add(value.Value);
}
}
}
}
......@@ -251,7 +251,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
isCollapsible);
}
public static BlockSpan CreateBlockSpan(
public static BlockSpan? CreateBlockSpan(
SyntaxNode node, SyntaxToken syntaxToken,
string bannerText, bool autoCollapse,
string type, bool isCollapsible)
......@@ -266,7 +266,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
isCollapsible);
}
public static BlockSpan CreateBlockSpan(
public static BlockSpan? CreateBlockSpan(
SyntaxNode node, SyntaxToken startToken,
int endPos, string bannerText, bool autoCollapse,
string type, bool isCollapsible)
......@@ -293,7 +293,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
isCollapsible);
}
public static BlockSpan CreateBlockSpan(
public static BlockSpan? CreateBlockSpan(
SyntaxNode node, SyntaxToken startToken,
SyntaxToken endToken, string bannerText, bool autoCollapse,
string type, bool isCollapsible)
......@@ -321,7 +321,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
// Adds everything after 'syntaxToken' up to and including the end
// of node as a region. The snippet to display is just "..."
public static BlockSpan CreateBlockSpan(
public static BlockSpan? CreateBlockSpan(
SyntaxNode node, SyntaxToken syntaxToken,
bool autoCollapse, string type, bool isCollapsible)
{
......@@ -335,7 +335,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
// Adds everything after 'syntaxToken' up to and including the end
// of node as a region. The snippet to display is just "..."
public static BlockSpan CreateBlockSpan(
public static BlockSpan? CreateBlockSpan(
SyntaxNode node, SyntaxToken startToken, SyntaxToken endToken,
bool autoCollapse, string type, bool isCollapsible)
{
......@@ -350,7 +350,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
// Adds the span surrounding the syntax list as a region. The
// snippet shown is the text from the first line of the first
// node in the list.
public static BlockSpan CreateBlockSpan(
public static BlockSpan? CreateBlockSpan(
IEnumerable<SyntaxNode> syntaxList, bool autoCollapse,
string type, bool isCollapsible)
{
......
// 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.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -24,7 +23,7 @@ internal class AccessorDeclarationStructureProvider : AbstractSyntaxNodeStructur
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
accessorDeclaration,
accessorDeclaration.Keyword,
autoCollapse: true,
......@@ -32,4 +31,4 @@ internal class AccessorDeclarationStructureProvider : AbstractSyntaxNodeStructur
isCollapsible: true));
}
}
}
}
\ 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.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -32,7 +31,7 @@ internal class AnonymousMethodExpressionStructureProvider : AbstractSyntaxNodeSt
? anonymousMethod.ParameterList.GetLastToken(includeZeroWidth: true)
: anonymousMethod.DelegateKeyword;
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
anonymousMethod,
startToken,
lastToken,
......@@ -41,4 +40,4 @@ internal class AnonymousMethodExpressionStructureProvider : AbstractSyntaxNodeSt
isCollapsible: true));
}
}
}
}
\ 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.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -23,7 +22,7 @@ internal class CompilationUnitStructureProvider : AbstractSyntaxNodeStructurePro
externsAndUsings.AddRange(compilationUnit.Usings);
externsAndUsings.Sort((node1, node2) => node1.SpanStart.CompareTo(node2.SpanStart));
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
externsAndUsings, autoCollapse: true,
type: BlockTypes.Imports, isCollapsible: true));
......@@ -41,4 +40,4 @@ protected override bool SupportedInWorkspaceKind(string kind)
return true;
}
}
}
}
\ 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.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -24,7 +23,7 @@ internal class ConstructorDeclarationStructureProvider : AbstractSyntaxNodeStruc
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
constructorDeclaration,
constructorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
autoCollapse: true,
......@@ -32,4 +31,4 @@ internal class ConstructorDeclarationStructureProvider : AbstractSyntaxNodeStruc
isCollapsible: true));
}
}
}
}
\ 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.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -24,7 +23,7 @@ internal class ConversionOperatorDeclarationStructureProvider : AbstractSyntaxNo
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
operatorDeclaration,
operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
autoCollapse: true,
......@@ -32,4 +31,4 @@ internal class ConversionOperatorDeclarationStructureProvider : AbstractSyntaxNo
isCollapsible: true));
}
}
}
}
\ 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.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -24,7 +23,7 @@ internal class DestructorDeclarationStructureProvider : AbstractSyntaxNodeStruct
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
destructorDeclaration,
destructorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
autoCollapse: true,
......
// 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.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -19,7 +18,7 @@ internal class EnumDeclarationStructureProvider : AbstractSyntaxNodeStructurePro
if (!enumDeclaration.OpenBraceToken.IsMissing &&
!enumDeclaration.CloseBraceToken.IsMissing)
{
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
enumDeclaration,
enumDeclaration.Identifier,
autoCollapse: false,
......
......@@ -23,7 +23,7 @@ internal class EventDeclarationStructureProvider : AbstractSyntaxNodeStructurePr
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
eventDeclaration,
eventDeclaration.Identifier,
autoCollapse: true,
......
// 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.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -25,7 +24,7 @@ internal class IndexerDeclarationStructureProvider : AbstractSyntaxNodeStructure
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
indexerDeclaration,
indexerDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
autoCollapse: true,
......
// 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.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -24,7 +23,7 @@ internal class MethodDeclarationStructureProvider : AbstractSyntaxNodeStructureP
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
methodDeclaration,
methodDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
autoCollapse: true,
......
// 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.Collections.Immutable;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
......@@ -21,7 +20,7 @@ internal class NamespaceDeclarationStructureProvider : AbstractSyntaxNodeStructu
if (!namespaceDeclaration.OpenBraceToken.IsMissing &&
!namespaceDeclaration.CloseBraceToken.IsMissing)
{
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
namespaceDeclaration,
namespaceDeclaration.Name.GetLastToken(includeZeroWidth: true),
autoCollapse: false,
......@@ -40,7 +39,7 @@ internal class NamespaceDeclarationStructureProvider : AbstractSyntaxNodeStructu
CSharpStructureHelpers.CollectCommentBlockSpans(externsAndUsings.First(), spans);
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
externsAndUsings, autoCollapse: true,
type: BlockTypes.Imports, isCollapsible: true));
......
// 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.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -24,7 +23,7 @@ internal class OperatorDeclarationStructureProvider : AbstractSyntaxNodeStructur
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
operatorDeclaration,
operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true),
autoCollapse: true,
......
......@@ -34,7 +34,7 @@ internal class ParenthesizedLambdaExpressionStructureProvider : AbstractSyntaxNo
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
lambdaExpression,
lambdaExpression.ArrowToken,
lastToken,
......
// 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.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -24,7 +23,7 @@ internal class PropertyDeclarationStructureProvider : AbstractSyntaxNodeStructur
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
propertyDeclaration,
propertyDeclaration.Identifier,
autoCollapse: true,
......@@ -32,4 +31,4 @@ internal class PropertyDeclarationStructureProvider : AbstractSyntaxNodeStructur
isCollapsible: true));
}
}
}
}
\ 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.
using System.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -34,7 +33,7 @@ internal class SimpleLambdaExpressionStructureProvider : AbstractSyntaxNodeStruc
return;
}
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
lambdaExpression,
lambdaExpression.ArrowToken,
lastToken,
......
// 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.Collections.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
......@@ -28,7 +27,7 @@ internal class TypeDeclarationStructureProvider : AbstractSyntaxNodeStructurePro
: typeDeclaration.Kind() == SyntaxKind.StructDeclaration
? BlockTypes.Structure
: BlockTypes.Class;
spans.Add(CSharpStructureHelpers.CreateBlockSpan(
spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan(
typeDeclaration,
lastToken,
autoCollapse: false,
......
......@@ -4,7 +4,7 @@
namespace Microsoft.CodeAnalysis.Structure
{
internal class BlockSpan
internal struct BlockSpan
{
private const string Ellipses = "...";
......
......@@ -80,17 +80,14 @@ public override async Task ProvideBlockStructureAsync(BlockStructureContext cont
foreach (var span in spans)
{
if (span != null)
{
var updatedSpan = UpdateBlockSpan(span,
showIndentGuidesForCodeLevelConstructs,
showIndentGuidesForDeclarationLevelConstructs,
showIndentGuidesForCommentsAndPreprocessorRegions,
showOutliningForCodeLevelConstructs,
showOutliningForDeclarationLevelConstructs,
showOutliningForCommentsAndPreprocessorRegions);
context.AddBlockSpan(updatedSpan);
}
var updatedSpan = UpdateBlockSpan(span,
showIndentGuidesForCodeLevelConstructs,
showIndentGuidesForDeclarationLevelConstructs,
showIndentGuidesForCommentsAndPreprocessorRegions,
showOutliningForCodeLevelConstructs,
showOutliningForDeclarationLevelConstructs,
showOutliningForCommentsAndPreprocessorRegions);
context.AddBlockSpan(updatedSpan);
}
spans.Free();
......
......@@ -16,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim block = TryCast(accessorDeclaration.Parent, AccessorBlockSyntax)
If Not block?.EndBlockStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=accessorDeclaration,
autoCollapse:=True, type:=BlockTypes.Accessor, isCollapsible:=True))
End If
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -12,10 +11,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Protected Overrides Sub CollectBlockSpans(compilationUnit As CompilationUnitSyntax,
spans As ArrayBuilder(Of BlockSpan),
cancellationToken As CancellationToken)
Dim regions As New List(Of BlockSpan)
CollectCommentsRegions(compilationUnit, spans)
spans.Add(CreateRegion(
spans.AddIfNotNull(CreateRegion(
compilationUnit.Imports, bannerText:="Imports" & SpaceEllipsis,
autoCollapse:=True, type:=BlockTypes.Nonstructural, isCollapsible:=True))
CollectCommentsRegions(compilationUnit.EndOfFileToken.LeadingTrivia, spans)
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -18,7 +17,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim block = TryCast(constructorDeclaration.Parent, ConstructorBlockSyntax)
If Not block?.EndBlockStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=constructorDeclaration, autoCollapse:=True,
type:=BlockTypes.Constructor, isCollapsible:=True))
End If
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.Text
......@@ -18,7 +17,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim startPos = nodeSpan.Start
Dim endPos = startPos + trivia.ToString().TrimEnd().Length
spans.Add(CreateRegion(
spans.AddIfNotNull(CreateRegion(
span:=TextSpan.FromBounds(startPos, endPos),
bannerText:=Ellipsis, autoCollapse:=True,
type:=BlockTypes.Nonstructural, isCollapsible:=True))
......
' 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.Collections.Immutable
Imports System.Text
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
......@@ -87,7 +86,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim fullSpan = TextSpan.FromBounds(startPos, endPos)
spans.Add(CreateRegion(
spans.AddIfNotNull(CreateRegion(
fullSpan, GetBannerText(documentationComment, cancellationToken),
autoCollapse:=True, type:=BlockTypes.Nonstructural, isCollapsible:=True))
End Sub
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -16,7 +15,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim block = TryCast(enumDeclaration.Parent, EnumBlockSyntax)
If Not block?.EndEnumStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=enumDeclaration, autoCollapse:=True,
type:=BlockTypes.Enum, isCollapsible:=True))
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -16,7 +15,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim block = TryCast(eventDeclaration.Parent, EventBlockSyntax)
If Not block?.EndEventStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=eventDeclaration, autoCollapse:=True,
type:=BlockTypes.Event, isCollapsible:=True))
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.Text
......@@ -25,7 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure.MetadataAsSource
cancellationToken As CancellationToken)
Dim match = regionDirective.GetMatchingStartOrEndDirective(cancellationToken)
If match IsNot Nothing Then
spans.Add(CreateRegion(
spans.AddIfNotNull(CreateRegion(
TextSpan.FromBounds(regionDirective.SpanStart, match.Span.End),
GetBannerText(regionDirective),
autoCollapse:=True,
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -16,7 +15,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim block = TryCast(methodDeclaration.Parent, MethodBlockSyntax)
If Not block?.EndBlockStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=methodDeclaration, autoCollapse:=True,
type:=BlockTypes.Method, isCollapsible:=True))
End If
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -13,7 +12,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
spans As ArrayBuilder(Of BlockSpan),
cancellationToken As CancellationToken)
If Not lambdaExpression.EndSubOrFunctionStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
lambdaExpression, bannerNode:=lambdaExpression.SubOrFunctionHeader, autoCollapse:=False,
type:=BlockTypes.AnonymousMethod, isCollapsible:=True))
End If
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -16,7 +15,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim block = TryCast(namespaceDeclaration.Parent, NamespaceBlockSyntax)
If Not block?.EndNamespaceStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=namespaceDeclaration, autoCollapse:=False,
type:=BlockTypes.Namespace, isCollapsible:=True))
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -16,7 +15,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim block = TryCast(operatorDeclaration.Parent, OperatorBlockSyntax)
If Not block?.EndBlockStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=operatorDeclaration, autoCollapse:=True,
type:=BlockTypes.Operator, isCollapsible:=True))
End If
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -16,7 +15,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim block = TryCast(propertyDeclaration.Parent, PropertyBlockSyntax)
If Not block?.EndPropertyStatement.IsMissing Then
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=propertyDeclaration, autoCollapse:=True,
type:=BlockTypes.Property, isCollapsible:=True))
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.Text
......@@ -25,7 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
cancellationToken As CancellationToken)
Dim matchingDirective = regionDirective.GetMatchingStartOrEndDirective(cancellationToken)
If matchingDirective IsNot Nothing Then
spans.Add(CreateRegion(
spans.AddIfNotNull(CreateRegion(
TextSpan.FromBounds(regionDirective.SpanStart, matchingDirective.Span.End),
GetBannerText(regionDirective),
autoCollapse:=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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -21,7 +20,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
If(typeDeclaration.Kind() = SyntaxKind.StructureStatement, BlockTypes.Structure,
If(typeDeclaration.Kind() = SyntaxKind.ModuleStatement, BlockTypes.Module,
BlockTypes.Class)))
spans.Add(CreateRegionFromBlock(
spans.AddIfNotNull(CreateRegionFromBlock(
block, bannerNode:=typeDeclaration, autoCollapse:=False,
type:=type, isCollapsible:=True))
......
' 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.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
......@@ -23,7 +22,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Dim lineText = line.ToString().Substring(span.Start - line.Start)
Dim bannerText = lineText & SpaceEllipsis
spans.Add(CreateRegion(
spans.AddIfNotNull(CreateRegion(
span, bannerText, autoCollapse:=False,
type:=BlockTypes.Xml, isCollapsible:=True))
End Sub
......
......@@ -18,7 +18,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
Return "' " & comment.ToString().Substring(1).Trim() & SpaceEllipsis
End Function
Private Function CreateCommentsRegion(startComment As SyntaxTrivia, endComment As SyntaxTrivia) As BlockSpan
Private Function CreateCommentsRegion(startComment As SyntaxTrivia,
endComment As SyntaxTrivia) As BlockSpan?
Return CreateRegion(
TextSpan.FromBounds(startComment.SpanStart, endComment.Span.End),
GetCommentBannerText(startComment),
......@@ -50,7 +51,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
trivia.Kind <> SyntaxKind.EndOfFileToken Then
If startComment IsNot Nothing Then
spans.Add(CreateCommentsRegion(startComment.Value, endComment.Value))
spans.AddIfNotNull(CreateCommentsRegion(startComment.Value, endComment.Value))
startComment = Nothing
endComment = Nothing
End If
......@@ -59,7 +60,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
' Add any final span
If startComment IsNot Nothing Then
spans.Add(CreateCommentsRegion(startComment.Value, endComment.Value))
spans.AddIfNotNull(CreateCommentsRegion(startComment.Value, endComment.Value))
End If
End If
End Sub
......@@ -81,7 +82,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
autoCollapse As Boolean,
type As String,
isCollapsible As Boolean,
Optional isDefaultCollapsed As Boolean = False) As BlockSpan
Optional isDefaultCollapsed As Boolean = False) As BlockSpan?
Return New BlockSpan(
textSpan:=span,
bannerText:=bannerText,
......@@ -96,7 +97,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
bannerText As String,
autoCollapse As Boolean,
type As String,
isCollapsible As Boolean) As BlockSpan
isCollapsible As Boolean) As BlockSpan?
Return CreateRegion(blockNode.Span, bannerText, autoCollapse, type, isCollapsible)
End Function
......@@ -105,7 +106,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
bannerNode As SyntaxNode,
autoCollapse As Boolean,
type As String,
isCollapsible As Boolean) As BlockSpan
isCollapsible As Boolean) As BlockSpan?
Return CreateRegion(
blockNode.Span, GetNodeBannerText(bannerNode),
autoCollapse, type, isCollapsible)
......@@ -115,7 +116,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure
bannerText As String,
autoCollapse As Boolean,
type As String,
isCollapsible As Boolean) As BlockSpan
isCollapsible As Boolean) As BlockSpan?
If syntaxList.IsEmpty() Then
Return Nothing
End If
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册