public void StartSearch(Workspace workspace, CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback)
        {
            var asyncToken = _asyncListener.BeginAsyncOperation(this.GetType().Name + ".Search");

            // NOTE: This task has CancellationToken.None specified, since it must complete no matter what
            // so the callback is appropriately notified that the search has terminated.
            Task.Run(async() =>
            {
                // The error message to show if we had an error. null will mean we succeeded.
                string completionErrorMessage = null;
                try
                {
                    await SearchAsync(workspace, searchScope, callback, _cancellationSource.Token).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    completionErrorMessage = EditorFeaturesResources.Canceled;
                }
                catch (Exception e) when(FatalError.ReportWithoutCrash(e))
                {
                    completionErrorMessage = e.Message;
                }
                finally
                {
                    if (completionErrorMessage != null)
                    {
                        callback.SearchFailed(completionErrorMessage);
                    }
                    else
                    {
                        callback.SearchSucceeded();
                    }
                }
            }, CancellationToken.None).CompletesAsyncOperation(asyncToken);
        }
Exemple #2
0
        // For Testing only
        internal void StartSearchWithDocuments(string categoryName, CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback, IImmutableSet <Document> documents)
        {
            var finder = _finders.FirstOrDefault(s => s.SearchCategory == categoryName);

            finder.SetDocuments(documents);
            finder.StartSearch(searchScope, callback);
        }
Exemple #3
0
        private async Task SearchAsync(ICallHierarchySearchCallback callback, CallHierarchySearchScope scope, CancellationToken cancellationToken)
        {
            callback.ReportProgress(0, 1);

            var asyncToken = _asyncListener.BeginAsyncOperation(this.GetType().Name + ".Search");

            // Follow the search task with task that lets the callback know we're done and which
            // marks the async operation as complete.  Note that we pass CancellationToken.None
            // here.  That's intentional.  This operation is *not* cancellable.

            var workspace      = _project.Solution.Workspace;
            var currentProject = workspace.CurrentSolution.GetProject(_project.Id);
            var compilation    = await currentProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

            var resolution = _symbol.Resolve(compilation, cancellationToken: cancellationToken);

            var documents = this.Documents ?? IncludeDocuments(scope, currentProject);

            var currentSymbol = resolution.Symbol;

            if (currentSymbol == null)
            {
                return;
            }

            await SearchWorkerAsync(currentSymbol, currentProject, callback, documents, cancellationToken).SafeContinueWith(
                t =>
            {
                callback.ReportProgress(1, 1);

                if (t.Status == TaskStatus.RanToCompletion)
                {
                    callback.SearchSucceeded();
                }
                else
                {
                    callback.SearchFailed(EditorFeaturesResources.Canceled);
                }

                asyncToken.Dispose();
            }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default).ConfigureAwait(false);
        }
        private async Task SearchAsync(ICallHierarchySearchCallback callback, CallHierarchySearchScope scope, CancellationToken cancellationToken)
        {
            callback.ReportProgress(0, 1);

            var asyncToken = _asyncListener.BeginAsyncOperation(this.GetType().Name + ".Search");

            // Follow the search task with task that lets the callback know we're done and which
            // marks the async operation as complete.  Note that we pass CancellationToken.None
            // here.  That's intentional.  This operation is *not* cancellable.

            var workspace = _project.Solution.Workspace;
            var currentProject = workspace.CurrentSolution.GetProject(_project.Id);
            var compilation = await currentProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
            var resolution = _symbol.Resolve(compilation, cancellationToken: cancellationToken);

            var documents = this.Documents ?? IncludeDocuments(scope, currentProject);

            var currentSymbol = resolution.Symbol;

            if (currentSymbol == null)
            {
                return;
            }

            await SearchWorkerAsync(currentSymbol, currentProject, callback, documents, cancellationToken).SafeContinueWith(
                t =>
            {
                callback.ReportProgress(1, 1);

                if (t.Status == TaskStatus.RanToCompletion)
                {
                    callback.SearchSucceeded();
                }
                else
                {
                    callback.SearchFailed(EditorFeaturesResources.Canceled);
                }

                asyncToken.Dispose();
            }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default).ConfigureAwait(false);
        }
        private IImmutableSet <Document> IncludeDocuments(CallHierarchySearchScope scope, Project project)
        {
            if (scope == CallHierarchySearchScope.CurrentDocument || scope == CallHierarchySearchScope.CurrentProject)
            {
                var documentTrackingService = project.Solution.Workspace.Services.GetService <IDocumentTrackingService>();
                if (documentTrackingService == null)
                {
                    return(null);
                }

                var activeDocument = documentTrackingService.GetActiveDocument();
                if (activeDocument != null)
                {
                    if (scope == CallHierarchySearchScope.CurrentProject)
                    {
                        var currentProject = project.Solution.GetProject(activeDocument.ProjectId);
                        if (currentProject != null)
                        {
                            return(ImmutableHashSet.CreateRange <Document>(currentProject.Documents));
                        }
                    }
                    else
                    {
                        var currentDocument = project.Solution.GetDocument(activeDocument);
                        if (currentDocument != null)
                        {
                            return(ImmutableHashSet.Create <Document>(currentDocument));
                        }
                    }

                    return(ImmutableHashSet <Document> .Empty);
                }
            }

            return(null);
        }
        private async Task SearchAsync(Workspace workspace, CallHierarchySearchScope scope, ICallHierarchySearchCallback callback, CancellationToken cancellationToken)
        {
            var project = workspace.CurrentSolution.GetProject(_projectId);

            if (project == null)
            {
                throw new Exception(string.Format(WorkspacesResources.The_symbol_0_cannot_be_located_within_the_current_solution, SymbolName));
            }

            var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

            var resolution = _symbolKey.Resolve(compilation, cancellationToken: cancellationToken);

            var symbol = resolution.Symbol;

            if (symbol == null)
            {
                throw new Exception(string.Format(WorkspacesResources.The_symbol_0_cannot_be_located_within_the_current_solution, SymbolName));
            }

            var documents = this.Documents ?? IncludeDocuments(scope, project);

            await SearchWorkerAsync(symbol, project, callback, documents, cancellationToken).ConfigureAwait(false);
        }
