Skip to content

Commit

Permalink
Merge pull request dotnet#54462 from dotnet/merges/main-to-main-vs-deps
Browse files Browse the repository at this point in the history
Merge main to main-vs-deps
  • Loading branch information
msftbot[bot] authored Jun 29, 2021
2 parents 568f852 + b0b31e3 commit 5336a84
Show file tree
Hide file tree
Showing 37 changed files with 378 additions and 386 deletions.
14 changes: 13 additions & 1 deletion src/Compilers/Core/Portable/InternalUtilities/VoidResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
// 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;

namespace Roslyn.Utilities
{
/// <summary>
/// Explicitly indicates result is void
/// </summary>
internal readonly struct VoidResult { }
internal readonly struct VoidResult : IEquatable<VoidResult>
{
public override bool Equals(object? obj)
=> obj is VoidResult;

public override int GetHashCode()
=> 0;

public bool Equals(VoidResult other)
=> true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6853,6 +6853,46 @@ public async Task TestInheritdocInlineSummary()
/// <remarks>Remarks documentation</remarks>
void M(int x) { }
/// <summary><inheritdoc cref=""M(int)""/></summary>
void $$M(int x, int y) { }";

await TestInClassAsync(markup,
MainDescription("void C.M(int x, int y)"),
Documentation("Summary documentation"));
}

[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public async Task TestInheritdocTwoLevels1()
{
var markup =
@"
/// <summary>Summary documentation</summary>
/// <remarks>Remarks documentation</remarks>
void M() { }
/// <inheritdoc cref=""M()""/>
void M(int x) { }
/// <inheritdoc cref=""M(int)""/>
void $$M(int x, int y) { }";

await TestInClassAsync(markup,
MainDescription("void C.M(int x, int y)"),
Documentation("Summary documentation"));
}

[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public async Task TestInheritdocTwoLevels2()
{
var markup =
@"
/// <summary>Summary documentation</summary>
/// <remarks>Remarks documentation</remarks>
void M() { }
/// <summary><inheritdoc cref=""M()""/></summary>
void M(int x) { }
/// <summary><inheritdoc cref=""M(int)""/></summary>
void $$M(int x, int y) { }";

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#nullable disable

using System;
using Microsoft.VisualStudio.Text;

namespace Microsoft.CodeAnalysis.Editor
{
internal interface INavigationBarControllerFactoryService
{
INavigationBarController CreateController(INavigationBarPresenter presenter, ITextBuffer textBuffer);
IDisposable CreateController(INavigationBarPresenter presenter, ITextBuffer textBuffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private void OnWorkspaceChanged(object? sender, WorkspaceChangeEventArgs args)
/// the editor. Calls to <see cref="ProcessChangesAsync"/> are serialized by <see cref="AsyncBatchingWorkQueue{TItem}"/>
/// so we don't need to worry about multiple calls to this happening concurrently.
/// </summary>
private async Task ProcessChangesAsync(ImmutableArray<ITextSnapshot> snapshots, CancellationToken cancellationToken)
private async ValueTask ProcessChangesAsync(ImmutableArray<ITextSnapshot> snapshots, CancellationToken cancellationToken)
{
// We have potentially heard about several changes to the subject buffer. However
// we only need to process the latest once.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -30,7 +31,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigationBar
/// The threading model for this class is simple: all non-static members are affinitized to the
/// UI thread.
/// </remarks>
internal partial class NavigationBarController : ForegroundThreadAffinitizedObject, INavigationBarController
internal partial class NavigationBarController : ForegroundThreadAffinitizedObject, IDisposable
{
private readonly INavigationBarPresenter _presenter;
private readonly ITextBuffer _subjectBuffer;
Expand All @@ -40,9 +41,9 @@ internal partial class NavigationBarController : ForegroundThreadAffinitizedObje
private bool _disconnected = false;

/// <summary>
/// Latest model and selected items produced once <see cref="DetermineSelectedItemInfoAsync"/> completes and
/// presents the single item to the view. These can then be read in when the dropdown is expanded and we want
/// to show all items.
/// Latest model and selected items produced once <see cref="SelectItemAsync"/> completes and presents the
/// single item to the view. These can then be read in when the dropdown is expanded and we want to show all
/// items.
/// </summary>
private (NavigationBarModel model, NavigationBarSelectedTypeAndMember selectedInfo) _latestModelAndSelectedInfo_OnlyAccessOnUIThread;

Expand All @@ -57,6 +58,21 @@ internal partial class NavigationBarController : ForegroundThreadAffinitizedObje
/// </summary>
private readonly ITaggerEventSource _eventSource;

private readonly CancellationTokenSource _cancellationTokenSource = new();

/// <summary>
/// Queue to batch up work to do to compute the current model. Used so we can batch up a lot of events and only
/// compute the model once for every batch. The <c>bool</c> type parameter isn't used, but is provided as this
/// type is generic.
/// </summary>
private readonly AsyncBatchingWorkQueue<bool, NavigationBarModel> _computeModelQueue;

/// <summary>
/// Queue to batch up work to do to determine the selected item. Used so we can batch up a lot of events and
/// only compute the selected item once for every batch.
/// </summary>
private readonly AsyncBatchingWorkQueue _selectItemQueue;

public NavigationBarController(
IThreadingContext threadingContext,
INavigationBarPresenter presenter,
Expand All @@ -70,6 +86,19 @@ public NavigationBarController(
_uiThreadOperationExecutor = uiThreadOperationExecutor;
_asyncListener = asyncListener;

_computeModelQueue = new AsyncBatchingWorkQueue<bool, NavigationBarModel>(
TimeSpan.FromMilliseconds(TaggerConstants.ShortDelay),
ComputeModelAndSelectItemAsync,
EqualityComparer<bool>.Default,
asyncListener,
_cancellationTokenSource.Token);

_selectItemQueue = new AsyncBatchingWorkQueue(
TimeSpan.FromMilliseconds(TaggerConstants.NearImmediateDelay),
SelectItemAsync,
asyncListener,
_cancellationTokenSource.Token);

presenter.CaretMoved += OnCaretMoved;
presenter.ViewFocused += OnViewFocused;

Expand All @@ -80,8 +109,6 @@ public NavigationBarController(
_latestModelAndSelectedInfo_OnlyAccessOnUIThread.model = new(ImmutableArray<NavigationBarItem>.Empty, itemService: null!);
_latestModelAndSelectedInfo_OnlyAccessOnUIThread.selectedInfo = new(typeItem: null, memberItem: null);

_modelTask = Task.FromResult(_latestModelAndSelectedInfo_OnlyAccessOnUIThread.model);

// Use 'compilation available' as that may produce different results from the initial 'frozen partial'
// snapshot we use.
_eventSource = new CompilationAvailableTaggerEventSource(
Expand All @@ -97,41 +124,17 @@ public NavigationBarController(
TaggerEventSources.OnWorkspaceRegistrationChanged(subjectBuffer));
_eventSource.Changed += OnEventSourceChanged;
_eventSource.Connect();
}

public void SetWorkspace(Workspace? newWorkspace)
{
if (newWorkspace != null)
StartModelUpdateAndSelectedItemUpdateTasks();
}

private void StartModelUpdateAndSelectedItemUpdateTasks()
{
// If we're disconnected, just disregard.
if (_disconnected)
return;

if (IsForeground())
{
StartModelUpdateAndSelectedItemUpdateTasksOnUIThread();
}
else
{
var asyncToken = _asyncListener.BeginAsyncOperation(nameof(StartModelUpdateAndSelectedItemUpdateTasks));
Task.Run(async () =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();
StartModelUpdateAndSelectedItemUpdateTasksOnUIThread();
}).CompletesAsyncOperation(asyncToken);
}
// Kick off initial work to populate the navbars
StartModelUpdateAndSelectedItemUpdateTasks();
}

private void OnEventSourceChanged(object? sender, TaggerEventArgs e)
{
StartModelUpdateAndSelectedItemUpdateTasks();
}

public void Disconnect()
void IDisposable.Dispose()
{
AssertIsForeground();

Expand All @@ -149,8 +152,17 @@ public void Disconnect()
_disconnected = true;

// Cancel off any remaining background work
_modelTaskCancellationSource.Cancel();
_selectedItemInfoTaskCancellationSource.Cancel();
_cancellationTokenSource.Cancel();
}

private void StartModelUpdateAndSelectedItemUpdateTasks()
{
// If we disconnected already, just disregard
if (_disconnected)
return;

// 'true' value is unused. this just signals to the queue that we have work to do.
_computeModelQueue.AddWork(true);
}

private void OnCaretMoved(object? sender, EventArgs e)
Expand Down Expand Up @@ -328,9 +340,7 @@ private async Task ProcessItemSelectionAsync(NavigationBarItem item, Cancellatio
}

// Now that the edit has been done, refresh to make sure everything is up-to-date.
// Have to make sure we come back to the main thread for this.
AssertIsForeground();
StartModelUpdateAndSelectedItemUpdateTasksOnUIThread();
StartModelUpdateAndSelectedItemUpdateTasks();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public NavigationBarControllerFactoryService(
_asyncListener = listenerProvider.GetListener(FeatureAttribute.NavigationBar);
}

public INavigationBarController CreateController(INavigationBarPresenter presenter, ITextBuffer textBuffer)
public IDisposable CreateController(INavigationBarPresenter presenter, ITextBuffer textBuffer)
{
return new NavigationBarController(
_threadingContext,
Expand Down
Loading

0 comments on commit 5336a84

Please sign in to comment.