public async void StartSearch(INavigateToCallback callback, string searchValue) { CancellationTokenSource searchCts; if (_library == null) { callback.Done(); return; } try { searchCts = new CancellationTokenSource(); var oldCts = Interlocked.Exchange(ref _searchCts, searchCts); if (oldCts != null) { oldCts.Cancel(); oldCts.Dispose(); } await _library.VisitNodesAsync( new LibraryNodeVisitor(this, callback, searchValue, _matchMode), searchCts.Token ); } catch (OperationCanceledException) { } catch (Exception ex) when(!ex.IsCriticalException()) { ex.ReportUnhandledException(_serviceProvider, GetType()); } finally { callback.Done(); } }
internal async Task SearchAsync() { try { using var navigateToSearch = Logger.LogBlock(FunctionId.NavigateTo_Search, KeyValueLogMessage.Create(LogType.UserAction), _cancellationToken); using var asyncToken = _asyncListener.BeginAsyncOperation(GetType() + ".Search"); _progress.AddItems(_solution.Projects.Count()); var workspace = _solution.Workspace; // If the workspace is tracking documents, use that to prioritize our search // order. That way we provide results for the documents the user is working // on faster than the rest of the solution. var docTrackingService = workspace.Services.GetService <IDocumentTrackingService>(); if (docTrackingService != null) { await SearchProjectsInPriorityOrder(docTrackingService).ConfigureAwait(false); } else { await SearchAllProjectsAsync().ConfigureAwait(false); } } catch (OperationCanceledException) { } finally { _callback.Done(); } }
private void StartSearch(INavigateToCallback callback, string searchValue, IImmutableSet <string> kinds) { this.StopSearch(); if (string.IsNullOrWhiteSpace(searchValue)) { callback.Done(); return; } if (kinds == null || kinds.Count == 0) { kinds = KindsProvided; } var searchCurrentDocument = (callback.Options as INavigateToOptions2)?.SearchCurrentDocument ?? false; var searcher = new Searcher( _workspace.CurrentSolution, _asyncListener, _displayFactory, callback, searchValue, searchCurrentDocument, kinds, _cancellationTokenSource.Token); _ = searcher.SearchAsync(); }
private void DoWork(object unused) { try { var fileList = GetFiles(); var parallelOptions = new ParallelOptions(); parallelOptions.CancellationToken = _cancellationToken; parallelOptions.MaxDegreeOfParallelism = Environment.ProcessorCount; Parallel.For(0, fileList.Count, parallelOptions, i => { string file = fileList[i]; IEnumerable <ParseItem> items = GetItems(file, _searchValue); foreach (ParseItem sel in items) { _cancellationToken.ThrowIfCancellationRequested(); _navigateToCallback.AddItem(new NavigateToItem(_searchValue, NavigateToItemKind.Field, "CSS", _searchValue, new CssGoToLineTag(sel, file), MatchKind.Exact, _providerFactory)); } var backgroundProgress = Interlocked.Increment(ref _backgroundProgress); _navigateToCallback.ReportProgress(backgroundProgress, fileList.Count); }); } catch { // Don't let exceptions from the background thread reach the ThreadPool. Swallow them // here and complete the navigate operation } finally { _navigateToCallback.Done(); } }
public async void StartSearch(INavigateToCallback callback, string searchValue) { CancellationTokenSource searchCts = null; try { searchCts = new CancellationTokenSource(); var oldCts = Interlocked.Exchange(ref _searchCts, searchCts); try { oldCts?.Cancel(); oldCts?.Dispose(); } catch (ObjectDisposedException) { } CancellationToken token; try { token = searchCts.Token; } catch (ObjectDisposedException) { // highly unlikely race, but easy enough to protect against return; } await FindMatchesAsync(callback, searchValue, token); } catch (OperationCanceledException) { } catch (Exception ex) when(!ex.IsCriticalException()) { ex.ReportUnhandledException(_services.Site, GetType()); } finally { callback.Done(); if (searchCts != null) { Interlocked.CompareExchange(ref _searchCts, null, searchCts); searchCts.Dispose(); } } }
public void StartSearch(INavigateToCallback callback, string searchValue) { this.StopSearch(); if (string.IsNullOrWhiteSpace(searchValue)) { callback.Done(); return; } var optionsService = _optionsServices.Length > 0 ? VersionSelector.SelectHighest(_optionsServices) : null; var searchCurrentDocument = optionsService?.GetSearchCurrentDocument(callback.Options) ?? false; var searcher = new Searcher( _workspace.CurrentSolution, _asyncListener, _displayFactory, callback, searchValue, searchCurrentDocument, _cancellationTokenSource.Token); searcher.Search(); }
private async Task FindMatchesAsync(INavigateToCallback callback, string searchValue, CancellationToken token) { #if USE_15_5 foreach (var a in _analyzers) { a.Task = null; a.Result = null; } callback.Done(); }
public void Done(bool isFullyLoaded) { if (!isFullyLoaded && _callback is INavigateToCallback2 callback2) { callback2.Done(IncompleteReason.SolutionLoading); } else { _callback.Done(); } }
public void StartSearch(INavigateToCallback callback, string searchValue) { var textView = GetCurrentTextView(); if (textView == null) { callback.Done(); return; } var cancellationTokenSource = new CancellationTokenSource(); _searchCancellationTokenSource = cancellationTokenSource; var cancellationToken = cancellationTokenSource.Token; var snapshot = textView.TextSnapshot; Task.Run(() => { try { var syntaxTree = snapshot.GetSyntaxTree(cancellationToken); var visitor = new NavigateToVisitor( searchValue, snapshot, textView, callback, _bufferGraphFactoryService, _navigateToItemProviderFactory, _glyphService, cancellationToken); visitor.Visit(syntaxTree.Root); } catch (OperationCanceledException) { } finally { callback.Done(); } }, cancellationToken); }
public void StartSearch(INavigateToCallback callback, string searchValue) { Debug.Assert(_currentWorker == null); if (searchValue.Length > 0 && (searchValue[0] == '.' || searchValue[0] == '#')) { _currentWorker = new Worker(_owner, callback, searchValue); } else { callback.Done(); } }
private void Search(IDisposable navigateToSearch, IAsyncToken asyncToken) { var searchTasks = _solution.Projects.Select(SearchAsync).ToArray(); var whenAllTask = Task.WhenAll(searchTasks); // NOTE(cyrusn) This SafeContinueWith is *not* cancellable. We must dispose of the notifier // in order for tests to work property. Also, if we don't notify the callback that we're // done then the UI will never stop displaying the progress bar. whenAllTask.SafeContinueWith(_ => { _callback.Done(); navigateToSearch.Dispose(); asyncToken.Dispose(); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); }
public void StartSearch(INavigateToCallback callback, string searchValue) { this.StopSearch(); if (string.IsNullOrWhiteSpace(searchValue)) { callback.Done(); return; } var searcher = new Searcher( _workspace.CurrentSolution, _asyncListener, _displayFactory, callback, searchValue, _cancellationTokenSource.Token); searcher.Search(); }
internal async void Search() { try { using (var navigateToSearch = Logger.LogBlock(FunctionId.NavigateTo_Search, _cancellationToken)) using (var asyncToken = _asyncListener.BeginAsyncOperation(GetType() + ".Search")) { _progress.AddItems(_solution.Projects.Count()); // Search each project with an independent threadpool task. var searchTasks = _solution.Projects.Select( p => Task.Run(() => SearchAsync(p))).ToArray(); await Task.WhenAll(searchTasks).ConfigureAwait(false); } } finally { _callback.Done(); } }
public void StartSearch(INavigateToCallback callback, string searchValue) { var libraryManager = (LibraryManager)_serviceProvider.GetService(typeof(IPythonLibraryManager)); var library = libraryManager.Library; var searchCts = new CancellationTokenSource(); var oldCts = Interlocked.Exchange(ref _searchCts, searchCts); if (oldCts != null) { oldCts.Dispose(); } var pyService = _serviceProvider.GetPythonToolsService(); Task.Run(() => { try { library.VisitNodes(new LibraryNodeVisitor(pyService, this, callback, searchValue), searchCts.Token); } finally { callback.Done(); } }).HandleAllExceptions(SR.ProductName, GetType()).DoNotWait(); }
private void Search(INavigateToCallback callback, string searchValue) { var i = 0; foreach (var file in Util.GetSolutionAllSdmapFiles(_serviceProvider)) { if (_cancellationTokenSource.IsCancellationRequested) { break; } i += 1; foreach (var match in SdmapIdListener.FindMatches(file, searchValue)) { callback.AddItem(match.ToNavigateToItem(_navigateToItemDisplayFactory)); } callback.ReportProgress(i, Math.Max(100, i + 1)); } callback.Done(); }
internal async void Search() { try { //using (var navigateToSearch = Logger.LogBlock(FunctionId.NavigateTo_Search, KeyValueLogMessage.Create(LogType.UserAction), _cancellationToken)) using (var asyncToken = _asyncListener.BeginAsyncOperation(GetType() + ".Search")) { if (_searchCurrentDocument) { _progress.AddItems(_currentDocuments.Length); foreach (var currentDocument in _currentDocuments) { await SearchAsync(currentDocument).ConfigureAwait(false); } } else { var documents = _workspace.CurrentDocuments.Documents.ToImmutableArray(); _progress.AddItems(documents.Length); foreach (var document in documents) { await SearchAsync(document).ConfigureAwait(false); } } } } catch (OperationCanceledException) { } finally { _callback.Done(); } }
void INavigateToItemProvider.StartSearch(INavigateToCallback callback, string searchValue) { _searchText = searchValue; _threadCommunicator.StartSearch(searchValue); callback.Done(); }
public void StartSearch(INavigateToCallback callback, string searchValue) { var libraryManager = (LibraryManager)_serviceProvider.GetService(typeof(IPythonLibraryManager)); var library = libraryManager.Library; var searchCts = new CancellationTokenSource(); var oldCts = Interlocked.Exchange(ref _searchCts, searchCts); if (oldCts != null) { oldCts.Dispose(); } var pyService = _serviceProvider.GetPythonToolsService(); Task.Run(() => { try { library.VisitNodes(new LibraryNodeVisitor(pyService, this, callback, searchValue), searchCts.Token); } finally { callback.Done(); } }).HandleAllExceptions(_serviceProvider, GetType()).DoNotWait(); }
void INavigateToItemProvider.StartSearch(INavigateToCallback callback, string searchValue) { _threadCommunicator.StartSearch(); callback.Done(); }