Skip to content

Commit

Permalink
Simplify further
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Apr 5, 2024
1 parent 5a66e89 commit 4ddd025
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ protected override int GetTargetCaretPosition(ISyntaxFactsService syntaxFacts, P

protected override ImmutableArray<SnippetPlaceholder> GetPlaceHolderLocationsList(PropertyDeclarationSyntax propertyDeclaration, ISyntaxFacts syntaxFacts, CancellationToken cancellationToken)
{
using var _ = ArrayBuilder<SnippetPlaceholder>.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ protected override async Task<Document> 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Snippets.SnippetProviders;
internal abstract class AbstractTypeSnippetProvider<TTypeDeclarationSyntax> : AbstractSnippetProvider<TTypeDeclarationSyntax>
where TTypeDeclarationSyntax : SyntaxNode
{
protected abstract void GetTypeDeclarationIdentifier(SyntaxNode node, out SyntaxToken identifier);
protected abstract SyntaxToken GetTypeDeclarationIdentifier(TTypeDeclarationSyntax node);
protected abstract Task<TTypeDeclarationSyntax> GenerateTypeDeclarationAsync(Document document, int position, CancellationToken cancellationToken);
protected abstract Task<TextChange?> GetAccessibilityModifiersChangeAsync(Document document, int position, CancellationToken cancellationToken);

Expand All @@ -36,11 +36,8 @@ protected sealed override async Task<ImmutableArray<TextChange>> GenerateSnippet

protected sealed override ImmutableArray<SnippetPlaceholder> GetPlaceHolderLocationsList(TTypeDeclarationSyntax node, ISyntaxFacts syntaxFacts, CancellationToken cancellationToken)
{
using var _ = ArrayBuilder<SnippetPlaceholder>.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<bool> AreAccessibilityModifiersRequiredAsync(Document document, CancellationToken cancellationToken)
Expand Down

0 comments on commit 4ddd025

Please sign in to comment.