public static SerializableSearchResult?Dehydrate( Solution solution, RenameLocations.SearchResult?result, CancellationToken cancellationToken ) => result == null ? null : new SerializableSearchResult { Locations = result.Locations .Select(loc => SerializableRenameLocation.Dehydrate(loc)) .ToArray(), ImplicitLocations = result.ImplicitLocations.IsDefault ? null : result.ImplicitLocations .Select( loc => SerializableReferenceLocation.Dehydrate(loc, cancellationToken) ) .ToArray(), ReferencedSymbols = result.ReferencedSymbols.IsDefault ? null : result.ReferencedSymbols .Select( s => SerializableSymbolAndProjectId.Dehydrate( solution, s, cancellationToken ) ) .ToArray(), };
/// <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())); }