Пример #1
0
        private async Task <Solution> FixSolutionAsync(
            Solution solution,
            FixIdContainer enabledFixIds,
            ProgressTracker progressTracker,
            CancellationToken cancellationToken)
        {
            // Prepopulate the solution progress tracker with the total number of documents to process
            foreach (var projectId in solution.ProjectIds)
            {
                var project = solution.GetProject(projectId);
                if (!CanCleanupProject(project))
                {
                    continue;
                }

                progressTracker.AddItems(project.DocumentIds.Count);
            }

            foreach (var projectId in solution.ProjectIds)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var project    = solution.GetProject(projectId);
                var newProject = await FixProjectAsync(project, enabledFixIds, progressTracker, addProgressItemsForDocuments : false, cancellationToken).ConfigureAwait(false);

                solution = newProject.Solution;
            }

            return(solution);
        }
            internal void Search()
            {
                var navigateToSearch = Logger.LogBlock(FunctionId.NavigateTo_Search, _cancellationToken);
                var asyncToken       = _asyncListener.BeginAsyncOperation(GetType() + ".Search");

                _progress.AddItems(_solution.Projects.Count());

                // make sure we run actual search from other thread. and let this thread return to caller as soon as possible.
                var dummy = Task.Run(() => Search(navigateToSearch, asyncToken), _cancellationToken);
            }
Пример #3
0
        public async Task <IEnumerable <ReferencedSymbol> > FindReferencesAsync(ISymbol symbol)
        {
            _progress.OnStarted();
            _progressTracker.AddItems(1);
            try
            {
                var symbols = await DetermineAllSymbolsAsync(symbol).ConfigureAwait(false);

                var projectMap = await CreateProjectMapAsync(symbols).ConfigureAwait(false);

                var documentMap = await CreateDocumentMapAsync(projectMap).ConfigureAwait(false);
                await ProcessAsync(documentMap).ConfigureAwait(false);
            }
            finally
            {
                _progressTracker.ItemCompleted();
                _progress.OnCompleted();
            }

            return(_foundReferences.Select(kvp => new ReferencedSymbol(kvp.Key, kvp.Value.ToImmutableArray())).ToImmutableArray());
        }
Пример #4
0
            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();
                }
            }
Пример #5
0
            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();
                }
            }
Пример #6
0
        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());

                await SearchAllProjectsAsync().ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                var service       = _solution.Workspace.Services.GetRequiredService <IWorkspaceStatusService>();
                var isFullyLoaded = await service.IsFullyLoadedAsync(_cancellationToken).ConfigureAwait(false);

                // providing this extra information will make UI to show indication to users
                // that result might not contain full data
                _callback.Done(isFullyLoaded);
            }
        }
Пример #7
0
            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 SearchProjectsInPriorityOrderAsync(docTrackingService).ConfigureAwait(false);
                    }
                    else
                    {
                        await SearchAllProjectsAsync().ConfigureAwait(false);
                    }
                }
                catch (OperationCanceledException)
                {
                }
                finally
                {
                    var service = _solution.Workspace.Services.GetService <IWorkspaceStatusService>();
                    if (_callback is INavigateToCallback2 callback2 &&
                        !await service.IsFullyLoadedAsync(_cancellationToken).ConfigureAwait(false))
                    {
                        // providing this extra information will make UI to show indication to users
                        // that result might not contain full data
                        callback2.Done(IncompleteReason.SolutionLoading);
                    }
Пример #8
0
        private async Task <Project> FixProjectAsync(
            Project project,
            FixIdContainer enabledFixIds,
            ProgressTracker progressTracker,
            bool addProgressItemsForDocuments,
            CancellationToken cancellationToken)
        {
            if (!CanCleanupProject(project))
            {
                return(project);
            }

            if (addProgressItemsForDocuments)
            {
                progressTracker.AddItems(project.DocumentIds.Count);
            }

            foreach (var documentId in project.DocumentIds)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var document = project.GetDocument(documentId);
                progressTracker.Description = document.Name;

                // FixDocumentAsync reports progress within a document, but we limit progress reporting for a project
                // to the current document.
                var documentProgressTracker = new ProgressTracker();

                var fixedDocument = await FixDocumentAsync(document, enabledFixIds, documentProgressTracker, cancellationToken).ConfigureAwait(false);

                project = fixedDocument.Project;
                progressTracker.ItemCompleted();
            }

            return(project);
        }