Exemple #7
0
 public void StartSearch(CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback)
 {
     Task.Run(() => SearchAsync(callback, searchScope, _cancellationSource.Token), _cancellationSource.Token);
 }
 public void StartSearch(CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback)
 {
     Task.Run(async () => await SearchAsync(callback, searchScope, _cancellationSource.Token).ConfigureAwait(false), _cancellationSource.Token);
 }
        private IImmutableSet<Document> IncludeDocuments(CallHierarchySearchScope scope, Project project)
        {
            if (scope == CallHierarchySearchScope.CurrentDocument || scope == CallHierarchySearchScope.CurrentProject)
            {
                var documentTrackingService = project.Solution.Workspace.Services.GetService<IDocumentTrackingService>();
                if (documentTrackingService == null)
                {
                    return null;
                }

                var activeDocument = documentTrackingService.GetActiveDocument();
                if (activeDocument != null)
                {
                    if (scope == CallHierarchySearchScope.CurrentProject)
                    {
                        var currentProject = project.Solution.GetProject(activeDocument.ProjectId);
                        if (currentProject != null)
                        {
                            return ImmutableHashSet.CreateRange<Document>(currentProject.Documents);
                        }
                    }
                    else
                    {
                        var currentDocument = project.Solution.GetDocument(activeDocument);
                        if (currentDocument != null)
                        {
                            return ImmutableHashSet.Create<Document>(currentDocument);
                        }
                    }

                    return ImmutableHashSet<Document>.Empty;
                }
            }

            return null;
        }
        internal void Navigate(CallHierarchyItem root, string searchCategory, string callSite, CallHierarchySearchScope scope = CallHierarchySearchScope.EntireSolution, IImmutableSet <Document> documents = null)
        {
            CallHierarchyItem item = null;

            this.SearchRoot(root, searchCategory, (CallHierarchyItem c) => item = c,
                            scope,
                            documents);

            if (callSite == ConvertToName(item))
            {
                var detail = item.Details.FirstOrDefault();
                if (detail != null)
                {
                    detail.NavigateTo();
                }
                else
                {
                    item.NavigateTo();
                }
            }
        }
 internal void VerifyResult(CallHierarchyItem root, string searchCategory, string[] expectedCallers, CallHierarchySearchScope scope = CallHierarchySearchScope.EntireSolution, IImmutableSet <Document> documents = null)
 {
     this.SearchRoot(root, searchCategory, (CallHierarchyItem c) =>
     {
         Assert.True(expectedCallers.Any());
         Assert.True(expectedCallers.Contains(ConvertToName(c)));
     },
                     scope,
                     documents);
 }
        internal void SearchRoot(CallHierarchyItem root, string displayName, Action <ICallHierarchyNameItem> verify, CallHierarchySearchScope scope, IImmutableSet <Document> documents = null)
        {
            var callback = new MockSearchCallback(verify);
            var category = root.SupportedSearchCategories.First(c => c.DisplayName == displayName).Name;

            if (documents != null)
            {
                root.StartSearchWithDocuments(category, scope, callback, documents);
            }
            else
            {
                root.StartSearch(category, scope, callback);
            }

            callback.WaitForCompletion();
        }
        internal void SearchRoot(CallHierarchyItem root, string displayName, Action<ICallHierarchyNameItem> verify, CallHierarchySearchScope scope, IImmutableSet<Document> documents = null)
        {
            var callback = new MockSearchCallback(verify);
            var category = root.SupportedSearchCategories.First(c => c.DisplayName == displayName).Name;
            if (documents != null)
            {
                root.StartSearchWithDocuments(category, scope, callback, documents);
            }
            else
            {
                root.StartSearch(category, scope, callback);
            }

            callback.WaitForCompletion();
        }
