public static async Task <ImmutableArray <INamedTypeSymbol> > FindTypesAsync( INamedTypeSymbol type, Solution solution, IImmutableSet <Project>?projects, bool transitive, DependentTypesKind kind, CancellationToken cancellationToken) { if (SerializableSymbolAndProjectId.TryCreate(type, solution, cancellationToken, out var serializedType)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { var projectIds = projects?.SelectAsArray(p => p.Id) ?? default; var result = await client.TryInvokeAsync <IRemoteDependentTypeFinderService, ImmutableArray <SerializableSymbolAndProjectId> >( solution, (service, solutionInfo, cancellationToken) => service.FindTypesAsync(solutionInfo, serializedType, projectIds, transitive, kind, cancellationToken), callbackTarget : null, cancellationToken).ConfigureAwait(false); if (!result.HasValue) { return(ImmutableArray <INamedTypeSymbol> .Empty); } return(await RehydrateAsync(solution, result.Value, cancellationToken).ConfigureAwait(false)); } // TODO: Do not fall back to in-proc https://github.com/dotnet/roslyn/issues/47557 } return(await FindTypesInCurrentProcessAsync(type, solution, projects, transitive, kind, cancellationToken).ConfigureAwait(false)); }
internal static async Task <ConflictResolution> RenameSymbolAsync( Solution solution, ISymbol symbol, string newName, RenameOptionSet optionSet, ImmutableHashSet <ISymbol>?nonConflictSymbols, CancellationToken cancellationToken) { Contract.ThrowIfNull(solution); Contract.ThrowIfNull(symbol); Contract.ThrowIfTrue(string.IsNullOrEmpty(newName)); cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Renamer_RenameSymbolAsync, cancellationToken)) { if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { var options = SerializableRenameOptionSet.Dehydrate(optionSet); var nonConflictSymbolIds = nonConflictSymbols?.SelectAsArray(s => SerializableSymbolAndProjectId.Dehydrate(solution, s, cancellationToken)) ?? default; var result = await client.TryInvokeAsync <IRemoteRenamerService, SerializableConflictResolution?>( solution, (service, solutionInfo, cancellationToken) => service.RenameSymbolAsync( solutionInfo, serializedSymbol, newName, options, nonConflictSymbolIds, cancellationToken), callbackTarget : null, cancellationToken).ConfigureAwait(false); if (result.HasValue && result.Value != null) { return(await result.Value.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false)); } // TODO: do not fall back to in-proc if client is available (https://github.com/dotnet/roslyn/issues/47557) } } } return(await RenameSymbolInCurrentProcessAsync( solution, symbol, newName, optionSet, nonConflictSymbols, cancellationToken).ConfigureAwait(false)); }
internal static async Task <ConflictResolution> RenameSymbolAsync( Solution solution, ISymbol symbol, string newName, RenameOptionSet optionSet, ImmutableHashSet <ISymbol>?nonConflictSymbols, CancellationToken cancellationToken) { Contract.ThrowIfNull(solution); Contract.ThrowIfNull(symbol); Contract.ThrowIfTrue(string.IsNullOrEmpty(newName)); cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Renamer_RenameSymbolAsync, cancellationToken)) { if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { var result = await client.TryRunRemoteAsync <SerializableConflictResolution?>( WellKnownServiceHubService.CodeAnalysis, nameof(IRemoteRenamer.RenameSymbolAsync), solution, new object?[] { serializedSymbol, newName, SerializableRenameOptionSet.Dehydrate(optionSet), nonConflictSymbols?.Select(s => SerializableSymbolAndProjectId.Dehydrate(solution, s, cancellationToken)).ToArray(), }, callbackTarget : null, cancellationToken).ConfigureAwait(false); if (result.HasValue && result.Value != null) { return(await result.Value.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false)); } } } } return(await RenameSymbolInCurrentProcessAsync( solution, symbol, newName, optionSet, nonConflictSymbols, cancellationToken).ConfigureAwait(false)); }
internal static async Task FindReferencesAsync( ISymbol symbol, Solution solution, IStreamingFindReferencesProgress progress, IImmutableSet <Document> documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.FindReference, cancellationToken)) { if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { // Create a callback that we can pass to the server process to hear about the // results as it finds them. When we hear about results we'll forward them to // the 'progress' parameter which will then update the UI. var serverCallback = new FindReferencesServerCallback(solution, progress, cancellationToken); var success = await client.TryRunRemoteAsync( WellKnownServiceHubService.CodeAnalysis, nameof(IRemoteSymbolFinder.FindReferencesAsync), solution, new object[] { serializedSymbol, documents?.Select(d => d.Id).ToArray(), SerializableFindReferencesSearchOptions.Dehydrate(options), }, serverCallback, cancellationToken).ConfigureAwait(false); if (success) { return; } } } // Couldn't effectively search in OOP. Perform the search in-proc. await FindReferencesInCurrentProcessAsync( symbol, solution, progress, documents, options, cancellationToken).ConfigureAwait(false); } }
/// <summary> /// Find the locations that need to be renamed. Can cross process boundaries efficiently to do this. /// </summary> public static async Task <LightweightRenameLocations> FindRenameLocationsAsync( ISymbol symbol, Solution solution, SymbolRenameOptions options, CodeCleanupOptionsProvider fallbackOptions, CancellationToken cancellationToken) { Contract.ThrowIfNull(solution); Contract.ThrowIfNull(symbol); cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Renamer_FindRenameLocationsAsync, cancellationToken)) { if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { var result = await client.TryInvokeAsync <IRemoteRenamerService, SerializableRenameLocations?>( solution, (service, solutionInfo, callbackId, cancellationToken) => service.FindRenameLocationsAsync(solutionInfo, callbackId, serializedSymbol, options, cancellationToken), callbackTarget : new RemoteOptionsProvider <CodeCleanupOptions>(solution.Workspace.Services, fallbackOptions), cancellationToken).ConfigureAwait(false); if (result.HasValue && result.Value != null) { var rehydrated = await TryRehydrateAsync( solution, symbol, fallbackOptions, result.Value, cancellationToken).ConfigureAwait(false); if (rehydrated != null) { return(rehydrated); } } // TODO: do not fall back to in-proc if client is available (https://github.com/dotnet/roslyn/issues/47557) } } } // Couldn't effectively search in OOP. Perform the search in-proc. var renameLocations = await HeavyweightRenameLocations.FindLocationsInCurrentProcessAsync( symbol, solution, options, fallbackOptions, cancellationToken).ConfigureAwait(false); return(new LightweightRenameLocations( symbol, solution, options, fallbackOptions, renameLocations.Locations, renameLocations.ImplicitLocations.IsDefault ? null : renameLocations.ImplicitLocations.Select(loc => SerializableReferenceLocation.Dehydrate(loc, cancellationToken)).ToArray(), renameLocations.ReferencedSymbols.IsDefault ? null : renameLocations.ReferencedSymbols.Select(sym => SerializableSymbolAndProjectId.Dehydrate(solution, sym, cancellationToken)).ToArray())); }
public static async Task <RenameLocations> FindLocationsAsync( ISymbol symbol, Solution solution, RenameOptionSet optionSet, CancellationToken cancellationToken) { Contract.ThrowIfNull(solution); Contract.ThrowIfNull(symbol); cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Renamer_FindRenameLocationsAsync, cancellationToken)) { if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { var result = await client.RunRemoteAsync <SerializableRenameLocations?>( WellKnownServiceHubService.CodeAnalysis, nameof(IRemoteRenamer.FindRenameLocationsAsync), solution, new object[] { serializedSymbol, SerializableRenameOptionSet.Dehydrate(optionSet), }, callbackTarget : null, cancellationToken).ConfigureAwait(false); if (result != null) { var rehydrated = await RenameLocations.TryRehydrateAsync( solution, result, cancellationToken).ConfigureAwait(false); if (rehydrated != null) { return(rehydrated); } } } } } // Couldn't effectively search in OOP. Perform the search in-proc. return(await FindLocationsInCurrentProcessAsync( symbol, solution, optionSet, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Find the locations that need to be renamed. /// </summary> public static async Task <RenameLocations> FindLocationsAsync( ISymbol symbol, Solution solution, RenameOptionSet optionSet, CancellationToken cancellationToken) { Contract.ThrowIfNull(solution); Contract.ThrowIfNull(symbol); cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Renamer_FindRenameLocationsAsync, cancellationToken)) { if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { var options = SerializableRenameOptionSet.Dehydrate(optionSet); var result = await client.TryInvokeAsync <IRemoteRenamerService, SerializableRenameLocations?>( solution, (service, solutionInfo, cancellationToken) => service.FindRenameLocationsAsync(solutionInfo, serializedSymbol, options, cancellationToken), callbackTarget : null, cancellationToken).ConfigureAwait(false); if (result.HasValue && result.Value != null) { var rehydrated = await TryRehydrateAsync( solution, result.Value, cancellationToken).ConfigureAwait(false); if (rehydrated != null) { return(rehydrated); } } // TODO: do not fall back to in-proc if client is available (https://github.com/dotnet/roslyn/issues/47557) } } } // Couldn't effectively search in OOP. Perform the search in-proc. return(await FindLocationsInCurrentProcessAsync( symbol, solution, optionSet, cancellationToken).ConfigureAwait(false)); }
public static async Task <ImmutableArray <INamedTypeSymbol>?> TryFindRemoteTypesAsync( INamedTypeSymbol type, Solution solution, IImmutableSet <Project> projects, bool transitive, FunctionId functionId, string remoteFunctionName, CancellationToken cancellationToken) { using (Logger.LogBlock(functionId, cancellationToken)) { if (SerializableSymbolAndProjectId.TryCreate(type, solution, cancellationToken, out var serializedType)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { var result = await client.TryRunRemoteAsync <ImmutableArray <SerializableSymbolAndProjectId> >( WellKnownServiceHubService.CodeAnalysis, remoteFunctionName, solution, new object?[] { serializedType, projects?.Select(p => p.Id).ToArray(), transitive, }, null, cancellationToken).ConfigureAwait(false); if (result.HasValue) { return(await RehydrateAsync(solution, result.Value, cancellationToken).ConfigureAwait(false)); } } } } return(null); }
internal static async Task FindReferencesAsync( ISymbol symbol, Solution solution, IStreamingFindReferencesProgress progress, IImmutableSet <Document> documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.FindReference, cancellationToken)) { if (SerializableSymbolAndProjectId.TryCreate(symbol, solution, cancellationToken, out var serializedSymbol)) { var client = await RemoteHostClient.TryGetClientAsync(solution.Workspace, cancellationToken).ConfigureAwait(false); if (client != null) { // Create a callback that we can pass to the server process to hear about the // results as it finds them. When we hear about results we'll forward them to // the 'progress' parameter which will then update the UI. var serverCallback = new FindReferencesServerCallback(solution, progress, cancellationToken); var documentIds = documents?.SelectAsArray(d => d.Id) ?? default; await client.TryInvokeAsync <IRemoteSymbolFinderService>( solution, (service, solutionInfo, callbackId, cancellationToken) => service.FindReferencesAsync(solutionInfo, callbackId, serializedSymbol, documentIds, options, cancellationToken), serverCallback, cancellationToken).ConfigureAwait(false); return; } } // Couldn't effectively search in OOP. Perform the search in-proc. await FindReferencesInCurrentProcessAsync( symbol, solution, progress, documents, options, cancellationToken).ConfigureAwait(false); } }