From 6a2b538182da365655bfccbf40a8a7fcd833d31e Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 27 Mar 2020 18:33:15 -0700 Subject: [PATCH] Updated documentation for compressEmptyLines values --- .../Providers/AccessorDeclarationStructureProvider.cs | 7 ++++++- .../Providers/ConstructorDeclarationStructureProvider.cs | 5 ++++- .../ConversionOperatorDeclarationStructureProvider.cs | 5 ++++- .../Providers/EnumDeclarationStructureProvider.cs | 5 ++++- .../Providers/EventDeclarationStructureProvider.cs | 7 ++++++- .../Providers/IndexerDeclarationStructureProvider.cs | 7 ++++++- .../Providers/MethodDeclarationStructureProvider.cs | 5 ++++- .../Providers/OperatorDeclarationStructureProvider.cs | 5 ++++- .../Providers/PropertyDeclarationStructureProvider.cs | 7 ++++++- .../Providers/TypeDeclarationStructureProvider.cs | 8 +++++++- 10 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/Features/CSharp/Portable/Structure/Providers/AccessorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/AccessorDeclarationStructureProvider.cs index c883f9097ec..e1116af8571 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/AccessorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/AccessorDeclarationStructureProvider.cs @@ -32,10 +32,15 @@ internal class AccessorDeclarationStructureProvider : AbstractSyntaxNodeStructur SyntaxNodeOrToken current = accessorDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + // + // All accessor kinds are grouped together. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.AsNode() is AccessorDeclarationSyntax; + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( accessorDeclaration, accessorDeclaration.Keyword, - compressEmptyLines: !nextSibling.IsNode || nextSibling.AsNode() is AccessorDeclarationSyntax, + compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.cs index 27c2388990d..cd12f1e76b6 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.cs @@ -32,10 +32,13 @@ internal class ConstructorDeclarationStructureProvider : AbstractSyntaxNodeStruc SyntaxNodeOrToken current = constructorDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.ConstructorDeclaration); + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( constructorDeclaration, constructorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true), - compressEmptyLines: !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.ConstructorDeclaration), + compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/ConversionOperatorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/ConversionOperatorDeclarationStructureProvider.cs index 335abb421df..d8f89e4195a 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/ConversionOperatorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/ConversionOperatorDeclarationStructureProvider.cs @@ -32,10 +32,13 @@ internal class ConversionOperatorDeclarationStructureProvider : AbstractSyntaxNo SyntaxNodeOrToken current = operatorDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.ConversionOperatorDeclaration); + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( operatorDeclaration, operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true), - compressEmptyLines: !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.ConversionOperatorDeclaration), + compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/EnumDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/EnumDeclarationStructureProvider.cs index a40c302f68b..2918adb46a1 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/EnumDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/EnumDeclarationStructureProvider.cs @@ -27,10 +27,13 @@ internal class EnumDeclarationStructureProvider : AbstractSyntaxNodeStructurePro SyntaxNodeOrToken current = enumDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax; + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( enumDeclaration, enumDeclaration.Identifier, - compressEmptyLines: !nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax, + compressEmptyLines: compressEmptyLines, autoCollapse: false, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/EventDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/EventDeclarationStructureProvider.cs index f2b3cf236ac..a72b6c3cc9d 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/EventDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/EventDeclarationStructureProvider.cs @@ -33,10 +33,15 @@ internal class EventDeclarationStructureProvider : AbstractSyntaxNodeStructurePr SyntaxNodeOrToken current = eventDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + // + // Full events are grouped together with event field definitions. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.EventDeclaration) || nextSibling.IsKind(SyntaxKind.EventFieldDeclaration); + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( eventDeclaration, eventDeclaration.Identifier, - compressEmptyLines: !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.EventDeclaration) || nextSibling.IsKind(SyntaxKind.EventFieldDeclaration), + compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/IndexerDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/IndexerDeclarationStructureProvider.cs index 0877d2e7543..1142a51726b 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/IndexerDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/IndexerDeclarationStructureProvider.cs @@ -33,10 +33,15 @@ internal class IndexerDeclarationStructureProvider : AbstractSyntaxNodeStructure SyntaxNodeOrToken current = indexerDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + // + // Indexers are grouped together with properties. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.IndexerDeclaration) || nextSibling.IsKind(SyntaxKind.PropertyDeclaration); + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( indexerDeclaration, indexerDeclaration.ParameterList.GetLastToken(includeZeroWidth: true), - compressEmptyLines: !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.IndexerDeclaration) || nextSibling.IsKind(SyntaxKind.PropertyDeclaration), + compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/MethodDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/MethodDeclarationStructureProvider.cs index 6af8b03dd92..49001a9fb3d 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/MethodDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/MethodDeclarationStructureProvider.cs @@ -32,10 +32,13 @@ internal class MethodDeclarationStructureProvider : AbstractSyntaxNodeStructureP SyntaxNodeOrToken current = methodDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.MethodDeclaration); + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( methodDeclaration, methodDeclaration.ParameterList.GetLastToken(includeZeroWidth: true), - compressEmptyLines: !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.MethodDeclaration), + compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/OperatorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/OperatorDeclarationStructureProvider.cs index dbfe3ec592d..4ba85795d0c 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/OperatorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/OperatorDeclarationStructureProvider.cs @@ -32,10 +32,13 @@ internal class OperatorDeclarationStructureProvider : AbstractSyntaxNodeStructur SyntaxNodeOrToken current = operatorDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.OperatorDeclaration); + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( operatorDeclaration, operatorDeclaration.ParameterList.GetLastToken(includeZeroWidth: true), - compressEmptyLines: !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.OperatorDeclaration), + compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/PropertyDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/PropertyDeclarationStructureProvider.cs index b218d0c2493..8d01a848ee8 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/PropertyDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/PropertyDeclarationStructureProvider.cs @@ -32,10 +32,15 @@ internal class PropertyDeclarationStructureProvider : AbstractSyntaxNodeStructur SyntaxNodeOrToken current = propertyDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + // + // Properties are grouped together with indexers. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.PropertyDeclaration) || nextSibling.IsKind(SyntaxKind.IndexerDeclaration); + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( propertyDeclaration, propertyDeclaration.Identifier, - compressEmptyLines: !nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.PropertyDeclaration) || nextSibling.IsKind(SyntaxKind.IndexerDeclaration), + compressEmptyLines: compressEmptyLines, autoCollapse: true, type: BlockTypes.Member, isCollapsible: true)); diff --git a/src/Features/CSharp/Portable/Structure/Providers/TypeDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/TypeDeclarationStructureProvider.cs index c483d64904d..c001090228f 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/TypeDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/TypeDeclarationStructureProvider.cs @@ -31,10 +31,16 @@ internal class TypeDeclarationStructureProvider : AbstractSyntaxNodeStructurePro SyntaxNodeOrToken current = typeDeclaration; var nextSibling = current.GetNextSibling(); + // Check IsNode to compress blank lines after this node if it is the last child of the parent. + // + // Collapse to Definitions doesn't collapse type nodes, but a Toggle All Outlining would collapse groups + // of types to the compressed form of not showing blank lines. All kinds of types are grouped together. + var compressEmptyLines = !nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax; + spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( typeDeclaration, lastToken, - compressEmptyLines: !nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax, + compressEmptyLines: compressEmptyLines, autoCollapse: false, type: BlockTypes.Type, isCollapsible: true)); -- GitLab