Skip to content

Commit 85b743f

Browse files
Remove blocking async calls from sig-change
1 parent 4234893 commit 85b743f

File tree

4 files changed

+118
-112
lines changed

4 files changed

+118
-112
lines changed

src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,13 @@ private static bool InSymbolHeader(SyntaxNode matchingNode, int position)
286286
}
287287
}
288288

289-
public override async Task<SyntaxNode> ChangeSignatureAsync(
290-
Document document,
289+
public override SyntaxNode ChangeSignature(
290+
SemanticDocument document,
291291
ISymbol declarationSymbol,
292292
SyntaxNode potentiallyUpdatedNode,
293293
SyntaxNode originalNode,
294294
SignatureChange signaturePermutation,
295+
LineFormattingOptions lineFormattingOptions,
295296
CancellationToken cancellationToken)
296297
{
297298
var updatedNode = potentiallyUpdatedNode as CSharpSyntaxNode;
@@ -307,7 +308,8 @@ or SyntaxKind.RecordDeclaration
307308
or SyntaxKind.StructDeclaration
308309
or SyntaxKind.ClassDeclaration)
309310
{
310-
var updatedLeadingTrivia = await UpdateParamTagsInLeadingTriviaAsync(document, updatedNode, declarationSymbol, signaturePermutation, cancellationToken).ConfigureAwait(false);
311+
var updatedLeadingTrivia = UpdateParamTagsInLeadingTrivia(
312+
document.Document, updatedNode, declarationSymbol, signaturePermutation, lineFormattingOptions);
311313
if (updatedLeadingTrivia != default && !updatedLeadingTrivia.IsEmpty)
312314
{
313315
updatedNode = updatedNode.WithLeadingTrivia(updatedLeadingTrivia);
@@ -318,37 +320,37 @@ or SyntaxKind.StructDeclaration
318320
if (updatedNode is MethodDeclarationSyntax method)
319321
{
320322
var updatedParameters = UpdateDeclaration(method.ParameterList.Parameters, signaturePermutation, CreateNewParameterSyntax);
321-
return method.WithParameterList(method.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
323+
return method.WithParameterList(method.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation));
322324
}
323325

324326
if (updatedNode is TypeDeclarationSyntax { ParameterList: not null } typeWithParameters)
325327
{
326328
var updatedParameters = UpdateDeclaration(typeWithParameters.ParameterList.Parameters, signaturePermutation, CreateNewParameterSyntax);
327-
return typeWithParameters.WithParameterList(typeWithParameters.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
329+
return typeWithParameters.WithParameterList(typeWithParameters.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation));
328330
}
329331

330332
if (updatedNode is LocalFunctionStatementSyntax localFunction)
331333
{
332334
var updatedParameters = UpdateDeclaration(localFunction.ParameterList.Parameters, signaturePermutation, CreateNewParameterSyntax);
333-
return localFunction.WithParameterList(localFunction.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
335+
return localFunction.WithParameterList(localFunction.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation));
334336
}
335337

336338
if (updatedNode is ConstructorDeclarationSyntax constructor)
337339
{
338340
var updatedParameters = UpdateDeclaration(constructor.ParameterList.Parameters, signaturePermutation, CreateNewParameterSyntax);
339-
return constructor.WithParameterList(constructor.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
341+
return constructor.WithParameterList(constructor.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation));
340342
}
341343

342344
if (updatedNode is IndexerDeclarationSyntax indexer)
343345
{
344346
var updatedParameters = UpdateDeclaration(indexer.ParameterList.Parameters, signaturePermutation, CreateNewParameterSyntax);
345-
return indexer.WithParameterList(indexer.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
347+
return indexer.WithParameterList(indexer.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation));
346348
}
347349

348350
if (updatedNode is DelegateDeclarationSyntax delegateDeclaration)
349351
{
350352
var updatedParameters = UpdateDeclaration(delegateDeclaration.ParameterList.Parameters, signaturePermutation, CreateNewParameterSyntax);
351-
return delegateDeclaration.WithParameterList(delegateDeclaration.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
353+
return delegateDeclaration.WithParameterList(delegateDeclaration.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation));
352354
}
353355

354356
if (updatedNode is AnonymousMethodExpressionSyntax anonymousMethod)
@@ -360,7 +362,7 @@ or SyntaxKind.StructDeclaration
360362
}
361363

362364
var updatedParameters = UpdateDeclaration(anonymousMethod.ParameterList.Parameters, signaturePermutation, CreateNewParameterSyntax);
363-
return anonymousMethod.WithParameterList(anonymousMethod.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
365+
return anonymousMethod.WithParameterList(anonymousMethod.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation));
364366
}
365367

366368
if (updatedNode is SimpleLambdaExpressionSyntax lambda)
@@ -411,23 +413,23 @@ or SyntaxKind.StructDeclaration
411413
return nameMemberCref.WithParameters(newCrefParameterList);
412414
}
413415

