提交 3ce7b422 编写于 作者: C Cyrus Najmabadi

Extract helpers.

上级 0785a6ee
...@@ -71,6 +71,10 @@ internal async void Search() ...@@ -71,6 +71,10 @@ internal async void Search()
_progress.AddItems(_solution.Projects.Count()); _progress.AddItems(_solution.Projects.Count());
var workspace = _solution.Workspace; 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>(); var docTrackingService = workspace.Services.GetService<IDocumentTrackingService>();
if (docTrackingService != null) if (docTrackingService != null)
{ {
...@@ -95,12 +99,9 @@ private async Task SearchProjectsInPriorityOrder(IDocumentTrackingService docTra ...@@ -95,12 +99,9 @@ private async Task SearchProjectsInPriorityOrder(IDocumentTrackingService docTra
{ {
var processedProjects = new HashSet<Project>(); var processedProjects = new HashSet<Project>();
var activeDocOpt = _solution.GetDocument(docTrackingService.GetActiveDocument()); var activeDocOpt = docTrackingService.GetActiveDocument(_solution);
var visibleDocs = docTrackingService.GetVisibleDocuments() var visibleDocs = docTrackingService.GetVisibleDocuments(_solution)
.Select(d => _solution.GetDocument(d))
.Where(d => d != activeDocOpt) .Where(d => d != activeDocOpt)
.WhereNotNull()
.Distinct()
.ToImmutableArray(); .ToImmutableArray();
// First, if there's an active document, search that project first, prioritizing // First, if there's an active document, search that project first, prioritizing
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Linq;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
internal static class IDocumentTrackingServiceExtensions
{
/// <summary>
/// Gets the active <see cref="Document"/> the user is currently working in. May be null if
/// there is no active document or the active document is not in this <paramref name="solution"/>.
/// </summary>
public static Document GetActiveDocument(this IDocumentTrackingService service, Solution solution)
{
// Note: GetDocument checks that the DocId is contained in the solution, and returns null if not.
return solution.GetDocument(service.GetActiveDocument());
}
/// <summary>
/// Get a read only collection of all the unique visible documents in the workspace that are
/// contained within <paramref name="solution"/>.
/// </summary>
public static ImmutableArray<Document> GetVisibleDocuments(this IDocumentTrackingService service, Solution solution)
=> service.GetVisibleDocuments()
.Select(d => solution.GetDocument(d))
.WhereNotNull()
.Distinct()
.ToImmutableArray();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册