private async Task SearchCurrentDocumentAsync(CancellationToken cancellationToken) { if (_activeDocument == null) { return; } var project = _activeDocument.Project; var service = _host.GetNavigateToSearchService(project); if (service == null) { return; } await _progress.AddItemsAsync(1, cancellationToken).ConfigureAwait(false); try { await service.SearchDocumentAsync( _activeDocument, _searchPattern, _kinds, r => _callback.AddItemAsync(project, r, cancellationToken), cancellationToken).ConfigureAwait(false); } finally { await _progress.ItemCompletedAsync(cancellationToken).ConfigureAwait(false); } }
private async Task SearchCoreAsync(Project project, ImmutableArray<Document> priorityDocuments) { if (_searchCurrentDocument && _currentDocument?.Project != project) return; var cacheService = project.Solution.Services.CacheService; if (cacheService != null) { using (cacheService.EnableCaching(project.Id)) { var service = GetSearchService(project); if (service != null) { var searchTask = _currentDocument != null ? service.SearchDocumentAsync(_currentDocument, _searchPattern, _kinds, _cancellationToken) : service.SearchProjectAsync(project, priorityDocuments, _searchPattern, _kinds, _cancellationToken); var results = await searchTask.ConfigureAwait(false); if (results != null) { foreach (var result in results) { await _callback.AddItemAsync(project, result, _cancellationToken).ConfigureAwait(false); } } } } } }
private async Task SearchCoreAsync( Project project, ImmutableArray <Document> priorityDocuments, HashSet <INavigateToSearchResult> seenItems) { if (_searchCurrentDocument && _currentDocument?.Project != project) { return; } var cacheService = project.Solution.Services.CacheService; if (cacheService != null) { using (cacheService.EnableCaching(project.Id)) { var service = GetSearchService(project); if (service != null) { var searchTask = _currentDocument != null ? service.SearchDocumentAsync(_currentDocument, _searchPattern, _kinds, _cancellationToken) : service.SearchProjectAsync(project, priorityDocuments, _searchPattern, _kinds, _cancellationToken); var results = await searchTask.ConfigureAwait(false); if (results != null) { foreach (var result in results) { // If we're seeing a dupe in another project, then filter it out here. The results from // the individual projects will already contain the information about all the projects // leading to a better condensed view that doesn't look like it contains duplicate info. lock (seenItems) { if (!seenItems.Add(result)) { continue; } } await _callback.AddItemAsync(project, result, _cancellationToken).ConfigureAwait(false); } } } } } }
private async Task <NavigateToSearchLocation> SearchCoreAsync( Project project, bool isFullyLoaded, HashSet <INavigateToSearchResult> seenItems, CancellationToken cancellationToken) { // If they don't even support the service, then always show them as having done the // complete search. That way we don't call back into this project ever. var service = _host.GetNavigateToSearchService(project); if (service == null) { return(NavigateToSearchLocation.Latest); } if (_searchCurrentDocument) { Contract.ThrowIfNull(_currentDocument); return(await service.SearchDocumentAsync( _currentDocument, _searchPattern, _kinds, OnResultFound, isFullyLoaded, cancellationToken).ConfigureAwait(false)); } else { return(await service.SearchProjectAsync( project, GetPriorityDocuments(project), _searchPattern, _kinds, OnResultFound, isFullyLoaded, cancellationToken).ConfigureAwait(false)); } Task OnResultFound(INavigateToSearchResult result) { // If we're seeing a dupe in another project, then filter it out here. The results from // the individual projects will already contain the information about all the projects // leading to a better condensed view that doesn't look like it contains duplicate info. lock (seenItems) { if (!seenItems.Add(result)) { return(Task.CompletedTask); } } return(_callback.AddItemAsync(project, result, cancellationToken)); } }