diff --git a/src/LanguageServer/ExternalAccess/VisualDiagnostics/Internal/VisualDiagnosticsServiceFactory.cs b/src/LanguageServer/ExternalAccess/VisualDiagnostics/Internal/VisualDiagnosticsServiceFactory.cs index d2e7cc11cf33a..bcd4c4934979f 100644 --- a/src/LanguageServer/ExternalAccess/VisualDiagnostics/Internal/VisualDiagnosticsServiceFactory.cs +++ b/src/LanguageServer/ExternalAccess/VisualDiagnostics/Internal/VisualDiagnosticsServiceFactory.cs @@ -58,11 +58,10 @@ public void Dispose() (_visualDiagnosticsLanguageService as IDisposable)?.Dispose(); } - public Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken) + public async Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken) { _cancellationToken = cancellationToken; _taskCompletionSource.TrySetResult(true); - return Task.CompletedTask; } public void OnServiceBrokerInitialized(IServiceBroker serviceBroker) diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs index 6d0590087b5fc..4f35f5c488218 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs @@ -118,21 +118,17 @@ private sealed class DynamicCapabilitiesRpcTarget public readonly ConcurrentDictionary Registrations = new(); [JsonRpcMethod("client/registerCapability", UseSingleObjectParameterDeserialization = true)] - public Task RegisterCapabilityAsync(RegistrationParams registrationParams, CancellationToken _) + public async Task RegisterCapabilityAsync(RegistrationParams registrationParams, CancellationToken _) { foreach (var registration in registrationParams.Registrations) Assert.True(Registrations.TryAdd(registration.Id, registration)); - - return Task.CompletedTask; } [JsonRpcMethod("client/unregisterCapability", UseSingleObjectParameterDeserialization = true)] - public Task UnregisterCapabilityAsync(UnregistrationParams unregistrationParams, CancellationToken _) + public async Task UnregisterCapabilityAsync(UnregistrationParams unregistrationParams, CancellationToken _) { foreach (var unregistration in unregistrationParams.Unregistrations) Assert.True(Registrations.TryRemove(unregistration.Id, out var _)); - - return Task.CompletedTask; } } } diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/BrokeredServiceContainer.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/BrokeredServiceContainer.cs index 088d183bc6701..33898cc63fad4 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/BrokeredServiceContainer.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/BrokeredServiceContainer.cs @@ -42,7 +42,7 @@ internal static async Task CreateAsync(ExportProvider container.ProfferIntrinsicService( FrameworkServices.Authorization, new ServiceRegistration(VisualStudio.Shell.ServiceBroker.ServiceAudience.Local, null, allowGuestClients: true), - (moniker, options, serviceBroker, cancellationToken) => new(new NoOpAuthorizationService())); + async (moniker, options, serviceBroker, cancellationToken) => new NoOpAuthorizationService()); var mefServiceBroker = exportProvider.GetExportedValue(); mefServiceBroker.SetContainer(container); @@ -62,14 +62,14 @@ private class NoOpAuthorizationService : IAuthorizationService public event EventHandler? AuthorizationChanged; - public ValueTask CheckAuthorizationAsync(ProtectedOperation operation, CancellationToken cancellationToken = default) + public async ValueTask CheckAuthorizationAsync(ProtectedOperation operation, CancellationToken cancellationToken = default) { - return new(true); + return true; } - public ValueTask> GetCredentialsAsync(CancellationToken cancellationToken = default) + public async ValueTask> GetCredentialsAsync(CancellationToken cancellationToken = default) { - return new(ImmutableDictionary.Empty); + return ImmutableDictionary.Empty; } protected virtual void OnCredentialsChanged(EventArgs args) => this.CredentialsChanged?.Invoke(this, args); diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/Services/BrokeredServiceBridgeManifest/BrokeredServiceBridgeManifestService.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/Services/BrokeredServiceBridgeManifest/BrokeredServiceBridgeManifestService.cs index 4c65e7361beab..593541ec74342 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/Services/BrokeredServiceBridgeManifest/BrokeredServiceBridgeManifestService.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/BrokeredServices/Services/BrokeredServiceBridgeManifest/BrokeredServiceBridgeManifestService.cs @@ -38,7 +38,7 @@ public BrokeredServiceBridgeManifest(ServiceBrokerFactory serviceBrokerFactory, /// /// Returns a subset of services registered to Microsoft.VisualStudio.Code.Server container that are proferred by the Language Server process. /// - public ValueTask> GetAvailableServicesAsync(CancellationToken cancellationToken) + public async ValueTask> GetAvailableServicesAsync(CancellationToken cancellationToken) { var services = (IReadOnlyCollection)[.. _serviceBrokerFactory.GetRequiredServiceBrokerContainer().GetRegisteredServices() .Select(s => s.Key) @@ -46,12 +46,11 @@ public ValueTask> GetAvailableServicesAsync( s.Name.StartsWith("Microsoft.VisualStudio.LanguageServer.", StringComparison.Ordinal) || s.Name.StartsWith("Microsoft.VisualStudio.LanguageServices.", StringComparison.Ordinal))]; _logger.LogDebug($"Proffered services: {string.Join(',', services.Select(s => s.ToString()))}"); - return ValueTask.FromResult(services); + return services; } - public Task InitializeAsync(CancellationToken cancellationToken) + public async Task InitializeAsync(CancellationToken cancellationToken) { - return Task.CompletedTask; } } #pragma warning restore RS0030 // Do not used banned APIs diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/CanonicalMiscFilesProjectLoader.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/CanonicalMiscFilesProjectLoader.cs index 1e77769b8b924..1dc74897b658f 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/CanonicalMiscFilesProjectLoader.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/CanonicalMiscFilesProjectLoader.cs @@ -276,10 +276,9 @@ private TextDocument CreatePrimordialProjectAndAddDocument_NoLock(string documen }; } - protected override ValueTask OnProjectUnloadedAsync(string projectFilePath) + protected override async ValueTask OnProjectUnloadedAsync(string projectFilePath) { // Nothing special to do on unload for canonical project - return ValueTask.CompletedTask; } protected override async ValueTask TransitionPrimordialProjectToLoaded_NoLockAsync( diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/FileBasedProgramsProjectSystem.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/FileBasedProgramsProjectSystem.cs index afa8e5e4dde15..62815a6276f4a 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/FileBasedProgramsProjectSystem.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/FileBasedPrograms/FileBasedProgramsProjectSystem.cs @@ -222,9 +222,8 @@ public async ValueTask TryRemoveMiscellaneousDocumentAsync(DocumentUri uri }; } - protected override ValueTask OnProjectUnloadedAsync(string projectFilePath) + protected override async ValueTask OnProjectUnloadedAsync(string projectFilePath) { - return ValueTask.CompletedTask; } protected override async ValueTask TransitionPrimordialProjectToLoaded_NoLockAsync( diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspDidChangeWatchedFilesHandler.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspDidChangeWatchedFilesHandler.cs index 5c41b30e837d2..a7b49ced2e38b 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspDidChangeWatchedFilesHandler.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspDidChangeWatchedFilesHandler.cs @@ -23,10 +23,9 @@ public LspDidChangeWatchedFilesHandler() public bool MutatesSolutionState => false; public bool RequiresLSPSolution => false; - Task INotificationHandler.HandleNotificationAsync(DidChangeWatchedFilesParams request, RequestContext requestContext, CancellationToken cancellationToken) + async Task INotificationHandler.HandleNotificationAsync(DidChangeWatchedFilesParams request, RequestContext requestContext, CancellationToken cancellationToken) { NotificationRaised?.Invoke(this, request); - return Task.CompletedTask; } public event EventHandler? NotificationRaised; diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs index a7b83343ac0fa..9a467a701e6ae 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs @@ -102,10 +102,9 @@ public async Task OpenProjectsAsync(ImmutableArray projectFilePaths) }; } - protected override ValueTask OnProjectUnloadedAsync(string projectFilePath) + protected override async ValueTask OnProjectUnloadedAsync(string projectFilePath) { // Nothing else to unload for ordinary projects. - return ValueTask.CompletedTask; } protected override async ValueTask TransitionPrimordialProjectToLoaded_NoLockAsync( diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/Razor/RazorInitializer.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/Razor/RazorInitializer.cs index 6773f0c322a8f..1cdbc88fbdf24 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/Razor/RazorInitializer.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/Razor/RazorInitializer.cs @@ -17,13 +17,13 @@ namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.Razor; [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] internal sealed class RazorInitializer(Lazy workspaceFactory, [Import(AllowDefault = true)] ITelemetryReporter? telemetryReporter) : ILspService, IOnInitialized { - public Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken) + public async Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken) { var razorInitializerService = context.GetService(); if (razorInitializerService is null) { // No initializer service registered, nothing to do. - return Task.CompletedTask; + return; } razorInitializerService.Initialize(workspaceFactory.Value.HostWorkspace); @@ -33,7 +33,5 @@ public Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestCon { razorTelemetryReporter.Initialize(new TelemetryReporterWrapper(telemetryReporter)); } - - return Task.CompletedTask; } } diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/WorkspaceProjectFactoryService.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/WorkspaceProjectFactoryService.cs index 267e4a7006e69..8e8cae416cead 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/WorkspaceProjectFactoryService.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/WorkspaceProjectFactoryService.cs @@ -65,10 +65,10 @@ public async Task CreateAndAddProjectAsync(WorkspaceProjectCr } } - public Task> GetSupportedBuildSystemPropertiesAsync(CancellationToken _) + public async Task> GetSupportedBuildSystemPropertiesAsync(CancellationToken _) { // TODO: implement - return Task.FromResult((IReadOnlyCollection)[]); + return []; } } #pragma warning restore RS0030 // Do not used banned APIs diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/DebugConfiguration/WorkspaceDebugConfigurationHandler.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/DebugConfiguration/WorkspaceDebugConfigurationHandler.cs index 4fe27fcea7d64..ddb95da49281b 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/DebugConfiguration/WorkspaceDebugConfigurationHandler.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/DebugConfiguration/WorkspaceDebugConfigurationHandler.cs @@ -28,7 +28,7 @@ public WorkspaceDebugConfigurationHandler(ProjectTargetFrameworkManager targetFr public bool RequiresLSPSolution => true; - public Task HandleRequestAsync(WorkspaceDebugConfigurationParams request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(WorkspaceDebugConfigurationParams request, RequestContext context, CancellationToken cancellationToken) { Contract.ThrowIfNull(context.Solution, nameof(context.Solution)); @@ -36,7 +36,7 @@ public Task HandleRequestAsync(WorkspaceDebugConfig .Where(p => p.FilePath != null && p.OutputFilePath != null) .Where(p => IsProjectInWorkspace(request.WorkspacePath, p)) .Select(GetProjectDebugConfiguration).ToArray(); - return Task.FromResult(projects); + return projects; } private static bool IsProjectInWorkspace(DocumentUri workspacePath, Project project) diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/Logging/UpdateLogLevelHandler.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/Logging/UpdateLogLevelHandler.cs index b8651a80df060..6ad1868b95059 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/Logging/UpdateLogLevelHandler.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/Logging/UpdateLogLevelHandler.cs @@ -22,11 +22,10 @@ internal sealed class UpdateLogLevelHandler(ServerConfiguration serverConfigurat public bool RequiresLSPSolution => false; - public Task HandleNotificationAsync(UpdateLogLevelParams request, RequestContext requestContext, CancellationToken cancellationToken) + public async Task HandleNotificationAsync(UpdateLogLevelParams request, RequestContext requestContext, CancellationToken cancellationToken) { var level = Enum.Parse(request.LogLevelValue); serverConfiguration.LogConfiguration.UpdateLogLevel(level); - return Task.CompletedTask; } } diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/Restore/RestorableProjectsHandler.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/Restore/RestorableProjectsHandler.cs index dff2f53aa8ce6..f0427ed9930d6 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/Restore/RestorableProjectsHandler.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/LanguageServer/Handler/Restore/RestorableProjectsHandler.cs @@ -25,7 +25,7 @@ internal sealed class RestorableProjectsHandler(ProjectTargetFrameworkManager pr public bool RequiresLSPSolution => true; - public Task HandleRequestAsync(RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(RequestContext context, CancellationToken cancellationToken) { Contract.ThrowIfNull(context.Solution); @@ -43,6 +43,6 @@ public Task HandleRequestAsync(RequestContext context, CancellationTok } } - return Task.FromResult(projects.ToArray()); + return projects.ToArray(); } } diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.Example/ExampleRequestContextFactory.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.Example/ExampleRequestContextFactory.cs index 4b9ba38ab475f..606762c26aa8f 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.Example/ExampleRequestContextFactory.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.Example/ExampleRequestContextFactory.cs @@ -16,12 +16,12 @@ public ExampleRequestContextFactory(ILspServices lspServices) _lspServices = lspServices; } - public override Task CreateRequestContextAsync(IQueueItem queueItem, IMethodHandler methodHandler, TRequestParam requestParam, CancellationToken cancellationToken) + public override async Task CreateRequestContextAsync(IQueueItem queueItem, IMethodHandler methodHandler, TRequestParam requestParam, CancellationToken cancellationToken) { var logger = _lspServices.GetRequiredService(); var requestContext = new ExampleRequestContext(_lspServices, logger); - return Task.FromResult(requestContext); + return requestContext; } } diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/Mocks/TestRequestContext.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/Mocks/TestRequestContext.cs index 2e0fbad7fa649..229fc9543cd90 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/Mocks/TestRequestContext.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/Mocks/TestRequestContext.cs @@ -13,7 +13,7 @@ internal sealed class Factory : AbstractRequestContextFactory CreateRequestContextAsync(IQueueItem queueItem, IMethodHandler methodHandler, TRequestParam requestParam, CancellationToken cancellationToken) - => Task.FromResult(new TestRequestContext()); + public override async Task CreateRequestContextAsync(IQueueItem queueItem, IMethodHandler methodHandler, TRequestParam requestParam, CancellationToken cancellationToken) + => new TestRequestContext(); } } diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/TestExampleLanguageServer.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/TestExampleLanguageServer.cs index 8cb327686f775..a09f06b3dcd1c 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/TestExampleLanguageServer.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/TestExampleLanguageServer.cs @@ -60,16 +60,14 @@ public TestLifeCycleManager(TaskCompletionSource shuttingDownSource, TaskCo _exitingSource = exitingSource; } - public Task ExitAsync() + public async Task ExitAsync() { _exitingSource.SetResult(0); - return Task.CompletedTask; } - public Task ShutdownAsync(string message = "Shutting down") + public async Task ShutdownAsync(string message = "Shutting down") { _shuttingDownSource.SetResult(0); - return Task.CompletedTask; } } diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/Handlers/InitializeHandler.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/Handlers/InitializeHandler.cs index 2552058e13c5b..f10cec2138dce 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/Handlers/InitializeHandler.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/Handlers/InitializeHandler.cs @@ -23,12 +23,12 @@ public InitializeHandler(IInitializeManager capabilitiesMan public bool MutatesSolutionState => true; - public Task HandleRequestAsync(TRequest request, TRequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(TRequest request, TRequestContext context, CancellationToken cancellationToken) { _capabilitiesManager.SetInitializeParams(request); var serverCapabilities = _capabilitiesManager.GetInitializeResult(); - return Task.FromResult(serverCapabilities); + return serverCapabilities; } } diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/Handlers/InitializedHandler.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/Handlers/InitializedHandler.cs index 30e014534168f..2e8da373ae885 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/Handlers/InitializedHandler.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/Handlers/InitializedHandler.cs @@ -18,7 +18,7 @@ internal sealed class InitializedHandler : INotificat public bool MutatesSolutionState => true; - public Task HandleNotificationAsync(TRequest request, TRequestContext requestContext, CancellationToken cancellationToken) + public async Task HandleNotificationAsync(TRequest request, TRequestContext requestContext, CancellationToken cancellationToken) { if (HasBeenInitialized) { @@ -26,7 +26,5 @@ public Task HandleNotificationAsync(TRequest request, TRequestContext requestCon } HasBeenInitialized = true; - - return Task.CompletedTask; } } diff --git a/src/LanguageServer/Protocol.TestUtilities/LanguageServer/AbstractLanguageServerProtocolTests.cs b/src/LanguageServer/Protocol.TestUtilities/LanguageServer/AbstractLanguageServerProtocolTests.cs index ad45e29418c17..f9167c06be2df 100644 --- a/src/LanguageServer/Protocol.TestUtilities/LanguageServer/AbstractLanguageServerProtocolTests.cs +++ b/src/LanguageServer/Protocol.TestUtilities/LanguageServer/AbstractLanguageServerProtocolTests.cs @@ -78,7 +78,7 @@ internal sealed class TestSpanMapper : ISpanMappingService /// public bool SupportsMappingImportDirectives => true; - public Task> MapSpansAsync(Document document, IEnumerable spans, CancellationToken cancellationToken) + public async Task> MapSpansAsync(Document document, IEnumerable spans, CancellationToken cancellationToken) { ImmutableArray mappedResult = default; if (document.Name == GeneratedFileName) @@ -86,7 +86,7 @@ public Task> MapSpansAsync(Document document, I mappedResult = [.. spans.Select(span => new MappedSpanResult(s_mappedFilePath, s_mappedLinePosition, new TextSpan(0, 5)))]; } - return Task.FromResult(mappedResult); + return mappedResult; } public Task> GetMappedTextChangesAsync( @@ -103,7 +103,7 @@ private protected sealed class OrderLocations : Comparer public override int Compare(LSP.Location? x, LSP.Location? y) => CompareLocations(x, y); } - protected virtual ValueTask CreateExportProviderAsync() => ValueTask.FromResult(Composition.ExportProviderFactory.CreateExportProvider()); + protected virtual async ValueTask CreateExportProviderAsync() => Composition.ExportProviderFactory.CreateExportProvider(); protected virtual TestComposition Composition => FeaturesLspComposition; private protected virtual TestAnalyzerReferenceByLanguage CreateTestAnalyzersReference() diff --git a/src/LanguageServer/Protocol.TestUtilities/Workspaces/LspTestWorkspace.cs b/src/LanguageServer/Protocol.TestUtilities/Workspaces/LspTestWorkspace.cs index 025e30f45eba0..70c54361f1883 100644 --- a/src/LanguageServer/Protocol.TestUtilities/Workspaces/LspTestWorkspace.cs +++ b/src/LanguageServer/Protocol.TestUtilities/Workspaces/LspTestWorkspace.cs @@ -36,11 +36,10 @@ internal LspTestWorkspace( bool ILspWorkspace.SupportsMutation => _supportsLspMutation; - ValueTask ILspWorkspace.UpdateTextIfPresentAsync(DocumentId documentId, SourceText sourceText, CancellationToken cancellationToken) + async ValueTask ILspWorkspace.UpdateTextIfPresentAsync(DocumentId documentId, SourceText sourceText, CancellationToken cancellationToken) { Contract.ThrowIfFalse(_supportsLspMutation); OnDocumentTextChanged(documentId, sourceText, PreservationMode.PreserveIdentity, requireDocumentPresent: false); - return ValueTask.CompletedTask; } internal override ValueTask TryOnDocumentClosedAsync(DocumentId documentId, CancellationToken cancellationToken) diff --git a/src/LanguageServer/Protocol/Features/DecompiledSource/AssemblyResolver.cs b/src/LanguageServer/Protocol/Features/DecompiledSource/AssemblyResolver.cs index da70d86cc57ee..f038fb3b9b395 100644 --- a/src/LanguageServer/Protocol/Features/DecompiledSource/AssemblyResolver.cs +++ b/src/LanguageServer/Protocol/Features/DecompiledSource/AssemblyResolver.cs @@ -48,14 +48,14 @@ void BuildReferenceCache() } } - public Task ResolveAsync(IAssemblyReference name) + public async Task ResolveAsync(IAssemblyReference name) { - return Task.FromResult(Resolve(name)); + return Resolve(name); } - public Task ResolveModuleAsync(MetadataFile mainModule, string moduleName) + public async Task ResolveModuleAsync(MetadataFile mainModule, string moduleName) { - return Task.FromResult(ResolveModule(mainModule, moduleName)); + return ResolveModule(mainModule, moduleName); } [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Could be non-static if instance data is accessed")] diff --git a/src/LanguageServer/Protocol/Features/EditAndContinue/EditAndContinueDiagnosticSource_OpenDocument.cs b/src/LanguageServer/Protocol/Features/EditAndContinue/EditAndContinueDiagnosticSource_OpenDocument.cs index db886e9f5f633..9151ccc849200 100644 --- a/src/LanguageServer/Protocol/Features/EditAndContinue/EditAndContinueDiagnosticSource_OpenDocument.cs +++ b/src/LanguageServer/Protocol/Features/EditAndContinue/EditAndContinueDiagnosticSource_OpenDocument.cs @@ -49,7 +49,7 @@ public override async Task> GetDiagnosticsAsync(R var activeStatementSpanProvider = spanLocator != null ? new ActiveStatementSpanProvider((documentId, filePath, cancellationToken) => spanLocator.GetSpansAsync(compileTimeSolution, documentId, filePath, cancellationToken)) - : static (_, _, _) => ValueTask.FromResult(ImmutableArray.Empty); + : static async (_, _, _) => ImmutableArray.Empty; var rudeEditDiagnostics = await proxy.GetDocumentDiagnosticsAsync(compileTimeDocument, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false); diff --git a/src/LanguageServer/Protocol/Features/EditAndContinue/EditAndContinueDiagnosticSource_Workspace.cs b/src/LanguageServer/Protocol/Features/EditAndContinue/EditAndContinueDiagnosticSource_Workspace.cs index 9069b39d0e3fc..8242e49a91481 100644 --- a/src/LanguageServer/Protocol/Features/EditAndContinue/EditAndContinueDiagnosticSource_Workspace.cs +++ b/src/LanguageServer/Protocol/Features/EditAndContinue/EditAndContinueDiagnosticSource_Workspace.cs @@ -20,15 +20,15 @@ internal static partial class EditAndContinueDiagnosticSource private sealed class ProjectSource(Project project, ImmutableArray diagnostics) : AbstractProjectDiagnosticSource(project) { - public override Task> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken) - => Task.FromResult(diagnostics); + public override async Task> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken) + => diagnostics; } private sealed class ClosedDocumentSource(TextDocument document, ImmutableArray diagnostics) : AbstractWorkspaceDocumentDiagnosticSource(document) { - public override Task> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken) - => Task.FromResult(diagnostics); + public override async Task> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken) + => diagnostics; } public static async ValueTask> CreateWorkspaceDiagnosticSourcesAsync(Solution solution, Func isDocumentOpen, CancellationToken cancellationToken) diff --git a/src/LanguageServer/Protocol/Features/FindUsages/SimpleFindUsagesContext.cs b/src/LanguageServer/Protocol/Features/FindUsages/SimpleFindUsagesContext.cs index 1b192d32ff53a..11c1473dd6c17 100644 --- a/src/LanguageServer/Protocol/Features/FindUsages/SimpleFindUsagesContext.cs +++ b/src/LanguageServer/Protocol/Features/FindUsages/SimpleFindUsagesContext.cs @@ -28,16 +28,14 @@ internal sealed class SimpleFindUsagesContext : FindUsagesContext public string Message { get; private set; } public string SearchTitle { get; private set; } - public override ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken) + public override async ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken) { Message = message; - return default; } - public override ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) + public override async ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) { SearchTitle = title; - return default; } public ImmutableArray GetDefinitions() @@ -56,14 +54,12 @@ public ImmutableArray GetReferences() } } - public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public override async ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { _definitionItems.Add(definition); } - - return default; } public override async ValueTask OnReferencesFoundAsync(IAsyncEnumerable references, CancellationToken cancellationToken) diff --git a/src/LanguageServer/Protocol/RoslynLanguageServer.cs b/src/LanguageServer/Protocol/RoslynLanguageServer.cs index ca575808b15f9..f3fae36b579f5 100644 --- a/src/LanguageServer/Protocol/RoslynLanguageServer.cs +++ b/src/LanguageServer/Protocol/RoslynLanguageServer.cs @@ -157,10 +157,9 @@ void AddBaseService(BaseService baseService) } } - public Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken) + public async Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken) { OnInitialized(); - return Task.CompletedTask; } public override bool TryGetLanguageForRequest(string methodName, object? serializedParameters, [NotNullWhen(true)] out string? language) diff --git a/src/LanguageServer/Protocol/Workspaces/LspMiscellaneousFilesWorkspaceProvider.cs b/src/LanguageServer/Protocol/Workspaces/LspMiscellaneousFilesWorkspaceProvider.cs index e479423f1e139..5342371a4db87 100644 --- a/src/LanguageServer/Protocol/Workspaces/LspMiscellaneousFilesWorkspaceProvider.cs +++ b/src/LanguageServer/Protocol/Workspaces/LspMiscellaneousFilesWorkspaceProvider.cs @@ -30,10 +30,10 @@ internal sealed class LspMiscellaneousFilesWorkspaceProvider(ILspServices lspSer { public bool SupportsMutation => true; - public ValueTask IsMiscellaneousFilesDocumentAsync(TextDocument document, CancellationToken cancellationToken) + public async ValueTask IsMiscellaneousFilesDocumentAsync(TextDocument document, CancellationToken cancellationToken) { // In this case, the only documents ever created live in the Miscellaneous Files workspace (which is this object directly), so we can just compare to 'this'. - return ValueTask.FromResult(document.Project.Solution.Workspace == this); + return document.Project.Solution.Workspace == this; } /// @@ -42,8 +42,8 @@ public ValueTask IsMiscellaneousFilesDocumentAsync(TextDocument document, /// Calls to this method and are made /// from LSP text sync request handling which do not run concurrently. /// - public ValueTask AddMiscellaneousDocumentAsync(DocumentUri uri, SourceText documentText, string languageId, ILspLogger logger) - => ValueTask.FromResult(AddMiscellaneousDocument(uri, documentText, languageId, logger)); + public async ValueTask AddMiscellaneousDocumentAsync(DocumentUri uri, SourceText documentText, string languageId, ILspLogger logger) + => AddMiscellaneousDocument(uri, documentText, languageId, logger); private TextDocument? AddMiscellaneousDocument(DocumentUri uri, SourceText documentText, string languageId, ILspLogger logger) { @@ -83,7 +83,7 @@ public ValueTask IsMiscellaneousFilesDocumentAsync(TextDocument document, /// Calls to this method and are made /// from LSP text sync request handling which do not run concurrently. /// - public ValueTask TryRemoveMiscellaneousDocumentAsync(DocumentUri uri) + public async ValueTask TryRemoveMiscellaneousDocumentAsync(DocumentUri uri) { // We'll only ever have a single document matching this URI in the misc solution. var matchingDocument = CurrentSolution.GetDocumentIds(uri).SingleOrDefault(); @@ -103,16 +103,15 @@ public ValueTask TryRemoveMiscellaneousDocumentAsync(DocumentUri uri) var project = CurrentSolution.GetRequiredProject(matchingDocument.ProjectId); OnProjectRemoved(project.Id); - return ValueTask.FromResult(true); + return true; } - return ValueTask.FromResult(false); + return false; } - public ValueTask UpdateTextIfPresentAsync(DocumentId documentId, SourceText sourceText, CancellationToken cancellationToken) + public async ValueTask UpdateTextIfPresentAsync(DocumentId documentId, SourceText sourceText, CancellationToken cancellationToken) { this.OnDocumentTextChanged(documentId, sourceText, PreservationMode.PreserveIdentity, requireDocumentPresent: false); - return ValueTask.CompletedTask; } private sealed class StaticSourceTextContainer(SourceText text) : SourceTextContainer diff --git a/src/LanguageServer/Protocol/Workspaces/SourceTextLoader.cs b/src/LanguageServer/Protocol/Workspaces/SourceTextLoader.cs index e585ee4c76743..c0009a60454b3 100644 --- a/src/LanguageServer/Protocol/Workspaces/SourceTextLoader.cs +++ b/src/LanguageServer/Protocol/Workspaces/SourceTextLoader.cs @@ -23,6 +23,6 @@ internal override string? FilePath => _fileUri; // TODO (https://github.com/dotnet/roslyn/issues/63583): Use options.ChecksumAlgorithm - public override Task LoadTextAndVersionAsync(LoadTextOptions options, CancellationToken cancellationToken) - => Task.FromResult(TextAndVersion.Create(_sourceText, VersionStamp.Create(), _fileUri)); + public override async Task LoadTextAndVersionAsync(LoadTextOptions options, CancellationToken cancellationToken) + => TextAndVersion.Create(_sourceText, VersionStamp.Create(), _fileUri); } diff --git a/src/LanguageServer/ProtocolUnitTests/Commands/ExecuteWorkspaceCommandTests.cs b/src/LanguageServer/ProtocolUnitTests/Commands/ExecuteWorkspaceCommandTests.cs index 6595db73e8c26..ac2e470b71ac4 100644 --- a/src/LanguageServer/ProtocolUnitTests/Commands/ExecuteWorkspaceCommandTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Commands/ExecuteWorkspaceCommandTests.cs @@ -67,9 +67,9 @@ public override TextDocumentIdentifier GetTextDocumentIdentifier(ExecuteCommandP return JsonSerializer.Deserialize((JsonElement)request.Arguments!.First(), ProtocolConversions.LspJsonSerializerOptions)!; } - public override Task HandleRequestAsync(ExecuteCommandParams request, RequestContext context, CancellationToken cancellationToken) + public override async Task HandleRequestAsync(ExecuteCommandParams request, RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(true); + return true; } } } diff --git a/src/LanguageServer/ProtocolUnitTests/Completion/CompletionResolveTests.cs b/src/LanguageServer/ProtocolUnitTests/Completion/CompletionResolveTests.cs index c60c51ae06e2c..dcbd3a4e7e054 100644 --- a/src/LanguageServer/ProtocolUnitTests/Completion/CompletionResolveTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Completion/CompletionResolveTests.cs @@ -505,15 +505,15 @@ public TestCaretOutOfScopeCompletionService(SolutionServices services) : base(se public override string Language => LanguageNames.CSharp; - internal override Task GetCompletionsAsync(Document document, + internal override async Task GetCompletionsAsync(Document document, int caretPosition, CodeAnalysis.Completion.CompletionOptions options, OptionSet passThroughOptions, CompletionTrigger trigger = default, ImmutableHashSet roles = null, - CancellationToken cancellationToken = default) => Task.FromResult(CodeAnalysis.Completion.CompletionList.Empty); + CancellationToken cancellationToken = default) => CodeAnalysis.Completion.CompletionList.Empty; - public override Task GetChangeAsync( + public override async Task GetChangeAsync( Document document, CodeAnalysis.Completion.CompletionItem item, char? commitCharacter = null, @@ -526,7 +526,7 @@ public override void M() } """); - return Task.FromResult(CompletionChange.Create(textChange, newPosition: 0)); + return CompletionChange.Create(textChange, newPosition: 0); } internal override bool ShouldTriggerCompletion(Project project, LanguageServices languageServices, SourceText text, int caretPosition, CompletionTrigger trigger, CodeAnalysis.Completion.CompletionOptions options, OptionSet passthroughOptions, ImmutableHashSet roles = null) @@ -535,7 +535,7 @@ internal override bool ShouldTriggerCompletion(Project project, LanguageServices internal override CompletionRules GetRules(CodeAnalysis.Completion.CompletionOptions options) => CompletionRules.Default; - internal override Task GetDescriptionAsync(Document document, CodeAnalysis.Completion.CompletionItem item, CodeAnalysis.Completion.CompletionOptions options, SymbolDescriptionOptions displayOptions, CancellationToken cancellationToken = default) - => Task.FromResult(CompletionDescription.Empty); + internal override async Task GetDescriptionAsync(Document document, CodeAnalysis.Completion.CompletionItem item, CodeAnalysis.Completion.CompletionOptions options, SymbolDescriptionOptions displayOptions, CancellationToken cancellationToken = default) + => CompletionDescription.Empty; } } diff --git a/src/LanguageServer/ProtocolUnitTests/Diagnostics/AbstractPullDiagnosticTestsBase.cs b/src/LanguageServer/ProtocolUnitTests/Diagnostics/AbstractPullDiagnosticTestsBase.cs index 3d2cbbff7391e..e3356c4ef825c 100644 --- a/src/LanguageServer/ProtocolUnitTests/Diagnostics/AbstractPullDiagnosticTestsBase.cs +++ b/src/LanguageServer/ProtocolUnitTests/Diagnostics/AbstractPullDiagnosticTestsBase.cs @@ -372,10 +372,10 @@ private sealed class MockTypescriptDiagnosticAnalyzer : DocumentDiagnosticAnalyz public override ImmutableArray SupportedDiagnostics => [Descriptor]; - public override Task> AnalyzeSyntaxAsync(TextDocument document, SyntaxTree? tree, CancellationToken cancellationToken) + public override async Task> AnalyzeSyntaxAsync(TextDocument document, SyntaxTree? tree, CancellationToken cancellationToken) { - return Task.FromResult(ImmutableArray.Create( - Diagnostic.Create(Descriptor, Location.Create(document.FilePath!, default, default)))); + return ImmutableArray.Create( + Diagnostic.Create(Descriptor, Location.Create(document.FilePath!, default, default))); } } } diff --git a/src/LanguageServer/ProtocolUnitTests/Diagnostics/AdditionalFileDiagnosticsTests.cs b/src/LanguageServer/ProtocolUnitTests/Diagnostics/AdditionalFileDiagnosticsTests.cs index 548f54f2ef519..bb99dc823bda6 100644 --- a/src/LanguageServer/ProtocolUnitTests/Diagnostics/AdditionalFileDiagnosticsTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Diagnostics/AdditionalFileDiagnosticsTests.cs @@ -227,23 +227,23 @@ internal sealed class TestAdditionalFileDocumentSourceProvider() : IDiagnosticSo bool IDiagnosticSourceProvider.IsEnabled(LSP.ClientCapabilities clientCapabilities) => true; - ValueTask> IDiagnosticSourceProvider.CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken) + async ValueTask> IDiagnosticSourceProvider.CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken) { if (context.TextDocument is not null && context.TextDocument is not Document) { - return new([new TestAdditionalFileDocumentSource(context.TextDocument)]); + return [new TestAdditionalFileDocumentSource(context.TextDocument)]; } - return new([]); + return []; } private class TestAdditionalFileDocumentSource(TextDocument textDocument) : IDiagnosticSource { - public Task> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken) + public async Task> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken) { var diagnostic = Diagnostic.Create(MockAdditionalFileDiagnosticAnalyzer.Descriptor, location: Location.Create(context.TextDocument!.FilePath!, Text.TextSpan.FromBounds(0, 0), new Text.LinePositionSpan(new Text.LinePosition(0, 0), new Text.LinePosition(0, 0))), "args"); - return Task.FromResult>([DiagnosticData.Create(diagnostic, context.TextDocument.Project)]); + return [DiagnosticData.Create(diagnostic, context.TextDocument.Project)]; } public LSP.TextDocumentIdentifier? GetDocumentIdentifier() => new() diff --git a/src/LanguageServer/ProtocolUnitTests/Diagnostics/DiagnosticsPullCacheTests.cs b/src/LanguageServer/ProtocolUnitTests/Diagnostics/DiagnosticsPullCacheTests.cs index ab67bd1e23670..0625038497254 100644 --- a/src/LanguageServer/ProtocolUnitTests/Diagnostics/DiagnosticsPullCacheTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Diagnostics/DiagnosticsPullCacheTests.cs @@ -118,12 +118,12 @@ private sealed class TestDiagnosticSource(Document document, TestDiagnosticSourc { public const string Id = "Id"; - public override Task> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken) + public override async Task> GetDiagnosticsAsync(RequestContext context, CancellationToken cancellationToken) { Interlocked.Increment(ref provider.DiagnosticsRequestedCount); - return Task.FromResult>([new DiagnosticData(Id, category: "category", context.Document!.Name, DiagnosticSeverity.Error, DiagnosticSeverity.Error, + return [new DiagnosticData(Id, category: "category", context.Document!.Name, DiagnosticSeverity.Error, DiagnosticSeverity.Error, isEnabledByDefault: true, warningLevel: 0, [], ImmutableDictionary.Empty,context.Document!.Project.Id, - new DiagnosticDataLocation(new FileLinePositionSpan(context.Document!.FilePath!, new Text.LinePosition(0, 0), new Text.LinePosition(0, 0))))]); + new DiagnosticDataLocation(new FileLinePositionSpan(context.Document!.FilePath!, new Text.LinePosition(0, 0), new Text.LinePosition(0, 0))))]; } } @@ -138,9 +138,9 @@ private sealed class TestDiagnosticSourceProvider() : IDiagnosticSourceProvider public int DiagnosticsRequestedCount = 0; - public ValueTask> CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken) + public async ValueTask> CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken) { - return new ValueTask>([new TestDiagnosticSource(context.Document!, this)]); + return [new TestDiagnosticSource(context.Document!, this)]; } public bool IsEnabled(LSP.ClientCapabilities clientCapabilities) diff --git a/src/LanguageServer/ProtocolUnitTests/DocumentChanges/DocumentChangesTests.cs b/src/LanguageServer/ProtocolUnitTests/DocumentChanges/DocumentChangesTests.cs index edb76dd49fa16..76678098035d3 100644 --- a/src/LanguageServer/ProtocolUnitTests/DocumentChanges/DocumentChangesTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/DocumentChanges/DocumentChangesTests.cs @@ -494,11 +494,11 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(TextDocumentIdentifier r return request; } - public Task HandleRequestAsync(TextDocumentIdentifier request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(TextDocumentIdentifier request, RequestContext context, CancellationToken cancellationToken) { var trackedDocumentInfo = context.GetTrackedDocumentInfo(request.DocumentUri); - return Task.FromResult(new TestVersionResponse(trackedDocumentInfo.LspVersion)); + return new TestVersionResponse(trackedDocumentInfo.LspVersion); } } } diff --git a/src/LanguageServer/ProtocolUnitTests/HandlerTests.cs b/src/LanguageServer/ProtocolUnitTests/HandlerTests.cs index a117815191a4d..3ec74706852c7 100644 --- a/src/LanguageServer/ProtocolUnitTests/HandlerTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/HandlerTests.cs @@ -316,9 +316,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(TestRequestTypeOne reque return request.TextDocumentIdentifier; } - public Task HandleRequestAsync(TestRequestTypeOne request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(TestRequestTypeOne request, RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(this.GetType().Name); + return this.GetType().Name; } } @@ -338,9 +338,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(TestRequestTypeOne reque return request.TextDocumentIdentifier; } - public Task HandleRequestAsync(TestRequestTypeOne request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(TestRequestTypeOne request, RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(this.GetType().Name); + return this.GetType().Name; } } @@ -355,9 +355,9 @@ internal sealed class TestRequestHandlerWithNoParams() : ILspServiceRequestHandl public bool MutatesSolutionState => true; public bool RequiresLSPSolution => true; - public Task HandleRequestAsync(RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(this.GetType().Name); + return this.GetType().Name; } } @@ -370,10 +370,9 @@ internal sealed class TestNotificationHandler() : ILspServiceNotificationHandler public bool MutatesSolutionState => true; public bool RequiresLSPSolution => true; - public Task HandleNotificationAsync(TestRequestTypeOne request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleNotificationAsync(TestRequestTypeOne request, RequestContext context, CancellationToken cancellationToken) { ResultSource.SetResult(this.GetType().Name); - return Task.CompletedTask; } } @@ -400,10 +399,9 @@ internal sealed class TestNotificationWithoutParamsHandler() : ILspServiceNotifi public bool MutatesSolutionState => true; public bool RequiresLSPSolution => true; - public Task HandleNotificationAsync(RequestContext context, CancellationToken cancellationToken) + public async Task HandleNotificationAsync(RequestContext context, CancellationToken cancellationToken) { ResultSource.SetResult(this.GetType().Name); - return Task.CompletedTask; } } @@ -438,9 +436,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(TestRequestTypeOne reque return request.TextDocumentIdentifier; } - public Task HandleRequestAsync(TestRequestTypeOne request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(TestRequestTypeOne request, RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(this.GetType().Name); + return this.GetType().Name; } } @@ -462,9 +460,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(TestRequestTypeTwo reque return request.TextDocumentIdentifier; } - public Task HandleRequestAsync(TestRequestTypeTwo request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(TestRequestTypeTwo request, RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(this.GetType().Name); + return this.GetType().Name; } } @@ -481,9 +479,9 @@ internal sealed class TestDuplicateLanguageSpecificHandler() : ILspServiceReques public bool MutatesSolutionState => true; public bool RequiresLSPSolution => true; - public Task HandleRequestAsync(RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(this.GetType().Name); + return this.GetType().Name; } } } diff --git a/src/LanguageServer/ProtocolUnitTests/Initialize/LocaleTests.cs b/src/LanguageServer/ProtocolUnitTests/Initialize/LocaleTests.cs index c96b532168aa4..f18286f314ffb 100644 --- a/src/LanguageServer/ProtocolUnitTests/Initialize/LocaleTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Initialize/LocaleTests.cs @@ -93,9 +93,9 @@ public LocaleTestHandler() public bool MutatesSolutionState => true; public bool RequiresLSPSolution => true; - public Task HandleRequestAsync(Request request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(Request request, RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(new Response(CultureInfo.CurrentUICulture.Name)); + return new Response(CultureInfo.CurrentUICulture.Name); } } diff --git a/src/LanguageServer/ProtocolUnitTests/Ordering/LongRunningNonMutatingRequestHandler.cs b/src/LanguageServer/ProtocolUnitTests/Ordering/LongRunningNonMutatingRequestHandler.cs index d5afa895b3871..2ffac1bb8b198 100644 --- a/src/LanguageServer/ProtocolUnitTests/Ordering/LongRunningNonMutatingRequestHandler.cs +++ b/src/LanguageServer/ProtocolUnitTests/Ordering/LongRunningNonMutatingRequestHandler.cs @@ -28,13 +28,13 @@ public LongRunningNonMutatingRequestHandler() public bool RequiresLSPSolution => true; - public Task HandleRequestAsync(TestRequest request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(TestRequest request, RequestContext context, CancellationToken cancellationToken) { do { if (cancellationToken.IsCancellationRequested) { - return Task.FromResult(new TestResponse()); + return new TestResponse(); } Thread.Sleep(100); diff --git a/src/LanguageServer/ProtocolUnitTests/Ordering/NonLSPSolutionRequestHandlerProvider.cs b/src/LanguageServer/ProtocolUnitTests/Ordering/NonLSPSolutionRequestHandlerProvider.cs index 38c122a1bdaaa..aff916af644b2 100644 --- a/src/LanguageServer/ProtocolUnitTests/Ordering/NonLSPSolutionRequestHandlerProvider.cs +++ b/src/LanguageServer/ProtocolUnitTests/Ordering/NonLSPSolutionRequestHandlerProvider.cs @@ -27,10 +27,10 @@ public NonLSPSolutionRequestHandler() public bool MutatesSolutionState => false; public bool RequiresLSPSolution => false; - public Task HandleRequestAsync(TestRequest request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(TestRequest request, RequestContext context, CancellationToken cancellationToken) { Assert.Null(context.Solution); - return Task.FromResult(new TestResponse()); + return new TestResponse(); } } diff --git a/src/LanguageServer/ProtocolUnitTests/Rename/WillRenameTests.cs b/src/LanguageServer/ProtocolUnitTests/Rename/WillRenameTests.cs index c6fefb8c008d7..2504b2e663ec2 100644 --- a/src/LanguageServer/ProtocolUnitTests/Rename/WillRenameTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Rename/WillRenameTests.cs @@ -152,9 +152,9 @@ private class TestWillRenameListener1() : ILspWillRenameListener { public WorkspaceEdit Result { get; set; } - public Task HandleWillRenameAsync(RenameFilesParams renameParams, RequestContext context, CancellationToken cancellationToken) + public async Task HandleWillRenameAsync(RenameFilesParams renameParams, RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(Result); + return Result; } } diff --git a/src/LanguageServer/ProtocolUnitTests/Symbols/WorkspaceSymbolsTests.cs b/src/LanguageServer/ProtocolUnitTests/Symbols/WorkspaceSymbolsTests.cs index 213721f2f4ea1..329885f80e6e4 100644 --- a/src/LanguageServer/ProtocolUnitTests/Symbols/WorkspaceSymbolsTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Symbols/WorkspaceSymbolsTests.cs @@ -261,7 +261,7 @@ private static string GetContainerName(Solution solution, string? containingSymb [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] protected sealed class TestWorkspaceNavigateToSearchHostService() : IWorkspaceNavigateToSearcherHostService { - public ValueTask IsFullyLoadedAsync(CancellationToken cancellationToken) - => new(true); + public async ValueTask IsFullyLoadedAsync(CancellationToken cancellationToken) + => true; } } diff --git a/src/LanguageServer/ProtocolUnitTests/UriTests.cs b/src/LanguageServer/ProtocolUnitTests/UriTests.cs index 020f9db691c8e..9bf3c82952be9 100644 --- a/src/LanguageServer/ProtocolUnitTests/UriTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/UriTests.cs @@ -383,9 +383,9 @@ private sealed class CustomResolveHandler() : ILspServiceDocumentRequestHandler< public bool MutatesSolutionState => false; public bool RequiresLSPSolution => true; public LSP.TextDocumentIdentifier GetTextDocumentIdentifier(CustomResolveParams request) => request.TextDocument; - public Task HandleRequestAsync(CustomResolveParams request, RequestContext context, CancellationToken cancellationToken) + public async Task HandleRequestAsync(CustomResolveParams request, RequestContext context, CancellationToken cancellationToken) { - return Task.FromResult(new ResolvedDocumentInfo(context.Workspace!.Kind!, context.GetRequiredDocument().Project.Language)); + return new ResolvedDocumentInfo(context.Workspace!.Kind!, context.GetRequiredDocument().Project.Language); } } }