414-
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
416+
var semanticModel = document.SemanticModel;
415417

416418
// Update reference site argument lists
417419
if (updatedNode is InvocationExpressionSyntax invocation)
418420
{
419421
var symbolInfo = semanticModel.GetSymbolInfo((InvocationExpressionSyntax)originalNode, cancellationToken);
420422

421423
return invocation.WithArgumentList(
422-
await UpdateArgumentListAsync(
424+
UpdateArgumentList(
425+
document,
423426
declarationSymbol,
424427
signaturePermutation,
425428
invocation.ArgumentList,
426429
symbolInfo.Symbol is IMethodSymbol { MethodKind: MethodKind.ReducedExtension },
427430
IsParamsArrayExpanded(semanticModel, invocation, symbolInfo, cancellationToken),
428-
document,
429431
originalNode.SpanStart,
430-
cancellationToken).ConfigureAwait(false));
432+
cancellationToken));
431433
}
432434

433435
// Handles both ObjectCreationExpressionSyntax and ImplicitObjectCreationExpressionSyntax
@@ -441,47 +443,47 @@ await UpdateArgumentListAsync(
441443
var symbolInfo = semanticModel.GetSymbolInfo((BaseObjectCreationExpressionSyntax)originalNode, cancellationToken);
442444

443445
return objCreation.WithArgumentList(
444-
await UpdateArgumentListAsync(
446+
UpdateArgumentList(
447+
document,
445448
declarationSymbol,
446449
signaturePermutation,
447450
objCreation.ArgumentList,
448451
isReducedExtensionMethod: false,
449452
IsParamsArrayExpanded(semanticModel, objCreation, symbolInfo, cancellationToken),
450-
document,
451453
originalNode.SpanStart,
452-
cancellationToken).ConfigureAwait(false));
454+
cancellationToken));
453455
}
454456

455457
if (updatedNode is ConstructorInitializerSyntax constructorInit)
456458
{
457459
var symbolInfo = semanticModel.GetSymbolInfo((ConstructorInitializerSyntax)originalNode, cancellationToken);
458460

459461
return constructorInit.WithArgumentList(
460-
await UpdateArgumentListAsync(
462+
UpdateArgumentList(
463+
document,
461464
declarationSymbol,
462465
signaturePermutation,
463466
constructorInit.ArgumentList,
464467
isReducedExtensionMethod: false,
465468
IsParamsArrayExpanded(semanticModel, constructorInit, symbolInfo, cancellationToken),
466-
document,
467469
originalNode.SpanStart,
468-
cancellationToken).ConfigureAwait(false));
470+
cancellationToken));
469471
}
470472

471473
if (updatedNode is ElementAccessExpressionSyntax elementAccess)
472474
{
473475
var symbolInfo = semanticModel.GetSymbolInfo((ElementAccessExpressionSyntax)originalNode, cancellationToken);
474476

475477
return elementAccess.WithArgumentList(
476-
await UpdateArgumentListAsync(
478+
UpdateArgumentList(
479+
document,
477480
declarationSymbol,
478481
signaturePermutation,
479482
elementAccess.ArgumentList,
480483
isReducedExtensionMethod: false,
481484
IsParamsArrayExpanded(semanticModel, elementAccess, symbolInfo, cancellationToken),
482-
document,
483485
originalNode.SpanStart,
484-
cancellationToken).ConfigureAwait(false));
486+
cancellationToken));
485487
}
486488

