From 9e64998d931b622fe0087d7251cf29815948c699 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 25 Aug 2020 09:08:34 -0700 Subject: [PATCH] Use SpecializedTasks where appropriate --- .../EditAndContinue/ActiveStatementTrackingService.cs | 2 +- .../Core/SymbolSearch/SymbolSearchUpdateEngineFactory.cs | 7 ++++--- .../KeywordRecommenders/DynamicKeywordRecommender.cs | 2 +- .../KeywordRecommenders/NotnullKeywordRecommender.cs | 2 +- .../KeywordRecommenders/UnmanagedKeywordRecommender.cs | 2 +- .../KeywordRecommenders/VarKeywordRecommender.cs | 2 +- .../Core/Portable/Completion/CommonCompletionProvider.cs | 3 ++- .../Analyzers/EditAndContinueDiagnosticAnalyzer.cs | 2 +- .../DiagnosticIncrementalAnalyzer_GetDiagnostics.cs | 2 +- .../EditAndContinue/EditAndContinueWorkspaceService.cs | 2 +- .../VSTypeScriptDocumentDiagnosticAnalyzer.cs | 5 +++-- .../VSTypeScriptProjectDiagnosticAnalyzer.cs | 3 ++- ...FromParameterCodeRefactoringProviderMemberCreation.cs | 2 +- ...ergeConsecutiveIfStatementsCodeRefactoringProvider.cs | 9 +++++---- ...ractMergeNestedIfStatementsCodeRefactoringProvider.cs | 5 +++-- .../AbstractUpgradeProjectCodeFixProvider.cs | 3 ++- .../ProjectContext/GetTextDocumentWithContextHandler.cs | 3 ++- .../Async/VisualBasicAddAwaitCodeFixProvider.vb | 4 ++-- .../Iterator/VisualBasicChangeToYieldCodeFixProvider.vb | 2 +- .../SyncNamespace/VisualBasicChangeNamespaceService.vb | 2 +- .../CoreTestUtilities/Remote/InProcRemostHostClient.cs | 2 +- .../TestDynamicFileInfoProviderThatProducesNoFiles.cs | 3 ++- src/Workspaces/Remote/Core/ServiceHubRemoteHostClient.cs | 4 +++- .../Workspace/Core/CodeFixes/CustomCodeActions.cs | 3 ++- .../FixAll/FixAllState.FixMultipleDiagnosticProvider.cs | 4 ++-- .../Portable/FindSymbols/VisualBasicReferenceFinder.vb | 2 +- 26 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTrackingService.cs b/src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTrackingService.cs index 982dcfcf266..4e911d6df45 100644 --- a/src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTrackingService.cs +++ b/src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTrackingService.cs @@ -96,7 +96,7 @@ public bool TryGetSpan(ActiveStatementId id, SourceText source, out TextSpan spa } public Task> GetLatestSpansAsync(Document document, ITextSnapshot snapshot, CancellationToken cancellationToken) - => _session?.GetLatestSpansAsync(document, snapshot, cancellationToken) ?? Task.FromResult(ImmutableArray.Empty); + => _session?.GetLatestSpansAsync(document, snapshot, cancellationToken) ?? SpecializedTasks.EmptyImmutableArray(); // internal for testing internal sealed class TrackingSession diff --git a/src/EditorFeatures/Core/SymbolSearch/SymbolSearchUpdateEngineFactory.cs b/src/EditorFeatures/Core/SymbolSearch/SymbolSearchUpdateEngineFactory.cs index 25742b66584..1224ad75450 100644 --- a/src/EditorFeatures/Core/SymbolSearch/SymbolSearchUpdateEngineFactory.cs +++ b/src/EditorFeatures/Core/SymbolSearch/SymbolSearchUpdateEngineFactory.cs @@ -10,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Remote; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.SymbolSearch { @@ -53,13 +54,13 @@ public static ISymbolSearchUpdateEngine CreateEngineInProcess(ISymbolSearchLogSe private sealed class NoOpUpdateEngine : ISymbolSearchUpdateEngine { public Task> FindPackagesWithAssemblyAsync(string source, string assemblyName, CancellationToken cancellationToken) - => Task.FromResult(ImmutableArray.Empty); + => SpecializedTasks.EmptyImmutableArray(); public Task> FindPackagesWithTypeAsync(string source, string name, int arity, CancellationToken cancellationToken) - => Task.FromResult(ImmutableArray.Empty); + => SpecializedTasks.EmptyImmutableArray(); public Task> FindReferenceAssembliesWithTypeAsync(string name, int arity, CancellationToken cancellationToken) - => Task.FromResult(ImmutableArray.Empty); + => SpecializedTasks.EmptyImmutableArray(); public Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirectory) => Task.CompletedTask; diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/DynamicKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/DynamicKeywordRecommender.cs index 6f499d69848..a6ecfa855c2 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/DynamicKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/DynamicKeywordRecommender.cs @@ -32,7 +32,7 @@ public Task> RecommendKeywordsAsync(int position return Task.FromResult(SpecializedCollections.SingletonEnumerable(new RecommendedKeyword("dynamic"))); } - return Task.FromResult>(null); + return SpecializedTasks.Null>(); } protected static bool IsDynamicTypeContext( diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/NotnullKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/NotnullKeywordRecommender.cs index 3de22f1e731..254771d0ab1 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/NotnullKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/NotnullKeywordRecommender.cs @@ -20,7 +20,7 @@ public Task> RecommendKeywordsAsync(int position return Task.FromResult(SpecializedCollections.SingletonEnumerable(new RecommendedKeyword("notnull"))); } - return Task.FromResult>(null); + return SpecializedTasks.Null>(); } } } diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/UnmanagedKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/UnmanagedKeywordRecommender.cs index 2af0d80be8b..9c17149b4a6 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/UnmanagedKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/UnmanagedKeywordRecommender.cs @@ -20,7 +20,7 @@ public Task> RecommendKeywordsAsync(int position return Task.FromResult(SpecializedCollections.SingletonEnumerable(new RecommendedKeyword("unmanaged"))); } - return Task.FromResult>(null); + return SpecializedTasks.Null>(); } } } diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/VarKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/VarKeywordRecommender.cs index 7401f91cbfd..d7d7987578c 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/VarKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/VarKeywordRecommender.cs @@ -37,7 +37,7 @@ public Task> RecommendKeywordsAsync(int position return Task.FromResult(SpecializedCollections.SingletonEnumerable(new RecommendedKeyword("var"))); } - return Task.FromResult>(null); + return SpecializedTasks.Null>(); } } } diff --git a/src/Features/Core/Portable/Completion/CommonCompletionProvider.cs b/src/Features/Core/Portable/Completion/CommonCompletionProvider.cs index 7aa5339f13c..92fcd2471f5 100644 --- a/src/Features/Core/Portable/Completion/CommonCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/CommonCompletionProvider.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Snippets; using Microsoft.CodeAnalysis.Text; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Completion { @@ -92,7 +93,7 @@ public override async Task GetChangeAsync(Document document, C => GetTextChangeAsync(selectedItem, ch, cancellationToken); protected virtual Task GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken) - => Task.FromResult(null); + => SpecializedTasks.Default(); private static readonly CompletionItemRules s_suggestionItemRules = CompletionItemRules.Create(enterKeyRule: EnterKeyRule.Never); diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/EditAndContinueDiagnosticAnalyzer.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/EditAndContinueDiagnosticAnalyzer.cs index a5e2a222b58..35ff7b5c7c9 100644 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/EditAndContinueDiagnosticAnalyzer.cs +++ b/src/Features/Core/Portable/Diagnostics/Analyzers/EditAndContinueDiagnosticAnalyzer.cs @@ -33,7 +33,7 @@ public override Task> AnalyzeSyntaxAsync(Document doc public override Task> AnalyzeSemanticsAsync(Document document, CancellationToken cancellationToken) { var encService = document.Project.Solution.Workspace.Services.GetService(); - return (encService != null) ? encService.GetDocumentDiagnosticsAsync(document, cancellationToken) : Task.FromResult(ImmutableArray.Empty); + return (encService != null) ? encService.GetDocumentDiagnosticsAsync(document, cancellationToken) : SpecializedTasks.EmptyImmutableArray(); } } } diff --git a/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs b/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs index 095c10ea8ad..0a36174f471 100644 --- a/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs +++ b/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs @@ -20,7 +20,7 @@ public Task> GetSpecificCachedDiagnosticsAsync(So { if (!(id is LiveDiagnosticUpdateArgsId argsId)) { - return Task.FromResult(ImmutableArray.Empty); + return SpecializedTasks.EmptyImmutableArray(); } var (documentId, projectId) = (argsId.ProjectOrDocumentId is DocumentId docId) ? (docId, docId.ProjectId) : (null, (ProjectId)argsId.ProjectOrDocumentId); diff --git a/src/Features/Core/Portable/EditAndContinue/EditAndContinueWorkspaceService.cs b/src/Features/Core/Portable/EditAndContinue/EditAndContinueWorkspaceService.cs index c869355fe09..b9c3cd53e3b 100644 --- a/src/Features/Core/Portable/EditAndContinue/EditAndContinueWorkspaceService.cs +++ b/src/Features/Core/Portable/EditAndContinue/EditAndContinueWorkspaceService.cs @@ -365,7 +365,7 @@ public Task HasChangesAsync(Solution solution, string? sourceFilePath, Can var editSession = _editSession; if (editSession == null) { - return Task.FromResult(false); + return SpecializedTasks.False; } return editSession.HasChangesAsync(solution, sourceFilePath, cancellationToken); diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDocumentDiagnosticAnalyzer.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDocumentDiagnosticAnalyzer.cs index 0885fdf45bc..99f510bd72d 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDocumentDiagnosticAnalyzer.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDocumentDiagnosticAnalyzer.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { @@ -21,7 +22,7 @@ public override Task> AnalyzeSyntaxAsync(Document doc var analyzer = document.Project.LanguageServices.GetRequiredService().Implementation; if (analyzer == null) { - return Task.FromResult(ImmutableArray.Empty); + return SpecializedTasks.EmptyImmutableArray(); } return analyzer.AnalyzeDocumentSyntaxAsync(document, cancellationToken); @@ -32,7 +33,7 @@ public override Task> AnalyzeSemanticsAsync(Document var analyzer = document.Project.LanguageServices.GetRequiredService().Implementation; if (analyzer == null) { - return Task.FromResult(ImmutableArray.Empty); + return SpecializedTasks.EmptyImmutableArray(); } return analyzer.AnalyzeDocumentSemanticsAsync(document, cancellationToken); diff --git a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptProjectDiagnosticAnalyzer.cs b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptProjectDiagnosticAnalyzer.cs index 24487de0848..52d41803efe 100644 --- a/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptProjectDiagnosticAnalyzer.cs +++ b/src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptProjectDiagnosticAnalyzer.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript { @@ -21,7 +22,7 @@ public override Task> AnalyzeProjectAsync(Project pro var analyzer = project.LanguageServices.GetRequiredService().Implementation; if (analyzer == null) { - return Task.FromResult(ImmutableArray.Empty); + return SpecializedTasks.EmptyImmutableArray(); } return analyzer.AnalyzeProjectAsync(project, cancellationToken); diff --git a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs index b51e9c36fa0..8b9684b04ac 100644 --- a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs +++ b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs @@ -51,7 +51,7 @@ internal abstract partial class AbstractInitializeMemberFromParameterCodeRefacto Document document, SyntaxNode functionDeclaration, IMethodSymbol method, IBlockOperation? blockStatementOpt, ImmutableArray listOfParameterNodes, TextSpan parameterSpan, CancellationToken cancellationToken) { - return Task.FromResult(ImmutableArray.Empty); + return SpecializedTasks.EmptyImmutableArray(); } protected override async Task> GetRefactoringsForSingleParameterAsync( diff --git a/src/Features/Core/Portable/SplitOrMergeIfStatements/Consecutive/AbstractMergeConsecutiveIfStatementsCodeRefactoringProvider.cs b/src/Features/Core/Portable/SplitOrMergeIfStatements/Consecutive/AbstractMergeConsecutiveIfStatementsCodeRefactoringProvider.cs index 5989e182aca..b48f9096574 100644 --- a/src/Features/Core/Portable/SplitOrMergeIfStatements/Consecutive/AbstractMergeConsecutiveIfStatementsCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/SplitOrMergeIfStatements/Consecutive/AbstractMergeConsecutiveIfStatementsCodeRefactoringProvider.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Utilities; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.SplitOrMergeIfStatements { @@ -52,7 +53,7 @@ protected sealed override CodeAction CreateCodeAction(Func(); if (CanBeMergedWithParent(syntaxFacts, ifGenerator, ifOrElseIf, out firstIfOrElseIf)) - return Task.FromResult(true); + return SpecializedTasks.True; return CanBeMergedWithPreviousStatementAsync(document, syntaxFacts, ifGenerator, ifOrElseIf, cancellationToken, out firstIfOrElseIf); } @@ -64,7 +65,7 @@ protected sealed override CodeAction CreateCodeAction(Func(); if (CanBeMergedWithElseIf(syntaxFacts, ifGenerator, ifOrElseIf, out secondIfOrElseIf)) - return Task.FromResult(true); + return SpecializedTasks.True; return CanBeMergedWithNextStatementAsync(document, syntaxFacts, ifGenerator, ifOrElseIf, cancellationToken, out secondIfOrElseIf); } @@ -154,7 +155,7 @@ protected sealed override SyntaxNode GetChangedRoot(Document document, SyntaxNod { return TryGetSiblingStatement(syntaxFacts, ifOrElseIf, relativeIndex: -1, out previousStatement) ? CanStatementsBeMergedAsync(document, syntaxFacts, ifGenerator, previousStatement, ifOrElseIf, cancellationToken) - : Task.FromResult(false); + : SpecializedTasks.False; } private static Task CanBeMergedWithNextStatementAsync( @@ -167,7 +168,7 @@ protected sealed override SyntaxNode GetChangedRoot(Document document, SyntaxNod { return TryGetSiblingStatement(syntaxFacts, ifOrElseIf, relativeIndex: 1, out nextStatement) ? CanStatementsBeMergedAsync(document, syntaxFacts, ifGenerator, ifOrElseIf, nextStatement, cancellationToken) - : Task.FromResult(false); + : SpecializedTasks.False; } private static async Task CanStatementsBeMergedAsync( diff --git a/src/Features/Core/Portable/SplitOrMergeIfStatements/Nested/AbstractMergeNestedIfStatementsCodeRefactoringProvider.cs b/src/Features/Core/Portable/SplitOrMergeIfStatements/Nested/AbstractMergeNestedIfStatementsCodeRefactoringProvider.cs index a3d5e623cb3..bc726c28706 100644 --- a/src/Features/Core/Portable/SplitOrMergeIfStatements/Nested/AbstractMergeNestedIfStatementsCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/SplitOrMergeIfStatements/Nested/AbstractMergeNestedIfStatementsCodeRefactoringProvider.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Utilities; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.SplitOrMergeIfStatements { @@ -40,7 +41,7 @@ protected sealed override CodeAction CreateCodeAction(Func(); if (!IsFirstStatementOfIfOrElseIf(syntaxFacts, ifGenerator, ifOrElseIf, out outerIfOrElseIf)) - return Task.FromResult(false); + return SpecializedTasks.False; return CanBeMergedAsync(document, syntaxFacts, ifGenerator, outerIfOrElseIf, ifOrElseIf, cancellationToken); } @@ -52,7 +53,7 @@ protected sealed override CodeAction CreateCodeAction(Func(); if (!IsFirstStatementIfStatement(syntaxFacts, ifGenerator, ifOrElseIf, out innerIfStatement)) - return Task.FromResult(false); + return SpecializedTasks.False; return CanBeMergedAsync(document, syntaxFacts, ifGenerator, ifOrElseIf, innerIfStatement, cancellationToken); } diff --git a/src/Features/Core/Portable/UpgradeProject/AbstractUpgradeProjectCodeFixProvider.cs b/src/Features/Core/Portable/UpgradeProject/AbstractUpgradeProjectCodeFixProvider.cs index d329535686b..ed31d94a848 100644 --- a/src/Features/Core/Portable/UpgradeProject/AbstractUpgradeProjectCodeFixProvider.cs +++ b/src/Features/Core/Portable/UpgradeProject/AbstractUpgradeProjectCodeFixProvider.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; +using Roslyn.Utilities; using static Microsoft.CodeAnalysis.CodeActions.CodeAction; namespace Microsoft.CodeAnalysis.UpgradeProject @@ -100,6 +101,6 @@ public ProjectOptionsChangeAction(string title, Func> ComputePreviewOperationsAsync(CancellationToken cancellationToken) - => Task.FromResult(Enumerable.Empty()); + => SpecializedTasks.EmptyEnumerable(); } } diff --git a/src/Features/LanguageServer/Protocol/Handler/ProjectContext/GetTextDocumentWithContextHandler.cs b/src/Features/LanguageServer/Protocol/Handler/ProjectContext/GetTextDocumentWithContextHandler.cs index 16ed4d7c0ad..5b5045d269d 100644 --- a/src/Features/LanguageServer/Protocol/Handler/ProjectContext/GetTextDocumentWithContextHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/ProjectContext/GetTextDocumentWithContextHandler.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.VisualStudio.LanguageServer.Protocol; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.LanguageServer.Handler { @@ -32,7 +33,7 @@ public GetTextDocumentWithContextHandler(ILspSolutionProvider solutionProvider) if (!documents.Any()) { - return Task.FromResult(null); + return SpecializedTasks.Null(); } var contexts = new List(); diff --git a/src/Features/VisualBasic/Portable/CodeFixes/Async/VisualBasicAddAwaitCodeFixProvider.vb b/src/Features/VisualBasic/Portable/CodeFixes/Async/VisualBasicAddAwaitCodeFixProvider.vb index e5ac84e74ef..6ed480c51ae 100644 --- a/src/Features/VisualBasic/Portable/CodeFixes/Async/VisualBasicAddAwaitCodeFixProvider.vb +++ b/src/Features/VisualBasic/Portable/CodeFixes/Async/VisualBasicAddAwaitCodeFixProvider.vb @@ -56,12 +56,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Async Select Case diagnostic.Id Case BC30311 If Not DoesExpressionReturnGenericTaskWhoseArgumentsMatchLeftSide(expression, semanticModel, document.Project, cancellationToken) Then - Return Task.FromResult(Of SyntaxNode)(Nothing) + Return SpecializedTasks.Null(Of SyntaxNode)() End If Return Task.FromResult(root.ReplaceNode(oldNode, ConverToAwaitExpression(expression))) Case BC37055 If Not DoesExpressionReturnTask(expression, semanticModel) Then - Return Task.FromResult(Of SyntaxNode)(Nothing) + Return SpecializedTasks.Null(Of SyntaxNode)() End If Return Task.FromResult(root.ReplaceNode(oldNode, ConverToAwaitExpression(expression))) Case BC42358 diff --git a/src/Features/VisualBasic/Portable/CodeFixes/Iterator/VisualBasicChangeToYieldCodeFixProvider.vb b/src/Features/VisualBasic/Portable/CodeFixes/Iterator/VisualBasicChangeToYieldCodeFixProvider.vb index 2c197ca64ed..a1e2bff5537 100644 --- a/src/Features/VisualBasic/Portable/CodeFixes/Iterator/VisualBasicChangeToYieldCodeFixProvider.vb +++ b/src/Features/VisualBasic/Portable/CodeFixes/Iterator/VisualBasicChangeToYieldCodeFixProvider.vb @@ -35,7 +35,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Iterator Protected Overrides Function GetCodeFixAsync(root As SyntaxNode, node As SyntaxNode, document As Document, diagnostics As Diagnostic, cancellationToken As CancellationToken) As Task(Of CodeAction) If Not node.IsKind(SyntaxKind.ReturnStatement) Then - Return Task.FromResult(Of CodeAction)(Nothing) + Return SpecializedTasks.Null(Of CodeAction)() End If Dim returnStatement = TryCast(node, ReturnStatementSyntax) diff --git a/src/Features/VisualBasic/Portable/CodeRefactorings/SyncNamespace/VisualBasicChangeNamespaceService.vb b/src/Features/VisualBasic/Portable/CodeRefactorings/SyncNamespace/VisualBasicChangeNamespaceService.vb index 524920d573d..408ba71bfa8 100644 --- a/src/Features/VisualBasic/Portable/CodeRefactorings/SyncNamespace/VisualBasicChangeNamespaceService.vb +++ b/src/Features/VisualBasic/Portable/CodeRefactorings/SyncNamespace/VisualBasicChangeNamespaceService.vb @@ -58,7 +58,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ChangeNamespace ' TODO: Implement the service for VB Protected Overrides Function GetValidContainersFromAllLinkedDocumentsAsync(document As Document, container As SyntaxNode, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of (DocumentId, SyntaxNode))) - Return Task.FromResult(CType(Nothing, ImmutableArray(Of (DocumentId, SyntaxNode)))) + Return SpecializedTasks.Default(Of ImmutableArray(Of (DocumentId, SyntaxNode)))() End Function ' This is only reachable when called from a VB service, which is not implemented yet. diff --git a/src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs b/src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs index 132f145767e..3257d90fd2e 100644 --- a/src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs +++ b/src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs @@ -93,7 +93,7 @@ public Task GetAssetsAsync(int scopeId, Checksum[] checksums, string pipeName, C /// Remote API. /// public Task IsExperimentEnabledAsync(string experimentName, CancellationToken cancellationToken) - => Task.FromResult(_services.GetRequiredService().IsExperimentEnabled(experimentName)); + => _services.GetRequiredService().IsExperimentEnabled(experimentName) ? SpecializedTasks.True : SpecializedTasks.False; public RemoteHostTestData TestData => _inprocServices.TestData; diff --git a/src/Workspaces/CoreTestUtilities/TestDynamicFileInfoProviderThatProducesNoFiles.cs b/src/Workspaces/CoreTestUtilities/TestDynamicFileInfoProviderThatProducesNoFiles.cs index 72599dd2b35..8af68c88bed 100644 --- a/src/Workspaces/CoreTestUtilities/TestDynamicFileInfoProviderThatProducesNoFiles.cs +++ b/src/Workspaces/CoreTestUtilities/TestDynamicFileInfoProviderThatProducesNoFiles.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Test.Utilities { @@ -25,7 +26,7 @@ public TestDynamicFileInfoProviderThatProducesNoFiles() event EventHandler IDynamicFileInfoProvider.Updated { add { } remove { } } public Task GetDynamicFileInfoAsync(ProjectId projectId, string projectFilePath, string filePath, CancellationToken cancellationToken) - => Task.FromResult(null); + => SpecializedTasks.Null(); public Task RemoveDynamicFileInfoAsync(ProjectId projectId, string projectFilePath, string filePath, CancellationToken cancellationToken) => Task.CompletedTask; diff --git a/src/Workspaces/Remote/Core/ServiceHubRemoteHostClient.cs b/src/Workspaces/Remote/Core/ServiceHubRemoteHostClient.cs index 301e55d4036..e3432ff7850 100644 --- a/src/Workspaces/Remote/Core/ServiceHubRemoteHostClient.cs +++ b/src/Workspaces/Remote/Core/ServiceHubRemoteHostClient.cs @@ -214,7 +214,9 @@ public Task IsExperimentEnabledAsync(string experimentName, CancellationTo { try { - return Task.FromResult(_services.GetRequiredService().IsExperimentEnabled(experimentName)); + return _services.GetRequiredService().IsExperimentEnabled(experimentName) + ? SpecializedTasks.True + : SpecializedTasks.False; } catch (Exception ex) when (FatalError.ReportWithoutCrashUnlessCanceledAndPropagate(ex, cancellationToken)) { diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CustomCodeActions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CustomCodeActions.cs index 6d9ef7b7e2e..96d50ac5c33 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CustomCodeActions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CustomCodeActions.cs @@ -5,6 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CodeActions { @@ -22,7 +23,7 @@ public SimpleCodeAction(string title, string equivalenceKey) public sealed override string EquivalenceKey { get; } protected override Task GetChangedDocumentAsync(CancellationToken cancellationToken) - => Task.FromResult(null); + => SpecializedTasks.Null(); } internal class DocumentChangeAction : SimpleCodeAction diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAll/FixAllState.FixMultipleDiagnosticProvider.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAll/FixAllState.FixMultipleDiagnosticProvider.cs index 91aa1a9489a..91b50192e27 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAll/FixAllState.FixMultipleDiagnosticProvider.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAll/FixAllState.FixMultipleDiagnosticProvider.cs @@ -63,7 +63,7 @@ public override Task> GetDocumentDiagnosticsAsync(Docume return Task.FromResult>(diagnostics); } - return Task.FromResult(SpecializedCollections.EmptyEnumerable()); + return SpecializedTasks.EmptyEnumerable(); } public override Task> GetProjectDiagnosticsAsync(Project project, CancellationToken cancellationToken) @@ -73,7 +73,7 @@ public override Task> GetProjectDiagnosticsAsync(Project return Task.FromResult>(diagnostics); } - return Task.FromResult(SpecializedCollections.EmptyEnumerable()); + return SpecializedTasks.EmptyEnumerable(); } } } diff --git a/src/Workspaces/VisualBasic/Portable/FindSymbols/VisualBasicReferenceFinder.vb b/src/Workspaces/VisualBasic/Portable/FindSymbols/VisualBasicReferenceFinder.vb index 63079b0e3c4..04b53a4c0a4 100644 --- a/src/Workspaces/VisualBasic/Portable/FindSymbols/VisualBasicReferenceFinder.vb +++ b/src/Workspaces/VisualBasic/Portable/FindSymbols/VisualBasicReferenceFinder.vb @@ -29,7 +29,7 @@ Namespace Microsoft.CodeAnalysis.FindSymbols Return DetermineCascadedSymbolsAsync( DirectCast(symbol, INamedTypeSymbol), project, cancellationToken) Else - Return Task.FromResult(ImmutableArray(Of ISymbol).Empty) + Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)() End If End Function -- GitLab