Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.Internal.NavigateTo;
[ExportLanguageService(typeof(INavigateToSearchService), LanguageNames.FSharp)]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal class FSharpNavigateToSearchService([Import(AllowDefault = true)] IFSharpNavigateToSearchService? service) : INavigateToSearchService
internal class FSharpNavigateToSearchService([Import(AllowDefault = true)] IFSharpNavigateToSearchService? service) : IAdvancedNavigateToSearchService
{
private readonly IFSharpNavigateToSearchService? _service = service;

Expand All @@ -33,7 +33,7 @@ public async Task SearchDocumentAsync(
Func<ImmutableArray<INavigateToSearchResult>, Task> onResultsFound,
CancellationToken cancellationToken)
{
if (_service == null)
if (_service is null)
return;

var results = await _service.SearchDocumentAsync(document, searchPattern, kinds, cancellationToken).ConfigureAwait(false);
Expand All @@ -52,19 +52,66 @@ public async Task SearchProjectsAsync(
Func<Task> onProjectCompleted,
CancellationToken cancellationToken)
{
if (_service == null)
return;

Contract.ThrowIfTrue(projects.IsEmpty);
Contract.ThrowIfTrue(projects.Select(p => p.Language).Distinct().Count() != 1);

foreach (var project in projects)
{
var results = await _service.SearchProjectAsync(project, priorityDocuments, searchPattern, kinds, cancellationToken).ConfigureAwait(false);
if (results.Length > 0)
await onResultsFound(results.SelectAsArray(result => (INavigateToSearchResult)new InternalFSharpNavigateToSearchResult(result))).ConfigureAwait(false);
if (_service is not null)
{
var results = await _service.SearchProjectAsync(project, priorityDocuments, searchPattern, kinds, cancellationToken).ConfigureAwait(false);
if (results.Length > 0)
await onResultsFound(results.SelectAsArray(result => (INavigateToSearchResult)new InternalFSharpNavigateToSearchResult(result))).ConfigureAwait(false);
}

await onProjectCompleted().ConfigureAwait(false);
}
}

public async Task SearchCachedDocumentsAsync(
Solution solution,
ImmutableArray<Project> projects,
ImmutableArray<Document> priorityDocuments,
string searchPattern,
IImmutableSet<string> kinds,
Document? activeDocument,
Func<ImmutableArray<INavigateToSearchResult>, Task> onResultsFound,
Func<Task> onProjectCompleted,
CancellationToken cancellationToken)
{
Contract.ThrowIfTrue(projects.IsEmpty);
Contract.ThrowIfTrue(projects.Select(p => p.Language).Distinct().Count() != 1);

// if the service doesn't support searching cached docs, immediately transition the projects to the
// completed state.
if (_service is not IFSharpAdvancedNavigateToSearchService advancedService)
{
foreach (var project in projects)
await onProjectCompleted().ConfigureAwait(false);
Comment thread
Copilot marked this conversation as resolved.
Resolved
}
else
{
await advancedService.SearchCachedDocumentsAsync(
solution, projects, priorityDocuments, searchPattern, kinds, activeDocument,
results => onResultsFound(results.SelectAsArray(result => (INavigateToSearchResult)new InternalFSharpNavigateToSearchResult(result))),
onProjectCompleted, cancellationToken).ConfigureAwait(false);
}
}

public async Task SearchGeneratedDocumentsAsync(
Solution solution,
ImmutableArray<Project> projects,
string searchPattern,
IImmutableSet<string> kinds,
Document? activeDocument,
Func<ImmutableArray<INavigateToSearchResult>, Task> onResultsFound,
Func<Task> onProjectCompleted,
CancellationToken cancellationToken)
{
// Nothing to search: F# has no Roslyn source generators, and type providers give types during checking
// rather than documents. The projects still have to be reported for the progress the searcher added for
// them to complete.
foreach (var project in projects)
await onProjectCompleted().ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.NavigateTo;

/// <summary>
/// Optional expanded API for Navigate-To. An <see cref="IFSharpNavigateToSearchService"/> that also implements this
/// takes part in the search that runs while the solution is still loading; one that does not is skipped until the
/// solution is fully loaded, and so contributes nothing to that search.
/// </summary>
internal interface IFSharpAdvancedNavigateToSearchService : IFSharpNavigateToSearchService
{
/// <summary>
/// Searches the documents inside <paramref name="projects"/> for symbols that matches <paramref
/// name="searchPattern"/>. Results should be reported from a previous computed cache (even if that cache is out of
/// date) to produce results as quickly as possible. This is called for every project of the solution while it
/// loads, so it must not wait on anything that only becomes available once the project has loaded.
Comment thread
Copilot marked this conversation as resolved.
Resolved
/// </summary>
/// <remarks>
/// All the projects passed are for F#. Similarly, all the <paramref name="priorityDocuments"/> belong to these
/// projects. <paramref name="onProjectCompleted"/> must be called exactly once per project, whether or not
/// anything was found in it.
/// </remarks>
Task SearchCachedDocumentsAsync(
Solution solution,
ImmutableArray<Project> projects,
ImmutableArray<Document> priorityDocuments,
string searchPattern,
IImmutableSet<string> kinds,
Document? activeDocument,
Func<ImmutableArray<FSharpNavigateToSearchResult>, Task> onResultsFound,
Func<Task> onProjectCompleted,
CancellationToken cancellationToken);
}