487489
if (updatedNode is AttributeSyntax attribute)
@@ -494,28 +496,28 @@ await UpdateArgumentListAsync(
494496
}
495497

496498
return attribute.WithArgumentList(
497-
await UpdateAttributeArgumentListAsync(
499+
UpdateAttributeArgumentList(
500+
document,
498501
declarationSymbol,
499502
signaturePermutation,
500503
attribute.ArgumentList,
501504
isReducedExtensionMethod: false,
502505
IsParamsArrayExpanded(semanticModel, attribute, symbolInfo, cancellationToken),
503-
document,
504506
originalNode.SpanStart,
505-
cancellationToken).ConfigureAwait(false));
507+
cancellationToken));
506508
}
507509

508510
Debug.Assert(false, "Unknown reference location");
509511
return null;
510512
}
511513

512-
private async Task<T> UpdateArgumentListAsync<T>(
514+
private T UpdateArgumentList<T>(
515+
SemanticDocument document,
513516
ISymbol declarationSymbol,
514517
SignatureChange signaturePermutation,
515518
T argumentList,
516519
bool isReducedExtensionMethod,
517520
bool isParamsArrayExpanded,
518-
Document document,
519521
int position,
520522
CancellationToken cancellationToken) where T : BaseArgumentListSyntax
521523
{
@@ -529,30 +531,30 @@ private async Task<T> UpdateArgumentListAsync<T>(
529531

530532
// Adds new arguments into the updated list
531533
// e.g. P(c, a) ==> P(x, c, a, y)
532-
newArguments = await AddNewArgumentsToListAsync(
534+
newArguments = AddNewArgumentsToList(
535+
document,
533536
declarationSymbol,
534537
newArguments,
535538
argumentList.Arguments,
536539
signaturePermutation,
537540
isReducedExtensionMethod,
538541
isParamsArrayExpanded,
539542
generateAttributeArguments: false,
540-
document,
541543
position,
542-
cancellationToken).ConfigureAwait(false);
544+
cancellationToken);
543545

544546
return (T)argumentList
545547
.WithArguments(newArguments)
546-
.WithAdditionalAnnotations(changeSignatureFormattingAnnotation);
548+
.WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation);
547549
}
548550

549-
private async Task<AttributeArgumentListSyntax> UpdateAttributeArgumentListAsync(
551+
private AttributeArgumentListSyntax UpdateAttributeArgumentList(
552+
SemanticDocument document,
550553
ISymbol declarationSymbol,
551554
SignatureChange signaturePermutation,
552555
AttributeArgumentListSyntax argumentList,
553556
bool isReducedExtensionMethod,
554557
bool isParamsArrayExpanded,
555-
Document document,
556558
int position,
557559
CancellationToken cancellationToken)
558560
{
@@ -561,21 +563,21 @@ private async Task<AttributeArgumentListSyntax> UpdateAttributeArgumentListAsync
561563
argumentList.Arguments,
562564
signaturePermutation.WithoutAddedParameters());
563565

564-
newArguments = await AddNewArgumentsToListAsync(
566+
newArguments = AddNewArgumentsToList(
567+
document,
565568
declarationSymbol,
566569
newArguments,
567570
argumentList.Arguments,
568571
signaturePermutation,
569572
isReducedExtensionMethod,
570573
isParamsArrayExpanded,
571574
generateAttributeArguments: true,
572-
document,
573575
position,
574-
cancellationToken).ConfigureAwait(false);
576+
cancellationToken);
575577

576578
return argumentList
577579
.WithArguments(newArguments)
578-
.WithAdditionalAnnotations(changeSignatureFormattingAnnotation);
580+
.WithAdditionalAnnotations(ChangeSignatureFormattingAnnotation);
579581
}
580582

581583
private static bool IsParamsArrayExpanded(SemanticModel semanticModel, SyntaxNode node, SymbolInfo symbolInfo, CancellationToken cancellationToken)
@@ -687,24 +689,22 @@ protected override T TransferLeadingWhitespaceTrivia<T>(T newArgument, SyntaxNod
687689
return newArgument;
688690
}
689691

690-
private async Task<SeparatedSyntaxList<TArgumentSyntax>> AddNewArgumentsToListAsync<TArgumentSyntax>(
692+
private SeparatedSyntaxList<TArgumentSyntax> AddNewArgumentsToList<TArgumentSyntax>(
693+
SemanticDocument document,
691694
ISymbol declarationSymbol,
692695
SeparatedSyntaxList<TArgumentSyntax> newArguments,
693696
SeparatedSyntaxList<TArgumentSyntax> originalArguments,
694697
SignatureChange signaturePermutation,
695698
bool isReducedExtensionMethod,
696699
bool isParamsArrayExpanded,
697700
bool generateAttributeArguments,
698-
Document document,
699701
int position,
700702
CancellationToken cancellationToken)
701703
where TArgumentSyntax : SyntaxNode
702704
{
703-
var newArgumentList = await AddNewArgumentsToListAsync(
704-
declarationSymbol, newArguments,
705-
signaturePermutation, isReducedExtensionMethod,
706-
isParamsArrayExpanded, generateAttributeArguments,
707-
document, position, cancellationToken).ConfigureAwait(false);
705+
var newArgumentList = AddNewArgumentsToList(
706+
document, declarationSymbol, newArguments, signaturePermutation,
707+
isReducedExtensionMethod, isParamsArrayExpanded, generateAttributeArguments, position, cancellationToken);
708708

709709
return SeparatedList(
710710
TransferLeadingWhitespaceTrivia(newArgumentList, originalArguments),
@@ -765,13 +765,15 @@ private ImmutableArray<T> TransferLeadingWhitespaceTrivia<T, U>(IEnumerable<T> n
765765
return result.ToImmutableAndClear();
766766
}
767767

768-
private async ValueTask<ImmutableArray<SyntaxTrivia>> UpdateParamTagsInLeadingTriviaAsync(
769-
Document document, CSharpSyntaxNode node, ISymbol declarationSymbol, SignatureChange updatedSignature, CancellationToken cancellationToken)
768+
private ImmutableArray<SyntaxTrivia> UpdateParamTagsInLeadingTrivia(
769+
Document document,
770+
CSharpSyntaxNode node,
771+
ISymbol declarationSymbol,
772+
SignatureChange updatedSignature,
773+
LineFormattingOptions lineFormattingOptions)
770774
{
771775
if (!node.HasLeadingTrivia)
772-
{
773776
return [];
774-
}
775777

776778
var paramNodes = node
777779
.DescendantNodes(descendIntoTrivia: true)
@@ -780,12 +782,9 @@ private async ValueTask<ImmutableArray<SyntaxTrivia>> UpdateParamTagsInLeadingTr
780782

781783
var permutedParamNodes = VerifyAndPermuteParamNodes(paramNodes, declarationSymbol, updatedSignature);
782784
if (permutedParamNodes.IsEmpty)
783-
{
784785
return [];
785-
}
786786

787-
var options = await document.GetLineFormattingOptionsAsync(cancellationToken).ConfigureAwait(false);
788-
return GetPermutedDocCommentTrivia(node, permutedParamNodes, document.Project.Services, options);
787+
return GetPermutedDocCommentTrivia(node, permutedParamNodes, document.Project.Services, lineFormattingOptions);
789788
}
790789

791790
private ImmutableArray<SyntaxNode> VerifyAndPermuteParamNodes(IEnumerable<XmlElementSyntax> paramNodes, ISymbol declarationSymbol, SignatureChange updatedSignature)

0 commit comments

Comments
 (0)