Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Workspaces/Core/Portable/CodeActions/CodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,8 @@ public static NoChangeAction Create(
CodeActionPriority priority = CodeActionPriority.Default)
=> new(title, equivalenceKey, priority, createdFromFactoryMethod: true);

protected sealed override Task<Solution?> GetChangedSolutionAsync(IProgress<CodeAnalysisProgress> progress, CancellationToken cancellationToken)
=> SpecializedTasks.Null<Solution>();
protected sealed override async Task<Solution?> GetChangedSolutionAsync(IProgress<CodeAnalysisProgress> progress, CancellationToken cancellationToken)
=> null;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ private protected sealed override async Task<ImmutableArray<CodeActionOperation>
/// </summary>
/// <param name="options">An object instance returned from a call to <see cref="GetOptions(CancellationToken)"/>.</param>
/// <param name="cancellationToken">A cancellation token.</param>
protected virtual Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(object options, CancellationToken cancellationToken)
=> SpecializedTasks.EmptyEnumerable<CodeActionOperation>();
protected virtual async Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(object options, CancellationToken cancellationToken)
=> [];

/// <summary>
/// Override this method to compute the operations that implement this <see cref="CodeAction"/>. Prefer
Expand All @@ -74,6 +74,6 @@ protected virtual Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(
protected virtual Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(object options, IProgress<CodeAnalysisProgress> progress, CancellationToken cancellationToken)
=> ComputeOperationsAsync(options, cancellationToken);

protected override Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(CancellationToken cancellationToken)
=> SpecializedTasks.EmptyEnumerable<CodeActionOperation>();
protected override async Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(CancellationToken cancellationToken)
=> [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public sealed class ApplyChangesOperation(Solution changedSolution) : CodeAction
public override void Apply(Workspace workspace, CancellationToken cancellationToken)
=> workspace.TryApplyChanges(ChangedSolution, CodeAnalysisProgress.None);

internal sealed override Task<bool> TryApplyAsync(Workspace workspace, Solution originalSolution, IProgress<CodeAnalysisProgress> progressTracker, CancellationToken cancellationToken)
=> Task.FromResult(ApplyOrMergeChanges(workspace, originalSolution, ChangedSolution, progressTracker, cancellationToken));
internal sealed override async Task<bool> TryApplyAsync(Workspace workspace, Solution originalSolution, IProgress<CodeAnalysisProgress> progressTracker, CancellationToken cancellationToken)
=> ApplyOrMergeChanges(workspace, originalSolution, ChangedSolution, progressTracker, cancellationToken);

internal static bool ApplyOrMergeChanges(
Workspace workspace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public virtual void Apply(Workspace workspace, CancellationToken cancellationTok
/// Called by the host environment to apply the effect of the operation.
/// This method is guaranteed to be called on the UI thread.
/// </summary>
internal virtual Task<bool> TryApplyAsync(Workspace workspace, Solution originalSolution, IProgress<CodeAnalysisProgress> progressTracker, CancellationToken cancellationToken)
internal virtual async Task<bool> TryApplyAsync(Workspace workspace, Solution originalSolution, IProgress<CodeAnalysisProgress> progressTracker, CancellationToken cancellationToken)
{
// It is a requirement that this method be called on the UI thread. So it's safe for us to call
// into .Apply without any threading operations here.
this.Apply(workspace, cancellationToken);
return SpecializedTasks.True;
return true;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ internal sealed class SimplificationCodeCleanupProvider : ICodeCleanupProvider
public Task<Document> CleanupAsync(Document document, ImmutableArray<TextSpan> spans, CodeCleanupOptions options, CancellationToken cancellationToken)
=> Simplifier.ReduceAsync(document, spans, options.SimplifierOptions, cancellationToken);

public Task<SyntaxNode> CleanupAsync(SyntaxNode root, ImmutableArray<TextSpan> spans, SyntaxFormattingOptions options, SolutionServices services, CancellationToken cancellationToken)
public async Task<SyntaxNode> CleanupAsync(SyntaxNode root, ImmutableArray<TextSpan> spans, SyntaxFormattingOptions options, SolutionServices services, CancellationToken cancellationToken)
{
// Simplifier doesn't work without semantic information
return Task.FromResult(root);
return root;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public FixMultipleDiagnosticProvider(ImmutableDictionary<Project, ImmutableArray
DocumentDiagnosticsMap = ImmutableDictionary<Document, ImmutableArray<Diagnostic>>.Empty;
}

public override Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(Project project, CancellationToken cancellationToken)
public override async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(Project project, CancellationToken cancellationToken)
{
var allDiagnosticsBuilder = ArrayBuilder<Diagnostic>.GetInstance();
ImmutableArray<Diagnostic> diagnostics;
Expand All @@ -53,27 +53,27 @@ public override Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(Project pro
allDiagnosticsBuilder.AddRange(diagnostics);
}

return Task.FromResult<IEnumerable<Diagnostic>>(allDiagnosticsBuilder.ToImmutableAndFree());
return allDiagnosticsBuilder.ToImmutableAndFree();
}

public override Task<IEnumerable<Diagnostic>> GetDocumentDiagnosticsAsync(Document document, CancellationToken cancellationToken)
public override async Task<IEnumerable<Diagnostic>> GetDocumentDiagnosticsAsync(Document document, CancellationToken cancellationToken)
{
if (DocumentDiagnosticsMap.TryGetValue(document, out var diagnostics))
{
return Task.FromResult<IEnumerable<Diagnostic>>(diagnostics);
return diagnostics;
}

return SpecializedTasks.EmptyEnumerable<Diagnostic>();
return [];
}

public override Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(Project project, CancellationToken cancellationToken)
public override async Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(Project project, CancellationToken cancellationToken)
{
if (ProjectDiagnosticsMap.TryGetValue(project, out var diagnostics))
{
return Task.FromResult<IEnumerable<Diagnostic>>(diagnostics);
return diagnostics;
}

return SpecializedTasks.EmptyEnumerable<Diagnostic>();
return [];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ private NoOpFixAllProvider()
{
}

public override Task<CodeAction?> GetFixAsync(FixAllContext fixAllContext)
=> Task.FromResult<CodeAction?>(null);
public override async Task<CodeAction?> GetFixAsync(FixAllContext fixAllContext)
=> null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FixAllScope.Document or FixAllScope.ContainingMember or FixAllScope.ContainingTy
return null;

return CodeAction.Create(
title, (_, _) => Task.FromResult(solution), equivalenceKey: null, CodeActionPriority.Default, fixAllContext.State.FixAllProvider.Cleanup);
title, async (_, _) => solution, equivalenceKey: null, CodeActionPriority.Default, fixAllContext.State.FixAllProvider.Cleanup);
}

private static Task<Solution?> GetDocumentFixesAsync<TFixAllContext>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ internal abstract class DocumentDiagnosticAnalyzer : DiagnosticAnalyzer
{
public const int DefaultPriority = 50;

public virtual Task<ImmutableArray<Diagnostic>> AnalyzeSyntaxAsync(TextDocument textDocument, SyntaxTree? tree, CancellationToken cancellationToken)
=> SpecializedTasks.EmptyImmutableArray<Diagnostic>();
public virtual async Task<ImmutableArray<Diagnostic>> AnalyzeSyntaxAsync(TextDocument textDocument, SyntaxTree? tree, CancellationToken cancellationToken)
=> [];

public virtual Task<ImmutableArray<Diagnostic>> AnalyzeSemanticsAsync(TextDocument textDocument, SyntaxTree? tree, CancellationToken cancellationToken)
=> SpecializedTasks.EmptyImmutableArray<Diagnostic>();
public virtual async Task<ImmutableArray<Diagnostic>> AnalyzeSemanticsAsync(TextDocument textDocument, SyntaxTree? tree, CancellationToken cancellationToken)
=> [];

/// <summary>
/// it is not allowed one to implement both DocumentDiagnosticAnalyzer and DiagnosticAnalyzer
Expand Down
6 changes: 3 additions & 3 deletions src/Workspaces/Core/Portable/Diagnostics/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,18 +349,18 @@ public static ImmutableArray<Diagnostic> Filter(
/// This checksum is also affected by the <see cref="SourceGeneratorExecutionVersion"/> for this project.
/// As such, it is not usable across different sessions of a particular host.
/// </remarks>
public static Task<Checksum> GetDiagnosticChecksumAsync(this Project? project, CancellationToken cancellationToken)
public static async Task<Checksum> GetDiagnosticChecksumAsync(this Project? project, CancellationToken cancellationToken)
{
if (project is null)
return SpecializedTasks.Default<Checksum>();
return default(Checksum);

var lazyChecksum = s_projectToDiagnosticChecksum.GetValue(
project,
static project => AsyncLazy.Create(
static (project, cancellationToken) => ComputeDiagnosticChecksumAsync(project, cancellationToken),
project));

return lazyChecksum.GetValueAsync(cancellationToken);
return await lazyChecksum.GetValueAsync(cancellationToken).ConfigureAwait(false);

static async Task<Checksum> ComputeDiagnosticChecksumAsync(Project project, CancellationToken cancellationToken)
{
Expand Down
12 changes: 4 additions & 8 deletions src/Workspaces/Core/Portable/Editing/SymbolEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,9 @@ public Task<ISymbol> EditOneDeclarationAsync(
{
return this.EditOneDeclarationAsync(
symbol,
(e, d, c) =>
async (e, d, c) =>
{
editAction(e, d);
return Task.CompletedTask;
},
cancellationToken);
}
Expand Down Expand Up @@ -351,10 +350,9 @@ public Task<ISymbol> EditOneDeclarationAsync(
return this.EditOneDeclarationAsync(
symbol,
location,
(e, d, c) =>
async (e, d, c) =>
{
editAction(e, d);
return Task.CompletedTask;
},
cancellationToken);
}
Expand Down Expand Up @@ -434,10 +432,9 @@ public Task<ISymbol> EditOneDeclarationAsync(
return this.EditOneDeclarationAsync(
symbol,
member,
(e, d, c) =>
async (e, d, c) =>
{
editAction(e, d);
return Task.CompletedTask;
},
cancellationToken);
}
Expand Down Expand Up @@ -515,10 +512,9 @@ public Task<ISymbol> EditAllDeclarationsAsync(
{
return this.EditAllDeclarationsAsync(
symbol,
(e, d, c) =>
async (e, d, c) =>
{
editAction(e, d);
return Task.CompletedTask;
},
cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols;

internal static partial class DependentTypeFinder
{
private static Task<ImmutableArray<INamedTypeSymbol>> FindDerivedClassesInCurrentProcessAsync(
private static async Task<ImmutableArray<INamedTypeSymbol>> FindDerivedClassesInCurrentProcessAsync(
INamedTypeSymbol type,
Solution solution,
IImmutableSet<Project>? projects,
Expand All @@ -24,13 +24,13 @@ private static Task<ImmutableArray<INamedTypeSymbol>> FindDerivedClassesInCurren
static bool TypeMatches(INamedTypeSymbol type, HashSet<INamedTypeSymbol> set)
=> TypeHasBaseTypeInSet(type, set);

return DescendInheritanceTreeAsync(type, solution, projects,
return await DescendInheritanceTreeAsync(type, solution, projects,
typeMatches: TypeMatches,
shouldContinueSearching: s_isNonSealedClass,
transitive: transitive,
cancellationToken: cancellationToken);
cancellationToken: cancellationToken).ConfigureAwait(false);
}

return SpecializedTasks.EmptyImmutableArray<INamedTypeSymbol>();
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols;

internal static partial class DependentTypeFinder
{
private static Task<ImmutableArray<INamedTypeSymbol>> FindDerivedInterfacesInCurrentProcessAsync(
private static async Task<ImmutableArray<INamedTypeSymbol>> FindDerivedInterfacesInCurrentProcessAsync(
INamedTypeSymbol type,
Solution solution,
IImmutableSet<Project>? projects,
Expand All @@ -25,13 +25,13 @@ private static Task<ImmutableArray<INamedTypeSymbol>> FindDerivedInterfacesInCur
static bool TypeMatches(INamedTypeSymbol type, HashSet<INamedTypeSymbol> set)
=> s_isInterface(type) && TypeHasInterfaceInSet(type, set);

return DescendInheritanceTreeAsync(type, solution, projects,
return await DescendInheritanceTreeAsync(type, solution, projects,
typeMatches: TypeMatches,
shouldContinueSearching: s_isInterface,
transitive: transitive,
cancellationToken: cancellationToken);
cancellationToken: cancellationToken).ConfigureAwait(false);
}

return SpecializedTasks.EmptyImmutableArray<INamedTypeSymbol>();
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ private sealed class NonCascadingSymbolSet(FindReferencesSearchEngine engine, Me
public override ImmutableArray<ISymbol> GetAllSymbols()
=> _symbols;

public override Task InheritanceCascadeAsync(Project project, CancellationToken cancellationToken)
public override async Task InheritanceCascadeAsync(Project project, CancellationToken cancellationToken)
{
// Nothing to do here. We're in a non-cascading scenario, so even as we encounter a new project we
// don't have to figure out what new symbols may be found.
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private async ValueTask ProcessDocumentAsync(
await Parallel.ForEachAsync(
symbolsToSearchFor,
GetParallelOptions(cancellationToken),
(kvp, cancellationToken) =>
async (kvp, cancellationToken) =>
{
var (symbolToSearchFor, symbolGroup) = kvp;

Expand All @@ -311,7 +311,6 @@ await Parallel.ForEachAsync(
cache, TryGet(symbolToGlobalAliases, symbolToSearchFor));

ProcessDocument(symbolToSearchFor, symbolGroup, state, onReferenceFound);
return ValueTask.CompletedTask;
}).ConfigureAwait(false);

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async ValueTask DirectSymbolSearchAsync(ISymbol symbol, SymbolGroup group, FindR
{
await ProducerConsumer<FinderLocation>.RunAsync(
ProducerConsumerOptions.SingleReaderWriterOptions,
static (callback, args, cancellationToken) =>
static async (callback, args, cancellationToken) =>
{
var (@this, symbol, group, state) = args;

Expand All @@ -148,8 +148,6 @@ await ProducerConsumer<FinderLocation>.RunAsync(
static (finderLocation, callback) => callback(finderLocation),
callback, @this._options, cancellationToken);
}

return Task.CompletedTask;
},
consumeItems: static async (values, args, cancellationToken) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected abstract bool TokensMatch(
protected sealed override bool CanFind(TSymbol symbol)
=> true;

protected sealed override Task DetermineDocumentsToSearchAsync<TData>(
protected sealed override async Task DetermineDocumentsToSearchAsync<TData>(
TSymbol symbol,
HashSet<string>? globalAliases,
Project project,
Expand All @@ -36,17 +36,16 @@ protected sealed override Task DetermineDocumentsToSearchAsync<TData>(
{
var location = symbol.Locations.FirstOrDefault();
if (location == null || !location.IsInSource)
return Task.CompletedTask;
return;

var document = project.GetDocument(location.SourceTree);
if (document == null)
return Task.CompletedTask;
return;

if (documents != null && !documents.Contains(document))
return Task.CompletedTask;
return;

processResult(document, processResultData);
return Task.CompletedTask;
}

protected sealed override void FindReferencesInDocument<TData>(
Expand Down
Loading
Loading