From 4ddd02524b3e0d3dc10d66fbfdaddc6e752f9f9a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 13:42:36 -0700 Subject: [PATCH] Simplify further --- .../AbstractCSharpAutoPropertySnippetProvider.cs | 9 +++++---- .../Snippets/AbstractCSharpTypeSnippetProvider.cs | 7 ++----- .../SnippetProviders/AbstractTypeSnippetProvider.cs | 9 +++------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Features/CSharp/Portable/Snippets/AbstractCSharpAutoPropertySnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/AbstractCSharpAutoPropertySnippetProvider.cs index 85ffe3357d917..554f45320a054 100644 --- a/src/Features/CSharp/Portable/Snippets/AbstractCSharpAutoPropertySnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/AbstractCSharpAutoPropertySnippetProvider.cs @@ -71,13 +71,14 @@ protected override int GetTargetCaretPosition(ISyntaxFactsService syntaxFacts, P protected override ImmutableArray GetPlaceHolderLocationsList(PropertyDeclarationSyntax propertyDeclaration, ISyntaxFacts syntaxFacts, CancellationToken cancellationToken) { - using var _ = ArrayBuilder.GetInstance(out var arrayBuilder); var identifier = propertyDeclaration.Identifier; var type = propertyDeclaration.Type; - arrayBuilder.Add(new SnippetPlaceholder(type.ToString(), type.SpanStart)); - arrayBuilder.Add(new SnippetPlaceholder(identifier.ValueText, identifier.SpanStart)); - return arrayBuilder.ToImmutable(); + return + [ + new SnippetPlaceholder(type.ToString(), type.SpanStart), + new SnippetPlaceholder(identifier.ValueText, identifier.SpanStart), + ]; } protected override PropertyDeclarationSyntax? FindAddedSnippetSyntaxNode(SyntaxNode root, int position) diff --git a/src/Features/CSharp/Portable/Snippets/AbstractCSharpTypeSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/AbstractCSharpTypeSnippetProvider.cs index 6bb523d58b01a..8d527b7523a2e 100644 --- a/src/Features/CSharp/Portable/Snippets/AbstractCSharpTypeSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/AbstractCSharpTypeSnippetProvider.cs @@ -106,9 +106,6 @@ protected override async Task AddIndentationToDocumentAsync(Document d return document.WithSyntaxRoot(newRoot); } - protected override void GetTypeDeclarationIdentifier(SyntaxNode node, out SyntaxToken identifier) - { - var typeDeclaration = (BaseTypeDeclarationSyntax)node; - identifier = typeDeclaration.Identifier; - } + protected sealed override SyntaxToken GetTypeDeclarationIdentifier(TTypeDeclarationSyntax baseTypeDeclaration) + => baseTypeDeclaration.Identifier; } diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractTypeSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractTypeSnippetProvider.cs index 58deb76a0d705..1a03d3168a221 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractTypeSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractTypeSnippetProvider.cs @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Snippets.SnippetProviders; internal abstract class AbstractTypeSnippetProvider : AbstractSnippetProvider where TTypeDeclarationSyntax : SyntaxNode { - protected abstract void GetTypeDeclarationIdentifier(SyntaxNode node, out SyntaxToken identifier); + protected abstract SyntaxToken GetTypeDeclarationIdentifier(TTypeDeclarationSyntax node); protected abstract Task GenerateTypeDeclarationAsync(Document document, int position, CancellationToken cancellationToken); protected abstract Task GetAccessibilityModifiersChangeAsync(Document document, int position, CancellationToken cancellationToken); @@ -36,11 +36,8 @@ protected sealed override async Task> GenerateSnippet protected sealed override ImmutableArray GetPlaceHolderLocationsList(TTypeDeclarationSyntax node, ISyntaxFacts syntaxFacts, CancellationToken cancellationToken) { - using var _ = ArrayBuilder.GetInstance(out var arrayBuilder); - GetTypeDeclarationIdentifier(node, out var identifier); - arrayBuilder.Add(new SnippetPlaceholder(identifier.ValueText, identifier.SpanStart)); - - return arrayBuilder.ToImmutableArray(); + var identifier = GetTypeDeclarationIdentifier(node); + return [new SnippetPlaceholder(identifier.ValueText, identifier.SpanStart)]; } protected static async Task AreAccessibilityModifiersRequiredAsync(Document document, CancellationToken cancellationToken)