public async Task SearchProjectAsync( Project project, ImmutableArray <Document> priorityDocuments, string searchPattern, IImmutableSet <string> kinds, Func <INavigateToSearchResult, Task> onResultFound, CancellationToken cancellationToken) { var solution = project.Solution; var client = await RemoteHostClient.TryGetClientAsync(project, cancellationToken).ConfigureAwait(false); var onItemFound = GetOnItemFoundCallback(solution, onResultFound, cancellationToken); if (client != null) { var priorityDocumentIds = priorityDocuments.SelectAsArray(d => d.Id); var callback = new NavigateToSearchServiceCallback(onItemFound); await client.TryInvokeAsync <IRemoteNavigateToSearchService>( solution, (service, solutionInfo, callbackId, cancellationToken) => service.SearchProjectAsync(solutionInfo, project.Id, priorityDocumentIds, searchPattern, kinds.ToImmutableArray(), callbackId, cancellationToken), callback, cancellationToken).ConfigureAwait(false); return; } await SearchProjectInCurrentProcessAsync(project, priorityDocuments, searchPattern, kinds, onItemFound, cancellationToken).ConfigureAwait(false); }
private static async Task SearchFullyLoadedDocumentAsync( Document document, string searchPattern, IImmutableSet <string> kinds, Func <INavigateToSearchResult, Task> onResultFound, CancellationToken cancellationToken) { var solution = document.Project.Solution; var onItemFound = GetOnItemFoundCallback(solution, onResultFound, cancellationToken); var client = await RemoteHostClient.TryGetClientAsync(document.Project, cancellationToken).ConfigureAwait(false); if (client != null) { var callback = new NavigateToSearchServiceCallback(onItemFound); await client.TryInvokeAsync <IRemoteNavigateToSearchService>( solution, (service, solutionInfo, callbackId, cancellationToken) => service.SearchFullyLoadedDocumentAsync(solutionInfo, document.Id, searchPattern, kinds.ToImmutableArray(), callbackId, cancellationToken), callback, cancellationToken).ConfigureAwait(false); return; } await SearchFullyLoadedDocumentInCurrentProcessAsync( document, searchPattern, kinds, onItemFound, cancellationToken).ConfigureAwait(false); }
private static async Task SearchCachedDocumentsAsync( ImmutableArray <Document> documents, ImmutableArray <Document> priorityDocuments, string searchPattern, IImmutableSet <string> kinds, Func <INavigateToSearchResult, Task> onResultFound, CancellationToken cancellationToken) { var document = documents.FirstOrDefault() ?? priorityDocuments.FirstOrDefault(); if (document == null) { return; } var project = document.Project; var solution = project.Solution; var client = await RemoteHostClient.TryGetClientAsync(project, cancellationToken).ConfigureAwait(false); var onItemFound = GetOnItemFoundCallback(solution, onResultFound, cancellationToken); var database = solution.Options.GetPersistentStorageDatabase(); var documentKeys = project.Documents.Select(d => DocumentKey.ToDocumentKey(d)).ToImmutableArray(); var priorityDocumentKeys = priorityDocuments.SelectAsArray(d => DocumentKey.ToDocumentKey(d)); if (client != null) { var callback = new NavigateToSearchServiceCallback(onItemFound); await client.TryInvokeAsync <IRemoteNavigateToSearchService>( (service, callbackId, cancellationToken) => service.SearchCachedDocumentsAsync(documentKeys, priorityDocumentKeys, database, searchPattern, kinds.ToImmutableArray(), callbackId, cancellationToken), callback, cancellationToken).ConfigureAwait(false); return; } await SearchCachedDocumentsInCurrentProcessAsync( solution.Workspace.Services, documentKeys, priorityDocumentKeys, database, searchPattern, kinds, onItemFound, cancellationToken).ConfigureAwait(false); }