diff --git a/src/VisualStudio/Core/Next/CodeLens/RemoteCodeLensReferencesService.cs b/src/VisualStudio/Core/Next/CodeLens/RemoteCodeLensReferencesService.cs index af13826508b1419f045285f4897907d939a7843e..febf8d5c6f71f5fb9eee7ff1540851fefb5de4f1 100644 --- a/src/VisualStudio/Core/Next/CodeLens/RemoteCodeLensReferencesService.cs +++ b/src/VisualStudio/Core/Next/CodeLens/RemoteCodeLensReferencesService.cs @@ -7,10 +7,9 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeLens; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Remote; using Microsoft.CodeAnalysis.Remote.Diagnostics; -using Microsoft.VisualStudio.LanguageServices.Implementation.Extensions; -using Microsoft.VisualStudio.LanguageServices.Remote; namespace Microsoft.VisualStudio.LanguageServices.CodeLens { @@ -20,85 +19,97 @@ internal sealed class RemoteCodeLensReferencesService : ICodeLensReferencesServi public async Task GetReferenceCountAsync(Solution solution, DocumentId documentId, SyntaxNode syntaxNode, int maxSearchResults, CancellationToken cancellationToken) { - if (syntaxNode == null) + using (Logger.LogBlock(FunctionId.CodeLens_GetReferenceCountAsync, cancellationToken)) { - return null; - } + if (syntaxNode == null) + { + return null; + } - var remoteHostClient = await solution.Workspace.Services.GetService().TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); - if (remoteHostClient == null) - { - // remote host is not running. this can happen if remote host is disabled. - return await CodeLensReferencesServiceFactory.Instance.GetReferenceCountAsync(solution, documentId, syntaxNode, maxSearchResults, cancellationToken).ConfigureAwait(false); - } + var remoteHostClient = await solution.Workspace.Services.GetService().TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); + if (remoteHostClient == null) + { + // remote host is not running. this can happen if remote host is disabled. + return await CodeLensReferencesServiceFactory.Instance.GetReferenceCountAsync(solution, documentId, syntaxNode, maxSearchResults, cancellationToken).ConfigureAwait(false); + } - // TODO: send telemetry on session - return await remoteHostClient.RunCodeAnalysisServiceOnRemoteHostAsync( - solution, WellKnownServiceHubServices.CodeAnalysisService_GetReferenceCountAsync, - new object[] { new CodeLensArguments(documentId, syntaxNode), maxSearchResults }, cancellationToken).ConfigureAwait(false); + // TODO: send telemetry on session + return await remoteHostClient.RunCodeAnalysisServiceOnRemoteHostAsync( + solution, WellKnownServiceHubServices.CodeAnalysisService_GetReferenceCountAsync, + new object[] { new CodeLensArguments(documentId, syntaxNode), maxSearchResults }, cancellationToken).ConfigureAwait(false); + } } public async Task> FindReferenceLocationsAsync(Solution solution, DocumentId documentId, SyntaxNode syntaxNode, CancellationToken cancellationToken) { - if (syntaxNode == null) + using (Logger.LogBlock(FunctionId.CodeLens_FindReferenceLocationsAsync, cancellationToken)) { - return null; - } + if (syntaxNode == null) + { + return null; + } - var remoteHostClient = await solution.Workspace.Services.GetService().TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); - if (remoteHostClient == null) - { - // remote host is not running. this can happen if remote host is disabled. - return await CodeLensReferencesServiceFactory.Instance.FindReferenceLocationsAsync(solution, documentId, syntaxNode, cancellationToken).ConfigureAwait(false); - } + var remoteHostClient = await solution.Workspace.Services.GetService().TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); + if (remoteHostClient == null) + { + // remote host is not running. this can happen if remote host is disabled. + return await CodeLensReferencesServiceFactory.Instance.FindReferenceLocationsAsync(solution, documentId, syntaxNode, cancellationToken).ConfigureAwait(false); + } - // TODO: send telemetry on session - return await remoteHostClient.RunCodeAnalysisServiceOnRemoteHostAsync>( - solution, WellKnownServiceHubServices.CodeAnalysisService_FindReferenceLocationsAsync, - new CodeLensArguments(documentId, syntaxNode), cancellationToken).ConfigureAwait(false); + // TODO: send telemetry on session + return await remoteHostClient.RunCodeAnalysisServiceOnRemoteHostAsync>( + solution, WellKnownServiceHubServices.CodeAnalysisService_FindReferenceLocationsAsync, + new CodeLensArguments(documentId, syntaxNode), cancellationToken).ConfigureAwait(false); + } } public async Task> FindReferenceMethodsAsync(Solution solution, DocumentId documentId, SyntaxNode syntaxNode, CancellationToken cancellationToken) { - if (syntaxNode == null) + using (Logger.LogBlock(FunctionId.CodeLens_FindReferenceMethodsAsync, cancellationToken)) { - return null; - } + if (syntaxNode == null) + { + return null; + } - var remoteHostClient = await solution.Workspace.Services.GetService().TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); - if (remoteHostClient == null) - { - // remote host is not running. this can happen if remote host is disabled. - return await CodeLensReferencesServiceFactory.Instance.FindReferenceMethodsAsync(solution, documentId, syntaxNode, cancellationToken).ConfigureAwait(false); - } + var remoteHostClient = await solution.Workspace.Services.GetService().TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); + if (remoteHostClient == null) + { + // remote host is not running. this can happen if remote host is disabled. + return await CodeLensReferencesServiceFactory.Instance.FindReferenceMethodsAsync(solution, documentId, syntaxNode, cancellationToken).ConfigureAwait(false); + } - // TODO: send telemetry on session - return await remoteHostClient.RunCodeAnalysisServiceOnRemoteHostAsync>( - solution, WellKnownServiceHubServices.CodeAnalysisService_FindReferenceMethodsAsync, - new CodeLensArguments(documentId, syntaxNode), cancellationToken).ConfigureAwait(false); + // TODO: send telemetry on session + return await remoteHostClient.RunCodeAnalysisServiceOnRemoteHostAsync>( + solution, WellKnownServiceHubServices.CodeAnalysisService_FindReferenceMethodsAsync, + new CodeLensArguments(documentId, syntaxNode), cancellationToken).ConfigureAwait(false); + } } public async Task GetFullyQualifiedName(Solution solution, DocumentId documentId, SyntaxNode syntaxNode, CancellationToken cancellationToken) { - if (syntaxNode == null) + using (Logger.LogBlock(FunctionId.CodeLens_GetFullyQualifiedName, cancellationToken)) { - return null; - } + if (syntaxNode == null) + { + return null; + } - var remoteHostClient = await solution.Workspace.Services.GetService().TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); - if (remoteHostClient == null) - { - // remote host is not running. this can happen if remote host is disabled. - return await CodeLensReferencesServiceFactory.Instance.GetFullyQualifiedName(solution, documentId, syntaxNode, cancellationToken).ConfigureAwait(false); - } + var remoteHostClient = await solution.Workspace.Services.GetService().TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); + if (remoteHostClient == null) + { + // remote host is not running. this can happen if remote host is disabled. + return await CodeLensReferencesServiceFactory.Instance.GetFullyQualifiedName(solution, documentId, syntaxNode, cancellationToken).ConfigureAwait(false); + } - // TODO: send telemetry on session - return await remoteHostClient.RunCodeAnalysisServiceOnRemoteHostAsync( - solution, WellKnownServiceHubServices.CodeAnalysisService_GetFullyQualifiedName, - new CodeLensArguments(documentId, syntaxNode), cancellationToken).ConfigureAwait(false); + // TODO: send telemetry on session + return await remoteHostClient.RunCodeAnalysisServiceOnRemoteHostAsync( + solution, WellKnownServiceHubServices.CodeAnalysisService_GetFullyQualifiedName, + new CodeLensArguments(documentId, syntaxNode), cancellationToken).ConfigureAwait(false); + } } } } diff --git a/src/Workspaces/Core/Portable/Log/FunctionId.cs b/src/Workspaces/Core/Portable/Log/FunctionId.cs index 0d550e0678b78b95f86404b1e1e5c20f76a766a7..444634c715660a42910a510ef8ae57bbef83263a 100644 --- a/src/Workspaces/Core/Portable/Log/FunctionId.cs +++ b/src/Workspaces/Core/Portable/Log/FunctionId.cs @@ -366,5 +366,9 @@ internal enum FunctionId RemoteHost_Connect, RemoteHost_Disconnect, CodeAnalysisService_GetTodoCommentsAsync, + CodeLens_GetReferenceCountAsync, + CodeLens_FindReferenceLocationsAsync, + CodeLens_FindReferenceMethodsAsync, + CodeLens_GetFullyQualifiedName, } }