Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Feb 10, 2022
1 parent 56bd080 commit 54e4b34
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindUsages
{
Expand All @@ -19,20 +20,25 @@ namespace Microsoft.CodeAnalysis.FindUsages
internal sealed class SimpleFindUsagesContext : FindUsagesContext
{
private readonly object _gate = new();
private readonly IGlobalOptionService _globalOptions;

private readonly ImmutableArray<DefinitionItem>.Builder _definitionItems =
ImmutableArray.CreateBuilder<DefinitionItem>();

private readonly ImmutableArray<SourceReferenceItem>.Builder _referenceItems =
ImmutableArray.CreateBuilder<SourceReferenceItem>();

public SimpleFindUsagesContext(IGlobalOptionService globalOptions)
: base(globalOptions)
{
_globalOptions = globalOptions;
}

public string Message { get; private set; }
public string SearchTitle { get; private set; }

public override ValueTask<FindUsagesOptions> GetOptionsAsync(string language, CancellationToken cancellationToken)
=> ValueTaskFactory.FromResult(_globalOptions.GetFindUsagesOptions(language));

public override ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken)
{
Message = message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.FindUsages;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.CustomProtocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.FindUsages;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal sealed class FindUsagesLSPContext : FindUsagesContext
private readonly Document _document;
private readonly int _position;
private readonly IMetadataAsSourceFileService _metadataAsSourceFileService;
private readonly IGlobalOptionService _globalOptions;

/// <summary>
/// Methods in FindUsagesLSPContext can be called by multiple threads concurrently.
Expand Down Expand Up @@ -78,16 +79,19 @@ public FindUsagesLSPContext(
IAsynchronousOperationListener asyncListener,
IGlobalOptionService globalOptions,
CancellationToken cancellationToken)
: base(globalOptions)
{
_progress = progress;
_document = document;
_position = position;
_metadataAsSourceFileService = metadataAsSourceFileService;
_globalOptions = globalOptions;
_workQueue = new AsyncBatchingWorkQueue<VSInternalReferenceItem>(
TimeSpan.FromMilliseconds(500), ReportReferencesAsync, asyncListener, cancellationToken);
}

public override ValueTask<FindUsagesOptions> GetOptionsAsync(string language, CancellationToken cancellationToken)
=> ValueTaskFactory.FromResult(_globalOptions.GetFindUsagesOptions(language));

// After all definitions/references have been found, wait here until all results have been reported.
public override async ValueTask OnCompletedAsync(CancellationToken cancellationToken)
=> await _workQueue.WaitUntilCurrentBatchCompletesAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ private class MockFindUsagesContext : FindUsagesContext
{
public readonly List<DefinitionItem> Result = new();

public MockFindUsagesContext(IGlobalOptionService globalOptions)
: base(globalOptions)
public MockFindUsagesContext()
{
}

public override ValueTask<FindUsagesOptions> GetOptionsAsync(string language, CancellationToken cancellationToken)
=> ValueTaskFactory.FromResult(FindUsagesOptions.Default);

public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken)
{
lock (Result)
Expand Down Expand Up @@ -70,7 +72,7 @@ public void ClearAll()
public async Task TestFindReferencesAsynchronousCall()
{
using var workspace = TestWorkspace.CreateCSharp("class C { C() { new C(); } }");
var context = new MockFindUsagesContext(workspace.GlobalOptions);
var context = new MockFindUsagesContext();
var presenter = new MockStreamingFindUsagesPresenter(context);

var listenerProvider = workspace.ExportProvider.GetExportedValue<IAsynchronousOperationListenerProvider>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class C

Dim listenerProvider = workspace.ExportProvider.GetExportedValue(Of IAsynchronousOperationListenerProvider)

Dim context = New FindReferencesTests.TestContext(workspace.GlobalOptions)
Dim context = New FindReferencesTests.TestContext()
Dim commandHandler = New FindReferencesCommandHandler(
New MockStreamingFindReferencesPresenter(context),
workspace.GlobalOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences
Assert.NotNull(startDocument)

Dim findRefsService = startDocument.GetLanguageService(Of IFindUsagesService)
Dim context = New TestContext(workspace.GlobalOptions)
Dim context = New TestContext()
Await findRefsService.FindReferencesAsync(context, startDocument, cursorPosition, CancellationToken.None)

Dim expectedDefinitions =
Expand Down Expand Up @@ -224,10 +224,13 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences
Public ReadOnly Definitions As List(Of DefinitionItem) = New List(Of DefinitionItem)()
Public ReadOnly References As List(Of SourceReferenceItem) = New List(Of SourceReferenceItem)()

Public Sub New(globalOptions As IGlobalOptionService)
MyBase.New(globalOptions)
Public Sub New()
End Sub

Public Overrides Function GetOptionsAsync(language As String, cancellationToken As CancellationToken) As ValueTask(Of FindUsagesOptions)
Return ValueTaskFactory.FromResult(FindUsagesOptions.Default)
End Function

Public Function ShouldShow(definition As DefinitionItem) As Boolean
If References.Any(Function(r) r.Definition Is definition) Then
Return True
Expand Down
8 changes: 2 additions & 6 deletions src/Features/Core/Portable/FindUsages/FindUsagesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ namespace Microsoft.CodeAnalysis.FindUsages
{
internal abstract class FindUsagesContext : IFindUsagesContext
{
private readonly IGlobalOptionService _globalOptions;

public IStreamingProgressTracker ProgressTracker { get; }

protected FindUsagesContext(IGlobalOptionService globalOptions)
protected FindUsagesContext()
{
ProgressTracker = new StreamingProgressTracker(ReportProgressAsync);
_globalOptions = globalOptions;
}

public ValueTask<FindUsagesOptions> GetOptionsAsync(string language, CancellationToken cancellationToken)
=> ValueTaskFactory.FromResult(_globalOptions.GetFindUsagesOptions(language));
public abstract ValueTask<FindUsagesOptions> GetOptionsAsync(string language, CancellationToken cancellationToken);

public virtual ValueTask ReportMessageAsync(string message, CancellationToken cancellationToken) => default;

Expand Down
10 changes: 9 additions & 1 deletion src/Features/Core/Portable/FindUsages/FindUsagesOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ namespace Microsoft.CodeAnalysis.FindUsages
{
[DataContract]
internal readonly record struct FindUsagesOptions(
[property: DataMember(Order = 0)] ClassificationOptions ClassificationOptions);
[property: DataMember(Order = 0)] ClassificationOptions ClassificationOptions)
{
public FindUsagesOptions()
: this(ClassificationOptions.Default)
{
}

public static readonly FindUsagesOptions Default = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private abstract class AbstractTableDataSourceFindUsagesContext :

public readonly StreamingFindUsagesPresenter Presenter;
private readonly IFindAllReferencesWindow _findReferencesWindow;
private readonly IGlobalOptionService _globalOptions;
protected readonly IWpfTableControl2 TableControl;

private readonly AsyncBatchingWorkQueue<(int current, int maximum)> _progressQueue;
Expand Down Expand Up @@ -117,12 +118,12 @@ protected AbstractTableDataSourceFindUsagesContext(
IGlobalOptionService globalOptions,
bool includeContainingTypeAndMemberColumns,
bool includeKindColumn)
: base(globalOptions)
{
presenter.AssertIsForeground();

Presenter = presenter;
_findReferencesWindow = findReferencesWindow;
_globalOptions = globalOptions;
TableControl = (IWpfTableControl2)findReferencesWindow.TableControl;
TableControl.GroupingsChanged += OnTableControlGroupingsChanged;

Expand Down Expand Up @@ -157,6 +158,9 @@ protected AbstractTableDataSourceFindUsagesContext(
CancellationTokenSource.Token);
}

public override ValueTask<FindUsagesOptions> GetOptionsAsync(string language, CancellationToken cancellationToken)
=> ValueTaskFactory.FromResult(_globalOptions.GetFindUsagesOptions(language));

private static ImmutableArray<string> SelectCustomColumnsToInclude(ImmutableArray<ITableColumnDefinition> customColumns, bool includeContainingTypeAndMemberColumns, bool includeKindColumn)
{
var customColumnsToInclude = ArrayBuilder<string>.GetInstance();
Expand Down

0 comments on commit 54e4b34

Please sign in to comment.