diff --git a/src/Features/Core/Portable/FindUsages/DefaultExternalDefinitionItemProvider.cs b/src/Features/Core/Portable/FindUsages/DefaultExternalDefinitionItemProvider.cs index dfa94995ac4e3..ac0a89f5d327a 100644 --- a/src/Features/Core/Portable/FindUsages/DefaultExternalDefinitionItemProvider.cs +++ b/src/Features/Core/Portable/FindUsages/DefaultExternalDefinitionItemProvider.cs @@ -20,6 +20,6 @@ internal sealed class DefaultExternalDefinitionItemProvider() : IExternalDefinit /// Provides an extension point that allows for other workspace layers to add additional /// results to the results found by the FindReferences engine. /// - public Task GetThirdPartyDefinitionItemAsync(Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) - => SpecializedTasks.Null(); + public async ValueTask GetThirdPartyDefinitionItemAsync(Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) + => null; } diff --git a/src/Features/Core/Portable/FindUsages/IExternalDefinitionItemProvider.cs b/src/Features/Core/Portable/FindUsages/IExternalDefinitionItemProvider.cs index bfab728b62a21..932f1c3ca41a1 100644 --- a/src/Features/Core/Portable/FindUsages/IExternalDefinitionItemProvider.cs +++ b/src/Features/Core/Portable/FindUsages/IExternalDefinitionItemProvider.cs @@ -10,6 +10,6 @@ namespace Microsoft.CodeAnalysis.FindUsages; internal interface IExternalDefinitionItemProvider : IWorkspaceService { - Task GetThirdPartyDefinitionItemAsync( + ValueTask GetThirdPartyDefinitionItemAsync( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken); } diff --git a/src/VisualStudio/CSharp/Impl/CSharpPackage.cs b/src/VisualStudio/CSharp/Impl/CSharpPackage.cs index d085fa72391ec..c12fedcdbe6d1 100644 --- a/src/VisualStudio/CSharp/Impl/CSharpPackage.cs +++ b/src/VisualStudio/CSharp/Impl/CSharpPackage.cs @@ -67,7 +67,7 @@ protected override void RegisterInitializeAsyncWork(PackageLoadTasks packageInit packageInitializationTasks.AddTask(isMainThreadTask: false, task: PackageInitializationBackgroundThreadAsync); } - private Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks packageInitializationTasks, CancellationToken cancellationToken) + private async Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks packageInitializationTasks, CancellationToken cancellationToken) { try { @@ -90,8 +90,6 @@ private Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks package catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General)) { } - - return Task.CompletedTask; } protected override void RegisterObjectBrowserLibraryManager() diff --git a/src/VisualStudio/CSharp/Impl/EditorConfigSettings/DataProvider/CodeStyle/CSharpCodeStyleSettingsProvider.cs b/src/VisualStudio/CSharp/Impl/EditorConfigSettings/DataProvider/CodeStyle/CSharpCodeStyleSettingsProvider.cs index 61559fa4ec6a4..814c27ffb1a02 100644 --- a/src/VisualStudio/CSharp/Impl/EditorConfigSettings/DataProvider/CodeStyle/CSharpCodeStyleSettingsProvider.cs +++ b/src/VisualStudio/CSharp/Impl/EditorConfigSettings/DataProvider/CodeStyle/CSharpCodeStyleSettingsProvider.cs @@ -33,7 +33,7 @@ public CSharpCodeStyleSettingsProvider( Update(); } - protected override Task UpdateOptionsAsync( + protected override async Task UpdateOptionsAsync( TieredAnalyzerConfigOptions options, ImmutableArray projectsInScope, CancellationToken cancellationToken) { var varSettings = GetVarCodeStyleOptions(options, SettingsUpdater); @@ -65,8 +65,6 @@ protected override Task UpdateOptionsAsync( var unusedValueSettings = GetUnusedValueCodeStyleOptions(options, SettingsUpdater); AddRange(unusedValueSettings); - - return Task.CompletedTask; } private static IEnumerable GetVarCodeStyleOptions(TieredAnalyzerConfigOptions options, OptionUpdater updater) diff --git a/src/VisualStudio/CSharp/Impl/EditorConfigSettings/DataProvider/Whitespace/CSharpWhitespaceSettingsProvider.cs b/src/VisualStudio/CSharp/Impl/EditorConfigSettings/DataProvider/Whitespace/CSharpWhitespaceSettingsProvider.cs index 5b1dec17cb78c..104fbf0424e1e 100644 --- a/src/VisualStudio/CSharp/Impl/EditorConfigSettings/DataProvider/Whitespace/CSharpWhitespaceSettingsProvider.cs +++ b/src/VisualStudio/CSharp/Impl/EditorConfigSettings/DataProvider/Whitespace/CSharpWhitespaceSettingsProvider.cs @@ -28,7 +28,7 @@ public CSharpWhitespaceSettingsProvider(IThreadingContext threadingContext, stri Update(); } - protected override Task UpdateOptionsAsync( + protected override async Task UpdateOptionsAsync( TieredAnalyzerConfigOptions options, ImmutableArray projectsInScope, CancellationToken cancellationToken) { var spacingOptions = GetSpacingOptions(options, SettingsUpdater); @@ -39,8 +39,6 @@ protected override Task UpdateOptionsAsync( AddRange(indentationOptions.ToImmutableArray()); var wrappingOptions = GetWrappingOptions(options, SettingsUpdater); AddRange(wrappingOptions.ToImmutableArray()); - - return Task.CompletedTask; } private static IEnumerable GetSpacingOptions(TieredAnalyzerConfigOptions options, OptionUpdater updaterService) diff --git a/src/VisualStudio/CSharp/Impl/SemanticSearch/SemanticSearchDocumentNavigationService.cs b/src/VisualStudio/CSharp/Impl/SemanticSearch/SemanticSearchDocumentNavigationService.cs index 44adda02940ba..bfa22be013cf0 100644 --- a/src/VisualStudio/CSharp/Impl/SemanticSearch/SemanticSearchDocumentNavigationService.cs +++ b/src/VisualStudio/CSharp/Impl/SemanticSearch/SemanticSearchDocumentNavigationService.cs @@ -22,14 +22,14 @@ namespace Microsoft.VisualStudio.LanguageServices.CSharp; internal sealed class SemanticSearchDocumentNavigationService(SemanticSearchToolWindowImpl window) : AbstractDocumentNavigationService { - public override Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken) - => SpecializedTasks.True; + public override async Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken) + => true; - public override Task GetLocationForSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken) + public override async Task GetLocationForSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken) { Debug.Assert(workspace is SemanticSearchWorkspace); Debug.Assert(documentId == window.SemanticSearchService.GetQueryDocumentId(workspace.CurrentSolution)); - return Task.FromResult(window.GetNavigableLocation(textSpan)); + return window.GetNavigableLocation(textSpan); } } diff --git a/src/VisualStudio/CSharp/Impl/SemanticSearch/SemanticSearchQueryExecutor.cs b/src/VisualStudio/CSharp/Impl/SemanticSearch/SemanticSearchQueryExecutor.cs index 3a26ad85af2c7..722533b98ac37 100644 --- a/src/VisualStudio/CSharp/Impl/SemanticSearch/SemanticSearchQueryExecutor.cs +++ b/src/VisualStudio/CSharp/Impl/SemanticSearch/SemanticSearchQueryExecutor.cs @@ -32,8 +32,8 @@ private sealed class ResultsObserver(IFindUsagesContext presenterContext, IOptio private readonly Lazy changes)>> _lazyDocumentUpdates = new(); private readonly Lazy> _lazyTextFileUpdates = new(); - public ValueTask GetClassificationOptionsAsync(Microsoft.CodeAnalysis.Host.LanguageServices language, CancellationToken cancellationToken) - => new(options.GetClassificationOptions(language.Language)); + public async ValueTask GetClassificationOptionsAsync(Microsoft.CodeAnalysis.Host.LanguageServices language, CancellationToken cancellationToken) + => options.GetClassificationOptions(language.Language); public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) => presenterContext.OnDefinitionFoundAsync(definition, cancellationToken); @@ -48,16 +48,14 @@ public ValueTask OnUserCodeExceptionAsync(UserCodeExceptionInfo exception, Cance => presenterContext.OnDefinitionFoundAsync( new SearchExceptionDefinitionItem(exception.Message, exception.TypeName, exception.StackTrace, (queryDocument != null) ? new DocumentSpan(queryDocument, exception.Span) : default), cancellationToken); - public ValueTask OnLogMessageAsync(string message, CancellationToken cancellationToken) + public async ValueTask OnLogMessageAsync(string message, CancellationToken cancellationToken) { logMessage(message); - return ValueTask.CompletedTask; } - public ValueTask OnDocumentUpdatedAsync(DocumentId documentId, ImmutableArray changes, CancellationToken cancellationToken) + public async ValueTask OnDocumentUpdatedAsync(DocumentId documentId, ImmutableArray changes, CancellationToken cancellationToken) { _lazyDocumentUpdates.Value.Push((documentId, changes)); - return ValueTask.CompletedTask; } private ImmutableArray<(DocumentId documentId, ImmutableArray changes)> GetDocumentUpdates() @@ -94,10 +92,9 @@ public async ValueTask GetUpdatedSolutionAsync(Solution oldSolution, C public ImmutableArray<(string filePath, string? newContent)> GetFileUpdates() => _lazyTextFileUpdates.IsValueCreated ? _lazyTextFileUpdates.Value.SelectAsArray(static entry => (entry.Key, entry.Value)) : []; - public ValueTask OnTextFileUpdatedAsync(string filePath, string? newContent, CancellationToken cancellationToken) + public async ValueTask OnTextFileUpdatedAsync(string filePath, string? newContent, CancellationToken cancellationToken) { _lazyTextFileUpdates.Value.TryAdd(filePath, newContent); - return ValueTask.CompletedTask; } } diff --git a/src/VisualStudio/CSharp/Test/EditorConfigSettings/DataProvider/DataProviderTests.MockAnalyzerReference.cs b/src/VisualStudio/CSharp/Test/EditorConfigSettings/DataProvider/DataProviderTests.MockAnalyzerReference.cs index 4053e232c7efb..106809d623bef 100644 --- a/src/VisualStudio/CSharp/Test/EditorConfigSettings/DataProvider/DataProviderTests.MockAnalyzerReference.cs +++ b/src/VisualStudio/CSharp/Test/EditorConfigSettings/DataProvider/DataProviderTests.MockAnalyzerReference.cs @@ -60,11 +60,10 @@ public sealed class MockFixer : CodeFixProvider public sealed override ImmutableArray FixableDiagnosticIds => [Id]; - public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) + public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { Called = true; ContextDiagnosticsCount = context.Diagnostics.Length; - return Task.CompletedTask; } } diff --git a/src/VisualStudio/CSharp/Test/Interactive/Commands/TestResetInteractive.cs b/src/VisualStudio/CSharp/Test/Interactive/Commands/TestResetInteractive.cs index f5f66d2d47e1a..0ae05af549bb4 100644 --- a/src/VisualStudio/CSharp/Test/Interactive/Commands/TestResetInteractive.cs +++ b/src/VisualStudio/CSharp/Test/Interactive/Commands/TestResetInteractive.cs @@ -58,10 +58,10 @@ protected override void CancelBuildProject() CancelBuildProjectCount++; } - protected override Task BuildProjectAsync() + protected override async Task BuildProjectAsync() { BuildProjectCount++; - return Task.FromResult(_buildSucceeds); + return _buildSucceeds; } protected override bool GetProjectProperties( @@ -86,8 +86,8 @@ protected override IUIThreadOperationExecutor GetUIThreadOperationExecutor() return _uiThreadOperationExecutor; } - protected override Task> GetNamespacesToImportAsync(IEnumerable namespacesToImport, IInteractiveWindow interactiveWindow) + protected override async Task> GetNamespacesToImportAsync(IEnumerable namespacesToImport, IInteractiveWindow interactiveWindow) { - return Task.FromResult((IEnumerable)NamespacesToImport); + return (IEnumerable)NamespacesToImport; } } diff --git a/src/VisualStudio/CSharp/Test/Interactive/TestInteractiveEvaluator.cs b/src/VisualStudio/CSharp/Test/Interactive/TestInteractiveEvaluator.cs index 79e88ecdc01a8..6ea2d516987fc 100644 --- a/src/VisualStudio/CSharp/Test/Interactive/TestInteractiveEvaluator.cs +++ b/src/VisualStudio/CSharp/Test/Interactive/TestInteractiveEvaluator.cs @@ -23,19 +23,19 @@ public void Dispose() { } - public Task InitializeAsync() - => Task.FromResult(ExecutionResult.Success); + public async Task InitializeAsync() + => ExecutionResult.Success; - public Task ResetAsync(bool initialize = true) - => Task.FromResult(ExecutionResult.Success); + public async Task ResetAsync(bool initialize = true) + => ExecutionResult.Success; public bool CanExecuteCode(string text) => true; - public Task ExecuteCodeAsync(string text) + public async Task ExecuteCodeAsync(string text) { OnExecute?.Invoke(this, text); - return Task.FromResult(ExecutionResult.Success); + return ExecutionResult.Success; } public string FormatClipboard() diff --git a/src/VisualStudio/CodeLens/ReferenceCodeLensProvider.cs b/src/VisualStudio/CodeLens/ReferenceCodeLensProvider.cs index a6d07c92f40a3..ca8ec5fe83a30 100644 --- a/src/VisualStudio/CodeLens/ReferenceCodeLensProvider.cs +++ b/src/VisualStudio/CodeLens/ReferenceCodeLensProvider.cs @@ -62,20 +62,20 @@ public void Dispose() _cancellationTokenSource.Cancel(); } - public Task CanCreateDataPointAsync( + public async Task CanCreateDataPointAsync( CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken) { if (descriptorContext != null && descriptorContext.ApplicableSpan.HasValue) { // we allow all reference points. // engine will call this for all points our roslyn code lens (reference) tagger tagged. - return SpecializedTasks.True; + return true; } - return SpecializedTasks.False; + return false; } - public Task CreateDataPointAsync( + public async Task CreateDataPointAsync( CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken) { var dataPoint = new DataPoint( @@ -84,7 +84,7 @@ public Task CreateDataPointAsync( descriptor); AddDataPoint(dataPoint); - return Task.FromResult(dataPoint); + return dataPoint; } // The current CodeLens OOP design does not allow us to register an event handler for WorkspaceChanged events diff --git a/src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs b/src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs index 80d620c98b01b..e35b9a87b5fa8 100644 --- a/src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs +++ b/src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs @@ -136,23 +136,23 @@ private async Task FixHierarchyContentAsync(IVsHierarchyCodeCleanupScope h return false; } - private Task FixTextBufferAsync(TextBufferCodeCleanUpScope textBufferScope, ICodeCleanUpExecutionContext context) + private async Task FixTextBufferAsync(TextBufferCodeCleanUpScope textBufferScope, ICodeCleanUpExecutionContext context) { var buffer = textBufferScope.SubjectBuffer; // Let LSP handle code cleanup in the cloud scenario if (buffer.IsInLspEditorContext()) - return SpecializedTasks.False; + return false; var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document == null) - return SpecializedTasks.False; + return false; var workspace = buffer.GetWorkspace(); if (workspace is not VisualStudioWorkspace visualStudioWorkspace) - return SpecializedTasks.False; + return false; - return FixAsync(visualStudioWorkspace, ApplyFixAsync, context); + return await FixAsync(visualStudioWorkspace, ApplyFixAsync, context).ConfigureAwait(false); // Local function async Task ApplyFixAsync(IProgress progress, CancellationToken cancellationToken) diff --git a/src/VisualStudio/Core/Def/DesignerAttribute/VisualStudioDesignerAttributeService.cs b/src/VisualStudio/Core/Def/DesignerAttribute/VisualStudioDesignerAttributeService.cs index 19186ff2d2b4e..73ba63b7daec3 100644 --- a/src/VisualStudio/Core/Def/DesignerAttribute/VisualStudioDesignerAttributeService.cs +++ b/src/VisualStudio/Core/Def/DesignerAttribute/VisualStudioDesignerAttributeService.cs @@ -311,10 +311,9 @@ private static async Task NotifyCpsProjectSystemAsync( /// /// Callback from the OOP service back into us. /// - public ValueTask ReportDesignerAttributeDataAsync(ImmutableArray data, CancellationToken cancellationToken) + public async ValueTask ReportDesignerAttributeDataAsync(ImmutableArray data, CancellationToken cancellationToken) { Contract.ThrowIfNull(_projectSystemNotificationQueue); _projectSystemNotificationQueue.AddWork(data.AsSpan()); - return ValueTask.CompletedTask; } } diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/DataProvider/CodeStyle/CommonCodeStyleSettingsProvider.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/DataProvider/CodeStyle/CommonCodeStyleSettingsProvider.cs index 2852da33b13b2..7d21208d1d50e 100644 --- a/src/VisualStudio/Core/Def/EditorConfigSettings/DataProvider/CodeStyle/CommonCodeStyleSettingsProvider.cs +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/DataProvider/CodeStyle/CommonCodeStyleSettingsProvider.cs @@ -29,7 +29,7 @@ public CommonCodeStyleSettingsProvider( Update(); } - protected override Task UpdateOptionsAsync( + protected override async Task UpdateOptionsAsync( TieredAnalyzerConfigOptions options, ImmutableArray projectsInScope, CancellationToken cancellationToken) { var qualifySettings = GetQualifyCodeStyleOptions(options, SettingsUpdater); @@ -60,8 +60,6 @@ protected override Task UpdateOptionsAsync( var experimentalSettings = GetExperimentalCodeStyleOptions(options, SettingsUpdater); AddRange(experimentalSettings); - - return Task.CompletedTask; } private static IEnumerable GetQualifyCodeStyleOptions(TieredAnalyzerConfigOptions options, OptionUpdater updater) diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/DataProvider/Whitespace/CommonWhitespaceSettingsProvider.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/DataProvider/Whitespace/CommonWhitespaceSettingsProvider.cs index 24e48ecd29ad2..78c6ba5e89f40 100644 --- a/src/VisualStudio/Core/Def/EditorConfigSettings/DataProvider/Whitespace/CommonWhitespaceSettingsProvider.cs +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/DataProvider/Whitespace/CommonWhitespaceSettingsProvider.cs @@ -29,13 +29,11 @@ public CommonWhitespaceSettingsProvider( Update(); } - protected override Task UpdateOptionsAsync( + protected override async Task UpdateOptionsAsync( TieredAnalyzerConfigOptions options, ImmutableArray projectsInScope, CancellationToken cancellationToken) { var defaultOptions = GetDefaultOptions(options, SettingsUpdater); AddRange(defaultOptions); - - return Task.CompletedTask; } private static IEnumerable GetDefaultOptions(TieredAnalyzerConfigOptions options, OptionUpdater updater) diff --git a/src/VisualStudio/Core/Def/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index c04271ba7a0ed..6e01e15b6e529 100644 --- a/src/VisualStudio/Core/Def/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -170,10 +170,9 @@ protected AbstractTableDataSourceFindUsagesContext( // results). To limit the amount of work we do, we'll only update the window every 250ms. _notifyQueue = new AsyncBatchingWorkQueue( DelayTimeSpan.Short, - cancellationToken => + async cancellationToken => { _tableDataSink.FactorySnapshotChanged(this); - return ValueTask.CompletedTask; }, presenter._asyncListener, CancellationTokenSource.Token); @@ -346,11 +345,10 @@ public IDisposable Subscribe(ITableDataSink sink) #region FindUsagesContext overrides. - public sealed override ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) + public sealed override async ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) { // Note: IFindAllReferenceWindow.Title is safe to set from any thread. _findReferencesWindow.Title = title; - return default; } public sealed override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) @@ -528,14 +526,12 @@ protected RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem defi } } - public sealed override ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken) + public sealed override async ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken) { lock (Gate) { NoDefinitionsFoundMessage = message; } - - return ValueTask.CompletedTask; } public sealed override async ValueTask ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken) @@ -543,13 +539,12 @@ public sealed override async ValueTask ReportMessageAsync(string message, Notifi await this.Presenter.ReportMessageAsync(message, severity, cancellationToken).ConfigureAwait(false); } - protected sealed override ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken) + protected sealed override async ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken) { _progressQueue.AddWork((current, maximum)); - return default; } - private ValueTask UpdateTableProgressAsync(ImmutableSegmentedList<(int current, int maximum)> nextBatch, CancellationToken _) + private async ValueTask UpdateTableProgressAsync(ImmutableSegmentedList<(int current, int maximum)> nextBatch, CancellationToken _) { if (!nextBatch.IsEmpty) { @@ -568,8 +563,6 @@ private ValueTask UpdateTableProgressAsync(ImmutableSegmentedList<(int current, if (current > 0) _findReferencesWindow.SetProgress(current, maximum); } - - return ValueTask.CompletedTask; } protected static DefinitionItem CreateNoResultsDefinitionItem(string message) diff --git a/src/VisualStudio/Core/Def/FindReferences/Entries/SimpleMessageEntry.cs b/src/VisualStudio/Core/Def/FindReferences/Entries/SimpleMessageEntry.cs index 3265dc00db67a..8454642f154fa 100644 --- a/src/VisualStudio/Core/Def/FindReferences/Entries/SimpleMessageEntry.cs +++ b/src/VisualStudio/Core/Def/FindReferences/Entries/SimpleMessageEntry.cs @@ -27,13 +27,13 @@ private SimpleMessageEntry( _message = message; } - public static Task CreateAsync( + public static async Task CreateAsync( RoslynDefinitionBucket definitionBucket, RoslynDefinitionBucket? navigationBucket, string message) { var referenceEntry = new SimpleMessageEntry(definitionBucket, navigationBucket, message); - return Task.FromResult(referenceEntry); + return referenceEntry; } protected override object? GetValueWorker(string keyName) diff --git a/src/VisualStudio/Core/Def/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index a87b2b42ce545..bfcf4b7c7458e 100644 --- a/src/VisualStudio/Core/Def/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -28,7 +28,7 @@ internal sealed class VisualStudioDefinitionsAndReferencesFactory( SVsServiceProvider serviceProvider, IThreadingContext threadingContext) : IExternalDefinitionItemProvider { - public async Task GetThirdPartyDefinitionItemAsync( + public async ValueTask GetThirdPartyDefinitionItemAsync( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) { var symbolNavigationService = solution.Services.GetRequiredService(); @@ -89,13 +89,13 @@ private sealed class ExternalDefinitionItem( { internal override bool IsExternal => true; - public override Task GetNavigableLocationAsync(Workspace workspace, CancellationToken cancellationToken) + public override async Task GetNavigableLocationAsync(Workspace workspace, CancellationToken cancellationToken) { - return Task.FromResult(new NavigableLocation(async (options, cancellationToken) => + return new NavigableLocation(async (options, cancellationToken) => { await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); return TryOpenFile() && TryNavigateToPosition(); - })); + }); } private bool TryOpenFile() diff --git a/src/VisualStudio/Core/Def/Library/AbstractObjectList.cs b/src/VisualStudio/Core/Def/Library/AbstractObjectList.cs index 73912910b0280..c084a223528f2 100644 --- a/src/VisualStudio/Core/Def/Library/AbstractObjectList.cs +++ b/src/VisualStudio/Core/Def/Library/AbstractObjectList.cs @@ -62,8 +62,8 @@ protected virtual bool TryGetContextMenu(uint index, out Guid menuGuid, out int return false; } - protected virtual Task<(bool success, object pvar)> TryGetPropertyAsync(uint index, _VSOBJLISTELEMPROPID propertyId, CancellationToken cancellationToken) - => SpecializedTasks.Default<(bool success, object pvar)>(); + protected virtual async Task<(bool success, object pvar)> TryGetPropertyAsync(uint index, _VSOBJLISTELEMPROPID propertyId, CancellationToken cancellationToken) + => default((bool success, object pvar)); protected virtual bool TryCountSourceItems(uint index, out IVsHierarchy hierarchy, out uint itemid, out uint items) { @@ -73,16 +73,16 @@ protected virtual bool TryCountSourceItems(uint index, out IVsHierarchy hierarch return false; } - protected virtual Task GetBrowseObjectAsync(uint index, CancellationToken cancellationToken) - => SpecializedTasks.Null(); + protected virtual async Task GetBrowseObjectAsync(uint index, CancellationToken cancellationToken) + => null; protected virtual bool SupportsNavInfo { get { return false; } } - protected virtual Task GetNavInfoAsync(uint index, CancellationToken cancellationToken) - => SpecializedTasks.Null(); + protected virtual async Task GetNavInfoAsync(uint index, CancellationToken cancellationToken) + => null; protected virtual IVsNavInfoNode GetNavInfoNode(uint index) => null; @@ -98,8 +98,8 @@ protected virtual bool SupportsDescription get { return false; } } - protected virtual Task TryFillDescriptionAsync(uint index, _VSOBJDESCOPTIONS options, IVsObjectBrowserDescription3 description, CancellationToken cancellationToken) - => SpecializedTasks.False; + protected virtual async Task TryFillDescriptionAsync(uint index, _VSOBJDESCOPTIONS options, IVsObjectBrowserDescription3 description, CancellationToken cancellationToken) + => false; int IVsSimpleObjectList2.CanDelete(uint index, out int pfOK) { diff --git a/src/VisualStudio/Core/Def/NavigateTo/RoslynSearchResultPreviewPanel.cs b/src/VisualStudio/Core/Def/NavigateTo/RoslynSearchResultPreviewPanel.cs index 535834ed445cc..e83ee7bbfbd1e 100644 --- a/src/VisualStudio/Core/Def/NavigateTo/RoslynSearchResultPreviewPanel.cs +++ b/src/VisualStudio/Core/Def/NavigateTo/RoslynSearchResultPreviewPanel.cs @@ -34,8 +34,8 @@ public RoslynSearchResultPreviewPanel( UserInterface = new CodeEditorModel( nameof(RoslynSearchResultPreviewPanel), - new VisualStudio.Threading.AsyncLazy(() => - Task.FromResult(new TextDocumentLocation(uri, projectGuid, span)), + new VisualStudio.Threading.AsyncLazy(async () => + new TextDocumentLocation(uri, projectGuid, span), provider._threadingContext.JoinableTaskFactory), isEditable: true); } diff --git a/src/VisualStudio/Core/Def/NavigateTo/RoslynSearchResultViewFactory.cs b/src/VisualStudio/Core/Def/NavigateTo/RoslynSearchResultViewFactory.cs index 93cb5c7e78da9..b96e6cae4ec5b 100644 --- a/src/VisualStudio/Core/Def/NavigateTo/RoslynSearchResultViewFactory.cs +++ b/src/VisualStudio/Core/Def/NavigateTo/RoslynSearchResultViewFactory.cs @@ -42,8 +42,8 @@ [.. searchResult.NameMatchSpans.NullToEmpty().Select(m => m.ToSpan())]), primaryIcon: searchResult.NavigableItem.Glyph.GetImageId()); } - public Task> GetPreviewPanelsAsync(SearchResult result, SearchResultViewBase searchResultView) - => Task.FromResult(GetPreviewPanels(result, searchResultView) ?? []); + public async Task> GetPreviewPanelsAsync(SearchResult result, SearchResultViewBase searchResultView) + => GetPreviewPanels(result, searchResultView) ?? []; private IReadOnlyList? GetPreviewPanels(SearchResult result, SearchResultViewBase searchResultView) { diff --git a/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs b/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs index ff484050603e9..ed8884cf6391f 100644 --- a/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs +++ b/src/VisualStudio/Core/Def/Options/VisualStudioOptionStorage.cs @@ -107,10 +107,9 @@ public FeatureFlagStorage(string flagName) FlagName = flagName; } - public Task PersistAsync(FeatureFlagPersister persister, object? value) + public async Task PersistAsync(FeatureFlagPersister persister, object? value) { persister.Persist(FlagName, value); - return Task.CompletedTask; } public bool TryFetch(FeatureFlagPersister persister, OptionKey2 optionKey, out object? value) @@ -122,10 +121,9 @@ internal sealed class LocalUserProfileStorage(string path, string key) : VisualS public string Path => path; public string Key => key; - public Task PersistAsync(LocalUserRegistryOptionPersister persister, OptionKey2 optionKey, object? value) + public async Task PersistAsync(LocalUserRegistryOptionPersister persister, OptionKey2 optionKey, object? value) { persister.Persist(optionKey, path, key, value); - return Task.CompletedTask; } public bool TryFetch(LocalUserRegistryOptionPersister persister, OptionKey2 optionKey, out object? value) diff --git a/src/VisualStudio/Core/Def/Options/VisualStudioSettingsOptionPersister.cs b/src/VisualStudio/Core/Def/Options/VisualStudioSettingsOptionPersister.cs index 80621591e11b1..5fedc87541e58 100644 --- a/src/VisualStudio/Core/Def/Options/VisualStudioSettingsOptionPersister.cs +++ b/src/VisualStudio/Core/Def/Options/VisualStudioSettingsOptionPersister.cs @@ -40,12 +40,11 @@ public VisualStudioSettingsOptionPersister( settingsSubset.SettingChangedAsync += OnSettingChangedAsync; } - private Task OnSettingChangedAsync(object sender, PropertyChangedEventArgs args) + private async Task OnSettingChangedAsync(object sender, PropertyChangedEventArgs args) { Contract.ThrowIfNull(this.SettingsManager); RefreshIfTracked(args.PropertyName); - return Task.CompletedTask; } public override bool TryFetch(OptionKey2 optionKey, string storageKey, out object? value) diff --git a/src/VisualStudio/Core/Def/Options/VisualStudioUnifiedSettingsOptionPersister.cs b/src/VisualStudio/Core/Def/Options/VisualStudioUnifiedSettingsOptionPersister.cs index 78ee53c51950a..ccb8b50bdd35f 100644 --- a/src/VisualStudio/Core/Def/Options/VisualStudioUnifiedSettingsOptionPersister.cs +++ b/src/VisualStudio/Core/Def/Options/VisualStudioUnifiedSettingsOptionPersister.cs @@ -50,7 +50,7 @@ private static void CheckStorageKeyAndType(string storageKey, [NotNull] Type? st optionKey.Option.Definition.Serializer.TryParse(stringValue, out var value) ? new(value) : default; } - public override Task PersistAsync(OptionKey2 optionKey, string storageKey, object? value) + public override async Task PersistAsync(OptionKey2 optionKey, string storageKey, object? value) { var storageType = value?.GetType(); CheckStorageKeyAndType(storageKey, storageType); @@ -65,7 +65,5 @@ public override Task PersistAsync(OptionKey2 optionKey, string storageKey, objec // ignoreCase: true, out result)` writer.EnqueueChange(storageKey, optionKey.Option.Definition.Serializer.Serialize(value).ToLowerInvariant()); writer.RequestCommit(nameof(VisualStudioUnifiedSettingsOptionPersister)); - - return Task.CompletedTask; } } diff --git a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs index de3f3b67b6b30..edb29c3e9778e 100644 --- a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs +++ b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs @@ -453,7 +453,7 @@ private void OnWorkspaceChanged(WorkspaceChangeEventArgs e) _workQueue.AddWork((solutionChanged, changedProject)); } - private ValueTask ProcessWorkQueueAsync( + private async ValueTask ProcessWorkQueueAsync( ImmutableSegmentedList<(bool solutionChanged, ProjectId? changedProject)> workQueue, CancellationToken cancellationToken) { // ThisCanBeCalledOnAnyThread(); @@ -462,9 +462,9 @@ private ValueTask ProcessWorkQueueAsync( // If we've been disconnected, then there's no point proceeding. if (Workspace == null || !IsEnabled) - return ValueTask.CompletedTask; + return; - return ProcessWorkQueueWorkerAsync(workQueue, cancellationToken); + await ProcessWorkQueueWorkerAsync(workQueue, cancellationToken).ConfigureAwait(false); } [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/src/VisualStudio/Core/Def/Preview/PreviewUpdater.PreviewDialogWorkspace.cs b/src/VisualStudio/Core/Def/Preview/PreviewUpdater.PreviewDialogWorkspace.cs index 52c0c30ceae6b..59f68767ae082 100644 --- a/src/VisualStudio/Core/Def/Preview/PreviewUpdater.PreviewDialogWorkspace.cs +++ b/src/VisualStudio/Core/Def/Preview/PreviewUpdater.PreviewDialogWorkspace.cs @@ -47,8 +47,8 @@ private sealed class PreviewTextLoader : TextLoader internal PreviewTextLoader(SourceText documentText) => _text = documentText; - public override Task LoadTextAndVersionAsync(LoadTextOptions options, CancellationToken cancellationToken) - => Task.FromResult(LoadTextAndVersionSynchronously(options, cancellationToken)); + public override async Task LoadTextAndVersionAsync(LoadTextOptions options, CancellationToken cancellationToken) + => LoadTextAndVersionSynchronously(options, cancellationToken); internal override TextAndVersion LoadTextAndVersionSynchronously(LoadTextOptions options, CancellationToken cancellationToken) => TextAndVersion.Create(_text, VersionStamp.Create()); diff --git a/src/VisualStudio/Core/Def/Progression/GraphNodeCreation.cs b/src/VisualStudio/Core/Def/Progression/GraphNodeCreation.cs index 60076ab449d24..792d49bff8b0d 100644 --- a/src/VisualStudio/Core/Def/Progression/GraphNodeCreation.cs +++ b/src/VisualStudio/Core/Def/Progression/GraphNodeCreation.cs @@ -14,10 +14,10 @@ namespace Microsoft.VisualStudio.LanguageServices.Progression; public static class GraphNodeCreation { [Obsolete("This method is not implemented and always returns an empty GraphNodeId.", error: true)] - public static Task CreateNodeIdAsync(ISymbol symbol, Solution solution, CancellationToken cancellationToken) - => Task.FromResult(GraphNodeId.Empty); + public static async Task CreateNodeIdAsync(ISymbol symbol, Solution solution, CancellationToken cancellationToken) + => GraphNodeId.Empty; [Obsolete("This method is not implemented and always returns an empty GraphNode.", error: true)] - public static Task CreateNodeAsync(this Graph graph, ISymbol symbol, Solution solution, CancellationToken cancellationToken) - => Task.FromResult(graph.Nodes.GetOrCreate(GraphNodeId.Empty)); + public static async Task CreateNodeAsync(this Graph graph, ISymbol symbol, Solution solution, CancellationToken cancellationToken) + => graph.Nodes.GetOrCreate(GraphNodeId.Empty); } diff --git a/src/VisualStudio/Core/Def/ProjectSystem/BrokeredService/WorkspaceProject.cs b/src/VisualStudio/Core/Def/ProjectSystem/BrokeredService/WorkspaceProject.cs index c87c7e3861576..aa7379ad6001f 100644 --- a/src/VisualStudio/Core/Def/ProjectSystem/BrokeredService/WorkspaceProject.cs +++ b/src/VisualStudio/Core/Def/ProjectSystem/BrokeredService/WorkspaceProject.cs @@ -163,22 +163,19 @@ public async Task SetBuildSystemPropertiesAsync(IReadOnlyDictionary arguments, CancellationToken cancellationToken) + public async Task SetCommandLineArgumentsAsync(IReadOnlyList arguments, CancellationToken cancellationToken) { _project.SetOptions([.. arguments]); - return Task.CompletedTask; } - public Task SetDisplayNameAsync(string displayName, CancellationToken cancellationToken) + public async Task SetDisplayNameAsync(string displayName, CancellationToken cancellationToken) { _project.DisplayName = displayName; - return Task.CompletedTask; } - public Task SetProjectHasAllInformationAsync(bool hasAllInformation, CancellationToken cancellationToken) + public async Task SetProjectHasAllInformationAsync(bool hasAllInformation, CancellationToken cancellationToken) { _project.LastDesignTimeBuildSucceeded = hasAllInformation; - return Task.CompletedTask; } public async Task StartBatchAsync(CancellationToken cancellationToken) diff --git a/src/VisualStudio/Core/Def/ProjectSystem/BrokeredService/WorkspaceProjectFactoryService.cs b/src/VisualStudio/Core/Def/ProjectSystem/BrokeredService/WorkspaceProjectFactoryService.cs index 57744b19a71e8..c3058230d6a86 100644 --- a/src/VisualStudio/Core/Def/ProjectSystem/BrokeredService/WorkspaceProjectFactoryService.cs +++ b/src/VisualStudio/Core/Def/ProjectSystem/BrokeredService/WorkspaceProjectFactoryService.cs @@ -34,9 +34,9 @@ public async Task CreateAndAddProjectAsync(WorkspaceProjectCr return new WorkspaceProject(project); } - public Task> GetSupportedBuildSystemPropertiesAsync(CancellationToken cancellationToken) + public async Task> GetSupportedBuildSystemPropertiesAsync(CancellationToken cancellationToken) { - return Task.FromResult((IReadOnlyCollection)_workspaceProjectContextFactory.EvaluationItemNames); + return (IReadOnlyCollection)_workspaceProjectContextFactory.EvaluationItemNames; } private sealed class EvaluationDataShim : EvaluationData diff --git a/src/VisualStudio/Core/Def/ProjectSystem/Legacy/SolutionEventsBatchScopeCreator.cs b/src/VisualStudio/Core/Def/ProjectSystem/Legacy/SolutionEventsBatchScopeCreator.cs index 0816942fef4c1..60f09078ded3a 100644 --- a/src/VisualStudio/Core/Def/ProjectSystem/Legacy/SolutionEventsBatchScopeCreator.cs +++ b/src/VisualStudio/Core/Def/ProjectSystem/Legacy/SolutionEventsBatchScopeCreator.cs @@ -205,24 +205,20 @@ public void OnUnhandledException(Exception exception) { } - public ValueTask OnBeforeOpenSolutionAsync(BeforeOpenSolutionArgs args, CancellationToken cancellationToken) + public async ValueTask OnBeforeOpenSolutionAsync(BeforeOpenSolutionArgs args, CancellationToken cancellationToken) { - return ValueTask.CompletedTask; } - public ValueTask OnBeforeCloseSolutionAsync(BeforeCloseSolutionArgs args, CancellationToken cancellationToken) + public async ValueTask OnBeforeCloseSolutionAsync(BeforeCloseSolutionArgs args, CancellationToken cancellationToken) { - return ValueTask.CompletedTask; } - public ValueTask OnAfterCloseSolutionAsync(AfterCloseSolutionArgs args, CancellationToken cancellationToken) + public async ValueTask OnAfterCloseSolutionAsync(AfterCloseSolutionArgs args, CancellationToken cancellationToken) { - return ValueTask.CompletedTask; } - public ValueTask OnAfterRenameSolutionAsync(AfterRenameSolutionArgs args, CancellationToken cancellationToken) + public async ValueTask OnAfterRenameSolutionAsync(AfterRenameSolutionArgs args, CancellationToken cancellationToken) { - return ValueTask.CompletedTask; } #endregion diff --git a/src/VisualStudio/Core/Def/Remote/DefaultRemoteHostClientProvider.cs b/src/VisualStudio/Core/Def/Remote/DefaultRemoteHostClientProvider.cs index 7635e1501ad77..2b7535c58d492 100644 --- a/src/VisualStudio/Core/Def/Remote/DefaultRemoteHostClientProvider.cs +++ b/src/VisualStudio/Core/Def/Remote/DefaultRemoteHostClientProvider.cs @@ -14,8 +14,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Remote; [method: Obsolete(MefConstruction.FactoryMethodMessage, error: true)] internal sealed class DefaultRemoteHostClientProvider() : IRemoteHostClientProvider { - public Task TryGetRemoteHostClientAsync(CancellationToken cancellationToken) - => SpecializedTasks.Null(); + public async Task TryGetRemoteHostClientAsync(CancellationToken cancellationToken) + => null; public Task WaitForClientCreationAsync(CancellationToken cancellationToken) => Task.CompletedTask; diff --git a/src/VisualStudio/Core/Def/Remote/VisualStudioRemoteHostClientProvider.cs b/src/VisualStudio/Core/Def/Remote/VisualStudioRemoteHostClientProvider.cs index 0eddc78a8298e..4cea589e1061d 100644 --- a/src/VisualStudio/Core/Def/Remote/VisualStudioRemoteHostClientProvider.cs +++ b/src/VisualStudio/Core/Def/Remote/VisualStudioRemoteHostClientProvider.cs @@ -139,7 +139,7 @@ private VisualStudioRemoteHostClientProvider( var client = await ServiceHubRemoteHostClient.CreateAsync(Services, configuration, localSettingsDirectory, _listenerProvider, serviceBroker, _callbackDispatchers, _threadingContext.DisposalToken).ConfigureAwait(false); // proffer in-proc brokered services: - _ = brokeredServiceContainer.Proffer(SolutionAssetProvider.ServiceDescriptor, (_, _, _, _) => ValueTask.FromResult(new SolutionAssetProvider(Services))); + _ = brokeredServiceContainer.Proffer(SolutionAssetProvider.ServiceDescriptor, async (_, _, _, _) => new SolutionAssetProvider(Services)); return client; } diff --git a/src/VisualStudio/Core/Def/RoslynPackage.cs b/src/VisualStudio/Core/Def/RoslynPackage.cs index 8c26bfde24b1b..66bc4d81a3dc5 100644 --- a/src/VisualStudio/Core/Def/RoslynPackage.cs +++ b/src/VisualStudio/Core/Def/RoslynPackage.cs @@ -86,12 +86,10 @@ protected override void RegisterOnAfterPackageLoadedAsyncWork(PackageLoadTasks a return; - Task OnAfterPackageLoadedMainThreadAsync(PackageLoadTasks afterPackageLoadedTasks, CancellationToken cancellationToken) + async Task OnAfterPackageLoadedMainThreadAsync(PackageLoadTasks afterPackageLoadedTasks, CancellationToken cancellationToken) { // load some services that have to be loaded in UI thread LoadComponentsInUIContextOnceSolutionFullyLoadedAsync(cancellationToken).Forget(); - - return Task.CompletedTask; } } @@ -102,12 +100,12 @@ private async Task ProfferServiceBrokerServicesAsync(CancellationToken cancellat serviceBrokerContainer.Proffer( WorkspaceProjectFactoryServiceDescriptor.ServiceDescriptor, - (_, _, _, _) => ValueTask.FromResult(new WorkspaceProjectFactoryService(this.ComponentModel.GetService()))); + async (_, _, _, _) => new WorkspaceProjectFactoryService(this.ComponentModel.GetService())); // Must be profferred before any C#/VB projects are loaded and the corresponding UI context activated. serviceBrokerContainer.Proffer( ManagedHotReloadLanguageServiceDescriptor.Descriptor, - (_, _, _, _) => ValueTask.FromResult(new ManagedEditAndContinueLanguageServiceBridge(this.ComponentModel.GetService()))); + async (_, _, _, _) => new ManagedEditAndContinueLanguageServiceBridge(this.ComponentModel.GetService())); } protected override async Task LoadComponentsAsync(CancellationToken cancellationToken) @@ -148,8 +146,8 @@ public override IVsAsyncToolWindowFactory GetAsyncToolWindowFactory(Guid toolWin protected override string GetToolWindowTitle(Type toolWindowType, int id) => base.GetToolWindowTitle(toolWindowType, id); - protected override Task InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken) - => Task.FromResult((object?)null); + protected override async Task InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken) + => (object?)null; private async Task LoadComponentsBackgroundAsync(CancellationToken cancellationToken) { diff --git a/src/VisualStudio/Core/Def/Snippets/SnippetFunctions/AbstractSnippetFunction.cs b/src/VisualStudio/Core/Def/Snippets/SnippetFunctions/AbstractSnippetFunction.cs index 2a23e190ab946..46cb0b4f3f452 100644 --- a/src/VisualStudio/Core/Def/Snippets/SnippetFunctions/AbstractSnippetFunction.cs +++ b/src/VisualStudio/Core/Def/Snippets/SnippetFunctions/AbstractSnippetFunction.cs @@ -35,9 +35,9 @@ private int GetDefaultValue(CancellationToken cancellationToken, out string valu return exitCode; } - protected virtual Task<(int ExitCode, string Value, int HasDefaultValue)> GetDefaultValueAsync(CancellationToken cancellationToken) + protected virtual async Task<(int ExitCode, string Value, int HasDefaultValue)> GetDefaultValueAsync(CancellationToken cancellationToken) { - return Task.FromResult((ExitCode: VSConstants.S_OK, Value: string.Empty, HasDefaultValue: 0)); + return (ExitCode: VSConstants.S_OK, Value: string.Empty, HasDefaultValue: 0); } private int GetCurrentValue(CancellationToken cancellationToken, out string value, out int hasCurrentValue) @@ -46,9 +46,9 @@ private int GetCurrentValue(CancellationToken cancellationToken, out string valu return exitCode; } - protected virtual Task<(int ExitCode, string Value, int HasCurrentValue)> GetCurrentValueAsync(CancellationToken cancellationToken) + protected virtual async Task<(int ExitCode, string Value, int HasCurrentValue)> GetCurrentValueAsync(CancellationToken cancellationToken) { - return Task.FromResult((ExitCode: VSConstants.S_OK, Value: string.Empty, HasDefaultValue: 0)); + return (ExitCode: VSConstants.S_OK, Value: string.Empty, HasCurrentValue: 0); } protected virtual int FieldChanged(string field, out int requeryFunction) diff --git a/src/VisualStudio/Core/Def/Telemetry/FileLogger.cs b/src/VisualStudio/Core/Def/Telemetry/FileLogger.cs index 8be4ed4130e4d..9fca096e7f9eb 100644 --- a/src/VisualStudio/Core/Def/Telemetry/FileLogger.cs +++ b/src/VisualStudio/Core/Def/Telemetry/FileLogger.cs @@ -93,7 +93,7 @@ public void LogBlockEnd(FunctionId functionId, LogMessage logMessage, int unique private void LogBlockEvent(FunctionId functionId, LogMessage logMessage, int uniquePairId, string blockEvent) => Log(functionId, $"[{blockEvent} - {uniquePairId}] {logMessage.GetMessage()}"); - private ValueTask ProcessWorkQueueAsync( + private async ValueTask ProcessWorkQueueAsync( ImmutableSegmentedList<(FunctionId functionId, string message)> list, CancellationToken cancellationToken) { using var _ = PooledStringBuilder.GetInstance(out var buffer); @@ -109,7 +109,5 @@ private ValueTask ProcessWorkQueueAsync( File.AppendAllText(_logFilePath, buffer.ToString()); }); - - return ValueTask.CompletedTask; } } diff --git a/src/VisualStudio/Core/Def/Utilities/VisualStudioNavigateToLinkService.cs b/src/VisualStudio/Core/Def/Utilities/VisualStudioNavigateToLinkService.cs index d3f2763c361c1..6f7ace14ca6f1 100644 --- a/src/VisualStudio/Core/Def/Utilities/VisualStudioNavigateToLinkService.cs +++ b/src/VisualStudio/Core/Def/Utilities/VisualStudioNavigateToLinkService.cs @@ -13,30 +13,25 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Utilities; -[ExportWorkspaceService(typeof(INavigateToLinkService), layer: ServiceLayer.Host)] -[Shared] -internal sealed class VisualStudioNavigateToLinkService : INavigateToLinkService +[ExportWorkspaceService(typeof(INavigateToLinkService), layer: ServiceLayer.Host), Shared] +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class VisualStudioNavigateToLinkService() : INavigateToLinkService { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public VisualStudioNavigateToLinkService() - { - } - - public Task TryNavigateToLinkAsync(Uri uri, CancellationToken cancellationToken) + public async Task TryNavigateToLinkAsync(Uri uri, CancellationToken cancellationToken) { if (!uri.IsAbsoluteUri) { - return SpecializedTasks.False; + return false; } if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) { - return SpecializedTasks.False; + return false; } StartBrowser(uri); - return SpecializedTasks.True; + return true; } public static void StartBrowser(string uri) diff --git a/src/VisualStudio/Core/Def/Workspace/VisualStudioDocumentNavigationService.cs b/src/VisualStudio/Core/Def/Workspace/VisualStudioDocumentNavigationService.cs index 016b4abbb7254..5cf6d459f1bef 100644 --- a/src/VisualStudio/Core/Def/Workspace/VisualStudioDocumentNavigationService.cs +++ b/src/VisualStudio/Core/Def/Workspace/VisualStudioDocumentNavigationService.cs @@ -104,7 +104,7 @@ public async Task CanNavigateToPositionAsync( return await GetNavigableLocationAsync(workspace, documentId, - _ => Task.FromResult(textSpan), + async _ => textSpan, text => GetVsTextSpan(text, textSpan, allowInvalidSpan), (text, span) => GetVsTextSpan(text, span, allowInvalidSpan), cancellationToken).ConfigureAwait(false); diff --git a/src/VisualStudio/Core/Impl/SolutionExplorer/Search/RoslynSolutionExplorerSearchProvider.cs b/src/VisualStudio/Core/Impl/SolutionExplorer/Search/RoslynSolutionExplorerSearchProvider.cs index a8f92c1f8fcba..a8b3732cb9817 100644 --- a/src/VisualStudio/Core/Impl/SolutionExplorer/Search/RoslynSolutionExplorerSearchProvider.cs +++ b/src/VisualStudio/Core/Impl/SolutionExplorer/Search/RoslynSolutionExplorerSearchProvider.cs @@ -80,7 +80,7 @@ public void Done(bool isFullyLoaded) { } public void ReportIncomplete() { } public void ReportProgress(int current, int maximum) { } - public Task AddResultsAsync( + public async Task AddResultsAsync( ImmutableArray results, Document? activeDocument, CancellationToken cancellationToken) @@ -92,8 +92,6 @@ public Task AddResultsAsync( var imageMoniker = result.NavigableItem.Glyph.GetImageMoniker(); resultAccumulator(new SolutionExplorerSearchResult(provider, result, name, imageMoniker)); } - - return Task.CompletedTask; } } diff --git a/src/VisualStudio/Core/Test.Next/Options/VisualStudioSettingsOptionPersisterTests.cs b/src/VisualStudio/Core/Test.Next/Options/VisualStudioSettingsOptionPersisterTests.cs index a8297d3514aa7..11a57f570272d 100644 --- a/src/VisualStudio/Core/Test.Next/Options/VisualStudioSettingsOptionPersisterTests.cs +++ b/src/VisualStudio/Core/Test.Next/Options/VisualStudioSettingsOptionPersisterTests.cs @@ -48,10 +48,9 @@ public GetValueResult TryGetValue(string name, out T value) return result; } - public Task SetValueAsync(string name, object? value, bool isMachineLocal) + public async Task SetValueAsync(string name, object? value, bool isMachineLocal) { SetValueImpl?.Invoke(name, value); - return Task.CompletedTask; } public ISettingsList GetOrCreateList(string name, bool isMachineLocal) diff --git a/src/VisualStudio/Core/Test.Next/Services/AssetProviderTests.cs b/src/VisualStudio/Core/Test.Next/Services/AssetProviderTests.cs index 2cd8b39d186c6..dad61ba775c3e 100644 --- a/src/VisualStudio/Core/Test.Next/Services/AssetProviderTests.cs +++ b/src/VisualStudio/Core/Test.Next/Services/AssetProviderTests.cs @@ -187,7 +187,7 @@ private sealed class OrderedAssetSource( ISerializerService serializerService, IReadOnlyDictionary map) : IAssetSource { - public ValueTask GetAssetsAsync( + public async ValueTask GetAssetsAsync( Checksum solutionChecksum, AssetPath assetPath, ReadOnlyMemory checksums, @@ -213,8 +213,6 @@ public ValueTask GetAssetsAsync( callback(checksum, (T)deserialized, arg); } } - - return ValueTask.CompletedTask; } } } diff --git a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs index 65dd675cd3f83..c97ca0f6a6bea 100644 --- a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs +++ b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs @@ -224,10 +224,9 @@ private sealed class DesignerAttributeComputerCallback : IDesignerAttributeDisco public Task> Infos => _infosSource.Task; - public ValueTask ReportDesignerAttributeDataAsync(ImmutableArray infos, CancellationToken cancellationToken) + public async ValueTask ReportDesignerAttributeDataAsync(ImmutableArray infos, CancellationToken cancellationToken) { _infosSource.SetResult(infos); - return ValueTask.CompletedTask; } } diff --git a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests_ExtensionMessageHandler.cs b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests_ExtensionMessageHandler.cs index 2e8e396f7225a..670dfe8ef80bb 100644 --- a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests_ExtensionMessageHandler.cs +++ b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests_ExtensionMessageHandler.cs @@ -787,8 +787,8 @@ private sealed class TestHandler( string name, Func? executeCallback = null) : IExtensionMessageHandlerWrapper { - public Task ExecuteAsync(object? message, TArgument argument, CancellationToken cancellationToken) - => Task.FromResult(executeCallback!(message, argument, cancellationToken)); + public async Task ExecuteAsync(object? message, TArgument argument, CancellationToken cancellationToken) + => executeCallback!(message, argument, cancellationToken); public Type MessageType => typeof(int); diff --git a/src/VisualStudio/ExternalAccess/FSharp/Internal/Classification/FSharpClassificationService.cs b/src/VisualStudio/ExternalAccess/FSharp/Internal/Classification/FSharpClassificationService.cs index d7cf5e8a4d05a..49a43ea764e3b 100644 --- a/src/VisualStudio/ExternalAccess/FSharp/Internal/Classification/FSharpClassificationService.cs +++ b/src/VisualStudio/ExternalAccess/FSharp/Internal/Classification/FSharpClassificationService.cs @@ -81,8 +81,7 @@ public void AddSyntacticClassifications(SolutionServices services, SyntaxNode? r return new(); } - public Task AddEmbeddedLanguageClassificationsAsync(Document document, ImmutableArray textSpans, ClassificationOptions options, SegmentedList result, CancellationToken cancellationToken) + public async Task AddEmbeddedLanguageClassificationsAsync(Document document, ImmutableArray textSpans, ClassificationOptions options, SegmentedList result, CancellationToken cancellationToken) { - return Task.CompletedTask; } } diff --git a/src/VisualStudio/ExternalAccess/FSharp/Internal/Editor/FSharpEditorInlineRenameService.cs b/src/VisualStudio/ExternalAccess/FSharp/Internal/Editor/FSharpEditorInlineRenameService.cs index 7af59bf296a18..637d8582f4b42 100644 --- a/src/VisualStudio/ExternalAccess/FSharp/Internal/Editor/FSharpEditorInlineRenameService.cs +++ b/src/VisualStudio/ExternalAccess/FSharp/Internal/Editor/FSharpEditorInlineRenameService.cs @@ -202,9 +202,9 @@ public FSharpEditorInlineRenameService( public bool IsEnabled => true; - public Task>> GetRenameContextAsync(IInlineRenameInfo inlineRenameInfo, IInlineRenameLocationSet inlineRenameLocationSet, CancellationToken cancellationToken) + public async Task>> GetRenameContextAsync(IInlineRenameInfo inlineRenameInfo, IInlineRenameLocationSet inlineRenameLocationSet, CancellationToken cancellationToken) { - return Task.FromResult(ImmutableDictionary>.Empty); + return ImmutableDictionary>.Empty; } public async Task GetRenameInfoAsync(Document document, int position, CancellationToken cancellationToken) diff --git a/src/VisualStudio/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs b/src/VisualStudio/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs index caa330436d993..431ca25879a71 100644 --- a/src/VisualStudio/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs +++ b/src/VisualStudio/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs @@ -37,9 +37,8 @@ public Task ReportMessageAsync(string message) return _context.ReportNoResultsAsync(message, CancellationToken).AsTask(); } - public Task ReportProgressAsync(int current, int maximum) + public async Task ReportProgressAsync(int current, int maximum) { - return Task.CompletedTask; } public Task SetSearchTitleAsync(string title) diff --git a/src/VisualStudio/LiveShare/Impl/Client/Projects/WorkspaceFileTextLoaderNoException.cs b/src/VisualStudio/LiveShare/Impl/Client/Projects/WorkspaceFileTextLoaderNoException.cs index 2474517cbcb80..f2ad0c2ed6c58 100644 --- a/src/VisualStudio/LiveShare/Impl/Client/Projects/WorkspaceFileTextLoaderNoException.cs +++ b/src/VisualStudio/LiveShare/Impl/Client/Projects/WorkspaceFileTextLoaderNoException.cs @@ -25,13 +25,13 @@ public WorkspaceFileTextLoaderNoException(SolutionServices services, string path { } - public override Task LoadTextAndVersionAsync(LoadTextOptions options, CancellationToken cancellationToken) + public override async Task LoadTextAndVersionAsync(LoadTextOptions options, CancellationToken cancellationToken) { if (!File.Exists(Path)) { - return Task.FromResult(TextAndVersion.Create(SourceText.From("", encoding: null, options.ChecksumAlgorithm), VersionStamp.Create())); + return TextAndVersion.Create(SourceText.From("", encoding: null, options.ChecksumAlgorithm), VersionStamp.Create()); } - return base.LoadTextAndVersionAsync(options, cancellationToken); + return await base.LoadTextAndVersionAsync(options, cancellationToken).ConfigureAwait(false); } } diff --git a/src/VisualStudio/LiveShare/Impl/Client/RoslynLSPClientService.cs b/src/VisualStudio/LiveShare/Impl/Client/RoslynLSPClientService.cs index dbb29ef7281df..a4e41d96669cc 100644 --- a/src/VisualStudio/LiveShare/Impl/Client/RoslynLSPClientService.cs +++ b/src/VisualStudio/LiveShare/Impl/Client/RoslynLSPClientService.cs @@ -26,7 +26,7 @@ internal abstract class AbstractLspClientServiceFactory : ICollaborationServiceF public LS.ILanguageServerClient ActiveLanguageServerClient { get; private set; } - public Task CreateServiceAsync(CollaborationSession collaborationSession, CancellationToken cancellationToken) + public async Task CreateServiceAsync(CollaborationSession collaborationSession, CancellationToken cancellationToken) { var languageServerGuestService = (LS.ILanguageServerGuestService)collaborationSession.GetService(typeof(LS.ILanguageServerGuestService)); @@ -90,7 +90,7 @@ public Task CreateServiceAsync(CollaborationSession colla ActiveLanguageServerClient = null; }; - return Task.FromResult(lifeTimeService); + return lifeTimeService; } protected abstract class RoslynLSPClientLifeTimeService : ICollaborationService, IDisposable diff --git a/src/VisualStudio/LiveShare/Impl/LSPSDKInitializeHandler.cs b/src/VisualStudio/LiveShare/Impl/LSPSDKInitializeHandler.cs index 23fb0dc7e581e..520242cc504e8 100644 --- a/src/VisualStudio/LiveShare/Impl/LSPSDKInitializeHandler.cs +++ b/src/VisualStudio/LiveShare/Impl/LSPSDKInitializeHandler.cs @@ -28,13 +28,13 @@ public LSPSDKInitializeHandler() { } - public Task HandleAsync(LSP.InitializeParams request, RequestContext requestContext, CancellationToken cancellationToken) + public async Task HandleAsync(LSP.InitializeParams request, RequestContext requestContext, CancellationToken cancellationToken) { var result = new LSP.InitializeResult { Capabilities = new LSP.ServerCapabilities() }; - return Task.FromResult(result); + return result; } } diff --git a/src/VisualStudio/LiveShare/Impl/LiveShareInitializeHandler.cs b/src/VisualStudio/LiveShare/Impl/LiveShareInitializeHandler.cs index 73780d3c8b3f5..ebfabf67cddc6 100644 --- a/src/VisualStudio/LiveShare/Impl/LiveShareInitializeHandler.cs +++ b/src/VisualStudio/LiveShare/Impl/LiveShareInitializeHandler.cs @@ -25,8 +25,8 @@ internal class LiveShareInitializeHandler : ILspRequestHandler HandleAsync(InitializeParams param, RequestContext requestContext, CancellationToken cancellationToken) - => Task.FromResult(s_initializeResult); + public async Task HandleAsync(InitializeParams param, RequestContext requestContext, CancellationToken cancellationToken) + => s_initializeResult; } [ExportLspRequestHandler(LiveShareConstants.RoslynContractName, Methods.InitializeName)] diff --git a/src/VisualStudio/LiveShare/Test/MockDocumentNavigationServiceFactory.cs b/src/VisualStudio/LiveShare/Test/MockDocumentNavigationServiceFactory.cs index a78e33358c98b..f9c51df21e6a1 100644 --- a/src/VisualStudio/LiveShare/Test/MockDocumentNavigationServiceFactory.cs +++ b/src/VisualStudio/LiveShare/Test/MockDocumentNavigationServiceFactory.cs @@ -20,8 +20,8 @@ namespace Microsoft.VisualStudio.LanguageServices.LiveShare.UnitTests; [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] internal sealed class MockDocumentNavigationService() : AbstractDocumentNavigationService { - public override Task CanNavigateToPositionAsync(Workspace workspace, DocumentId documentId, int position, int virtualSpace, bool allowInvalidPosition, CancellationToken cancellationToken) - => SpecializedTasks.True; + public override async Task CanNavigateToPositionAsync(Workspace workspace, DocumentId documentId, int position, int virtualSpace, bool allowInvalidPosition, CancellationToken cancellationToken) + => true; public override Task GetLocationForPositionAsync(Workspace workspace, DocumentId documentId, int position, int virtualSpace, bool allowInvalidPosition, CancellationToken cancellationToken) => NavigableLocation.TestAccessor.Create(true); diff --git a/src/VisualStudio/VisualStudioDiagnosticsToolWindow/VisualStudioDiagnosticsWindowPackage.cs b/src/VisualStudio/VisualStudioDiagnosticsToolWindow/VisualStudioDiagnosticsWindowPackage.cs index 720f866972587..1202455fe078f 100644 --- a/src/VisualStudio/VisualStudioDiagnosticsToolWindow/VisualStudioDiagnosticsWindowPackage.cs +++ b/src/VisualStudio/VisualStudioDiagnosticsToolWindow/VisualStudioDiagnosticsWindowPackage.cs @@ -111,8 +111,8 @@ protected override string GetToolWindowTitle(Type toolWindowType, int id) return null; } - protected override Task InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken) + protected override async Task InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken) { - return Task.FromResult(new object()); + return new object(); } } diff --git a/src/VisualStudio/Xaml/Impl/CodeFixes/RemoveUnnecessaryUsings/XamlRemoveUnnecessaryUsingsCodeFixProvider.cs b/src/VisualStudio/Xaml/Impl/CodeFixes/RemoveUnnecessaryUsings/XamlRemoveUnnecessaryUsingsCodeFixProvider.cs index 6890bcc6c0d57..09ae6dbfccf24 100644 --- a/src/VisualStudio/Xaml/Impl/CodeFixes/RemoveUnnecessaryUsings/XamlRemoveUnnecessaryUsingsCodeFixProvider.cs +++ b/src/VisualStudio/Xaml/Impl/CodeFixes/RemoveUnnecessaryUsings/XamlRemoveUnnecessaryUsingsCodeFixProvider.cs @@ -40,7 +40,7 @@ public override FixAllProvider GetFixAllProvider() return null; } - public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) + public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { context.RegisterCodeFix( CodeAction.Create( @@ -48,7 +48,6 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) c => RemoveUnnecessaryImportsAsync(context.Document, c), nameof(Resources.RemoveUnnecessaryNamespaces)), context.Diagnostics); - return Task.CompletedTask; } private static async Task RemoveUnnecessaryImportsAsync( diff --git a/src/VisualStudio/Xaml/Impl/Features/InlineRename/XamlEditorInlineRenameService.cs b/src/VisualStudio/Xaml/Impl/Features/InlineRename/XamlEditorInlineRenameService.cs index 05afdafdff8ca..a82ad035e0047 100644 --- a/src/VisualStudio/Xaml/Impl/Features/InlineRename/XamlEditorInlineRenameService.cs +++ b/src/VisualStudio/Xaml/Impl/Features/InlineRename/XamlEditorInlineRenameService.cs @@ -32,9 +32,9 @@ public XamlEditorInlineRenameService(IXamlRenameInfoService renameService) public bool IsEnabled => true; - public Task>> GetRenameContextAsync(IInlineRenameInfo inlineRenameInfo, IInlineRenameLocationSet inlineRenameLocationSet, CancellationToken cancellationToken) + public async Task>> GetRenameContextAsync(IInlineRenameInfo inlineRenameInfo, IInlineRenameLocationSet inlineRenameLocationSet, CancellationToken cancellationToken) { - return Task.FromResult(ImmutableDictionary>.Empty); + return ImmutableDictionary>.Empty; } public async Task GetRenameInfoAsync(Document document, int position, CancellationToken cancellationToken)