Exemple #14
0
        public void StartSearch(string categoryName, CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback)
        {
            var finder = _finders.FirstOrDefault(s => s.SearchCategory == categoryName);

            finder.StartSearch(searchScope, callback);
        }
 public void StartSearch(CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback)
 {
     Task.Run(() => SearchAsync(callback, searchScope, _cancellationSource.Token), _cancellationSource.Token);
 }
 internal void VerifyResult(CallHierarchyItem root, string searchCategory, string[] expectedCallers, CallHierarchySearchScope scope = CallHierarchySearchScope.EntireSolution, IImmutableSet<Document> documents = null)
 {
     this.SearchRoot(root, searchCategory, (CallHierarchyItem c) =>
         {
             Assert.True(expectedCallers.Any());
             Assert.True(expectedCallers.Contains(ConvertToName(c)));
         },
         scope,
         documents);
 }
        internal void SearchRoot(CallHierarchyItem root, string displayName, Action <ICallHierarchyNameItem> verify, CallHierarchySearchScope scope, IImmutableSet <Document> documents = null)
        {
            var callback = new MockSearchCallback(verify);

            // Assert we have the category before we try to find it to give better diagnosing
            Assert.Contains(displayName, root.SupportedSearchCategories.Select(c => c.DisplayName));
            var category = root.SupportedSearchCategories.First(c => c.DisplayName == displayName).Name;

            if (documents != null)
            {
                root.StartSearchWithDocuments(category, scope, callback, documents);
            }
            else
            {
                root.StartSearch(category, scope, callback);
            }

            callback.WaitForCompletion();
        }
        internal void Navigate(CallHierarchyItem root, string searchCategory, string callSite, CallHierarchySearchScope scope = CallHierarchySearchScope.EntireSolution, IImmutableSet<Document> documents = null)
        {
            CallHierarchyItem item = null;
            this.SearchRoot(root, searchCategory, (CallHierarchyItem c) => item = c,
                scope,
                documents);

            if (callSite == ConvertToName(item))
            {
                var detail = item.Details.FirstOrDefault();
                if (detail != null)
                {
                    detail.NavigateTo();
                }
                else
                {
                    item.NavigateTo();
                }
            }
        }
Exemple #19
0
 public void StartSearch(CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback)
 {
     Task.Run(async() => await SearchAsync(callback, searchScope, _cancellationSource.Token).ConfigureAwait(false), _cancellationSource.Token);
 }
Exemple #20
0
 // For Testing only
 internal void StartSearchWithDocuments(string categoryName, CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback, IImmutableSet<Document> documents)
 {
     var finder = _finders.FirstOrDefault(s => s.SearchCategory == categoryName);
     finder.SetDocuments(documents);
     finder.StartSearch(searchScope, callback);
 }
Exemple #21
0
 public void StartSearch(string categoryName, CallHierarchySearchScope searchScope, ICallHierarchySearchCallback callback)
 {
     var finder = _finders.FirstOrDefault(s => s.SearchCategory == categoryName);
     finder.StartSearch(searchScope, callback);
 }