Skip to content

Commit 1cdbc3a

Browse files
Make codepaths sync that don't need to be async (#76490)
2 parents a4324e6 + 9b73421 commit 1cdbc3a

File tree

32 files changed

+257
-275
lines changed

32 files changed

+257
-275
lines changed

src/Analyzers/Core/CodeFixes/GenerateConstructor/AbstractGenerateConstructorService.State.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ private async Task<bool> TryInitializeAsync(
9292
{
9393
if (_service.IsConstructorInitializerGeneration(_document, node, cancellationToken))
9494
{
95-
if (!await TryInitializeConstructorInitializerGenerationAsync(node, cancellationToken).ConfigureAwait(false))
95+
if (!TryInitializeConstructorInitializerGeneration(node, cancellationToken))
9696
return false;
9797
}
9898
else if (_service.IsSimpleNameGeneration(_document, node, cancellationToken))
9999
{
100-
if (!await TryInitializeSimpleNameGenerationAsync(node, cancellationToken).ConfigureAwait(false))
100+
if (!TryInitializeSimpleNameGeneration(node, cancellationToken))
101101
return false;
102102
}
103103
else if (_service.IsImplicitObjectCreation(_document, node, cancellationToken))
104104
{
105-
if (!await TryInitializeImplicitObjectCreationAsync(node, cancellationToken).ConfigureAwait(false))
105+
if (!TryInitializeImplicitObjectCreation(node, cancellationToken))
106106
return false;
107107
}
108108
else
@@ -298,7 +298,7 @@ private static ITypeSymbol FixType(ITypeSymbol typeSymbol, SemanticModel semanti
298298
.RemoveUnnamedErrorTypes(compilation);
299299
}
300300

301-
private async Task<bool> TryInitializeConstructorInitializerGenerationAsync(
301+
private bool TryInitializeConstructorInitializerGeneration(
302302
SyntaxNode constructorInitializer, CancellationToken cancellationToken)
303303
{
304304
if (_service.TryInitializeConstructorInitializerGeneration(
@@ -311,13 +311,13 @@ private async Task<bool> TryInitializeConstructorInitializerGenerationAsync(
311311

312312
var semanticInfo = _document.SemanticModel.GetSymbolInfo(constructorInitializer, cancellationToken);
313313
if (semanticInfo.Symbol == null)
314-
return await TryDetermineTypeToGenerateInAsync(typeToGenerateIn, cancellationToken).ConfigureAwait(false);
314+
return TryDetermineTypeToGenerateIn(typeToGenerateIn, cancellationToken);
315315
}
316316

317317
return false;
318318
}
319319

320-
private async Task<bool> TryInitializeImplicitObjectCreationAsync(SyntaxNode implicitObjectCreation, CancellationToken cancellationToken)
320+
private bool TryInitializeImplicitObjectCreation(SyntaxNode implicitObjectCreation, CancellationToken cancellationToken)
321321
{
322322
if (_service.TryInitializeImplicitObjectCreation(
323323
_document, implicitObjectCreation, cancellationToken,
@@ -328,13 +328,13 @@ private async Task<bool> TryInitializeImplicitObjectCreationAsync(SyntaxNode imp
328328

329329
var semanticInfo = _document.SemanticModel.GetSymbolInfo(implicitObjectCreation, cancellationToken);
330330
if (semanticInfo.Symbol == null)
331-
return await TryDetermineTypeToGenerateInAsync(typeToGenerateIn, cancellationToken).ConfigureAwait(false);
331+
return TryDetermineTypeToGenerateIn(typeToGenerateIn, cancellationToken);
332332
}
333333

334334
return false;
335335
}
336336

337-
private async Task<bool> TryInitializeSimpleNameGenerationAsync(
337+
private bool TryInitializeSimpleNameGeneration(
338338
SyntaxNode simpleName,
339339
CancellationToken cancellationToken)
340340
{
@@ -361,7 +361,7 @@ private async Task<bool> TryInitializeSimpleNameGenerationAsync(
361361

362362
cancellationToken.ThrowIfCancellationRequested();
363363

364-
return await TryDetermineTypeToGenerateInAsync(typeToGenerateIn, cancellationToken).ConfigureAwait(false);
364+
return TryDetermineTypeToGenerateIn(typeToGenerateIn, cancellationToken);
365365
}
366366

367367
private static bool IsValidAttributeParameterType(ITypeSymbol type)
@@ -400,10 +400,10 @@ private static bool IsValidAttributeParameterType(ITypeSymbol type)
400400
}
401401
}
402402

403-
private async Task<bool> TryDetermineTypeToGenerateInAsync(
403+
private bool TryDetermineTypeToGenerateIn(
404404
INamedTypeSymbol original, CancellationToken cancellationToken)
405405
{
406-
var definition = await SymbolFinder.FindSourceDefinitionAsync(original, _document.Project.Solution, cancellationToken).ConfigureAwait(false);
406+
var definition = SymbolFinderInternal.FindSourceDefinition(original, _document.Project.Solution, cancellationToken);
407407
TypeToGenerateIn = definition as INamedTypeSymbol;
408408

409409
return TypeToGenerateIn?.TypeKind is (TypeKind?)TypeKind.Class or (TypeKind?)TypeKind.Struct;

src/Analyzers/Core/CodeFixes/GenerateEnumMember/AbstractGenerateEnumMemberService.State.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System.Linq;
66
using System.Threading;
7-
using System.Threading.Tasks;
87
using Microsoft.CodeAnalysis.CodeGeneration;
98
using Microsoft.CodeAnalysis.FindSymbols;
109
using Microsoft.CodeAnalysis.LanguageService;
@@ -24,20 +23,17 @@ private sealed partial class State
2423
public TSimpleNameSyntax SimpleName { get; private set; } = null!;
2524
public TExpressionSyntax SimpleNameOrMemberAccessExpression { get; private set; } = null!;
2625

27-
public static async Task<State?> GenerateAsync(
26+
public static State? Generate(
2827
TService service,
2928
SemanticDocument document,
3029
SyntaxNode node,
3130
CancellationToken cancellationToken)
3231
{
3332
var state = new State();
34-
if (!await state.TryInitializeAsync(service, document, node, cancellationToken).ConfigureAwait(false))
35-
return null;
36-
37-
return state;
33+
return state.TryInitialize(service, document, node, cancellationToken) ? state : null;
3834
}
3935

40-
private async Task<bool> TryInitializeAsync(
36+
private bool TryInitialize(
4137
TService service,
4238
SemanticDocument document,
4339
SyntaxNode node,
@@ -67,7 +63,7 @@ private async Task<bool> TryInitializeAsync(
6763
}
6864

6965
cancellationToken.ThrowIfCancellationRequested();
70-
var sourceType = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
66+
var sourceType = SymbolFinderInternal.FindSourceDefinition(TypeToGenerateIn, document.Project.Solution, cancellationToken) as INamedTypeSymbol;
7167
if (!ValidateTypeToGenerateIn(sourceType, true, EnumType))
7268
return false;
7369

src/Analyzers/Core/CodeFixes/GenerateEnumMember/AbstractGenerateEnumMemberService.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Microsoft.CodeAnalysis.CodeActions;
11-
using Microsoft.CodeAnalysis.CodeGeneration;
1211
using Microsoft.CodeAnalysis.Internal.Log;
1312

1413
namespace Microsoft.CodeAnalysis.GenerateMember.GenerateEnumMember;
@@ -19,10 +18,6 @@ internal abstract partial class AbstractGenerateEnumMemberService<TService, TSim
1918
where TSimpleNameSyntax : TExpressionSyntax
2019
where TExpressionSyntax : SyntaxNode
2120
{
22-
protected AbstractGenerateEnumMemberService()
23-
{
24-
}
25-
2621
protected abstract bool IsIdentifierNameGeneration(SyntaxNode node);
2722
protected abstract bool TryInitializeIdentifierNameState(SemanticDocument document, TSimpleNameSyntax identifierName, CancellationToken cancellationToken, out SyntaxToken identifierToken, out TExpressionSyntax simpleNameOrMemberAccessExpression);
2823

@@ -31,7 +26,7 @@ public async Task<ImmutableArray<CodeAction>> GenerateEnumMemberAsync(Document d
3126
using (Logger.LogBlock(FunctionId.Refactoring_GenerateMember_GenerateEnumMember, cancellationToken))
3227
{
3328
var semanticDocument = await SemanticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);
34-
var state = await State.GenerateAsync((TService)this, semanticDocument, node, cancellationToken).ConfigureAwait(false);
29+
var state = State.Generate((TService)this, semanticDocument, node, cancellationToken);
3530
if (state == null)
3631
{
3732
return [];

src/Analyzers/Core/CodeFixes/GenerateParameterizedMember/AbstractGenerateParameterizedMemberService.State.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Location Location
5858
protected async Task<bool> TryFinishInitializingStateAsync(TService service, SemanticDocument document, CancellationToken cancellationToken)
5959
{
6060
cancellationToken.ThrowIfCancellationRequested();
61-
TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(TypeToGenerateIn, document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
61+
TypeToGenerateIn = SymbolFinderInternal.FindSourceDefinition(TypeToGenerateIn, document.Project.Solution, cancellationToken) as INamedTypeSymbol;
6262
if (TypeToGenerateIn.IsErrorType())
6363
{
6464
return false;

src/Analyzers/Core/CodeFixes/GenerateVariable/AbstractGenerateVariableService.State.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,14 @@ private State(
7070
_document = document;
7171
}
7272

73-
public static async Task<State> GenerateAsync(
73+
public static State Generate(
7474
TService service,
7575
SemanticDocument document,
7676
SyntaxNode interfaceNode,
7777
CancellationToken cancellationToken)
7878
{
7979
var state = new State(service, document);
80-
if (!await state.TryInitializeAsync(interfaceNode, cancellationToken).ConfigureAwait(false))
81-
{
82-
return null;
83-
}
84-
85-
return state;
80+
return state.TryInitialize(interfaceNode, cancellationToken) ? state : null;
8681
}
8782

8883
public Accessibility DetermineMaximalAccessibility()
@@ -108,9 +103,8 @@ public Accessibility DetermineMaximalAccessibility()
108103
return accessibility;
109104
}
110105

111-
private async Task<bool> TryInitializeAsync(
112-
SyntaxNode node,
113-
CancellationToken cancellationToken)
106+
private bool TryInitialize(
107+
SyntaxNode node, CancellationToken cancellationToken)
114108
{
115109
if (_service.IsIdentifierNameGeneration(node))
116110
{
@@ -155,8 +149,8 @@ private async Task<bool> TryInitializeAsync(
155149
return false;
156150
}
157151

158-
TypeToGenerateIn = await SymbolFinder.FindSourceDefinitionAsync(
159-
TypeToGenerateIn, _document.Project.Solution, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
152+
TypeToGenerateIn = SymbolFinderInternal.FindSourceDefinition(
153+
TypeToGenerateIn, _document.Project.Solution, cancellationToken) as INamedTypeSymbol;
160154

161155
if (!ValidateTypeToGenerateIn(TypeToGenerateIn, IsStatic, ClassInterfaceModuleStructTypes))
162156
{

src/Analyzers/Core/CodeFixes/GenerateVariable/AbstractGenerateVariableService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task<ImmutableArray<CodeAction>> GenerateVariableAsync(
3838
{
3939
var semanticDocument = await SemanticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);
4040

41-
var state = await State.GenerateAsync((TService)this, semanticDocument, node, cancellationToken).ConfigureAwait(false);
41+
var state = State.Generate((TService)this, semanticDocument, node, cancellationToken);
4242
if (state == null)
4343
return [];
4444

src/Analyzers/Core/CodeFixes/UnsealClass/AbstractUnsealClassCodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3939
if (semanticModel.GetSymbolInfo(node, cancellationToken).Symbol is INamedTypeSymbol type &&
4040
type.TypeKind == TypeKind.Class && type.IsSealed && !type.IsStatic)
4141
{
42-
var definition = await SymbolFinder.FindSourceDefinitionAsync(
43-
type, document.Project.Solution, cancellationToken).ConfigureAwait(false);
42+
var definition = SymbolFinderInternal.FindSourceDefinition(
43+
type, document.Project.Solution, cancellationToken);
4444
if (definition is not null && definition.DeclaringSyntaxReferences.Length > 0)
4545
{
4646
var title = string.Format(TitleFormat, type.Name);

src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public async Task<IEnumerable<IPeekableItem>> GetPeekableItemsAsync(
6060
throw new ArgumentNullException(nameof(peekResultFactory));
6161

6262
var solution = project.Solution;
63-
symbol = await SymbolFinder.FindSourceDefinitionAsync(symbol, solution, cancellationToken).ConfigureAwait(false) ?? symbol;
64-
symbol = await GoToDefinitionFeatureHelpers.TryGetPreferredSymbolAsync(solution, symbol, cancellationToken).ConfigureAwait(false);
63+
symbol = SymbolFinder.FindSourceDefinition(symbol, solution, cancellationToken) ?? symbol;
64+
symbol = GoToDefinitionFeatureHelpers.TryGetPreferredSymbol(solution, symbol, cancellationToken);
6565
if (symbol is null)
66-
return ImmutableArray<IPeekableItem>.Empty;
66+
return [];
6767

6868
// if we mapped the symbol, then get the new project it is contained in.
6969
var originatingProject = solution.GetProject(symbol.ContainingAssembly, cancellationToken);

src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.TrackingSession.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private async Task<TriggerIdentifierKind> DetermineIfRenamableIdentifierAsync(Sn
197197
// This is a reference from a nameof expression. Allow the rename but set the RenameOverloads option
198198
ForceRenameOverloads = true;
199199

200-
return await DetermineIfRenamableSymbolsAsync(renameSymbolInfo.Symbols, document).ConfigureAwait(false);
200+
return DetermineIfRenamableSymbols(renameSymbolInfo.Symbols, document);
201201
}
202202
else
203203
{
@@ -208,20 +208,20 @@ private async Task<TriggerIdentifierKind> DetermineIfRenamableIdentifierAsync(Sn
208208
return TriggerIdentifierKind.NotRenamable;
209209
}
210210

211-
return await DetermineIfRenamableSymbolAsync(renameSymbolInfo.Symbols.Single(), document, token).ConfigureAwait(false);
211+
return DetermineIfRenamableSymbol(renameSymbolInfo.Symbols.Single(), document, token);
212212
}
213213
}
214214
}
215215

216216
return TriggerIdentifierKind.NotRenamable;
217217
}
218218

219-
private async Task<TriggerIdentifierKind> DetermineIfRenamableSymbolsAsync(IEnumerable<ISymbol> symbols, Document document)
219+
private TriggerIdentifierKind DetermineIfRenamableSymbols(IEnumerable<ISymbol> symbols, Document document)
220220
{
221221
foreach (var symbol in symbols)
222222
{
223223
// Get the source symbol if possible
224-
var sourceSymbol = await SymbolFinder.FindSourceDefinitionAsync(symbol, document.Project.Solution, _cancellationToken).ConfigureAwait(false) ?? symbol;
224+
var sourceSymbol = SymbolFinder.FindSourceDefinition(symbol, document.Project.Solution, _cancellationToken) ?? symbol;
225225

226226
if (!sourceSymbol.IsFromSource())
227227
{
@@ -232,10 +232,10 @@ private async Task<TriggerIdentifierKind> DetermineIfRenamableSymbolsAsync(IEnum
232232
return TriggerIdentifierKind.RenamableReference;
233233
}
234234

235-
private async Task<TriggerIdentifierKind> DetermineIfRenamableSymbolAsync(ISymbol symbol, Document document, SyntaxToken token)
235+
private TriggerIdentifierKind DetermineIfRenamableSymbol(ISymbol symbol, Document document, SyntaxToken token)
236236
{
237237
// Get the source symbol if possible
238-
var sourceSymbol = await SymbolFinder.FindSourceDefinitionAsync(symbol, document.Project.Solution, _cancellationToken).ConfigureAwait(false) ?? symbol;
238+
var sourceSymbol = SymbolFinder.FindSourceDefinition(symbol, document.Project.Solution, _cancellationToken) ?? symbol;
239239

240240
if (sourceSymbol.Kind == SymbolKind.Field &&
241241
((IFieldSymbol)sourceSymbol).ContainingType.IsTupleType &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ public override async Task<ImmutableArray<ISymbol>> DetermineCascadedSymbolsFrom
871871

872872
if (convertedType != null)
873873
{
874-
convertedType = await SymbolFinder.FindSourceDefinitionAsync(convertedType, document.Project.Solution, cancellationToken).ConfigureAwait(false)
874+
convertedType = SymbolFinder.FindSourceDefinition(convertedType, document.Project.Solution, cancellationToken)
875875
?? convertedType;
876876
}
877877

0 commit comments

Comments
 (0)