Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release/dev17.3' into asyncNav…
Browse files Browse the repository at this point in the history
…igation5
  • Loading branch information
CyrusNajmabadi committed Mar 6, 2022
2 parents 13cd975 + fd728d5 commit f67d2e5
Show file tree
Hide file tree
Showing 74 changed files with 513 additions and 522 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Task<bool> CanNavigateToLineAndOffsetAsync(Workspace workspace, DocumentI
public Task<bool> CanNavigateToPositionAsync(Workspace workspace, DocumentId documentId, int position, int virtualSpace, CancellationToken cancellationToken)
=> SpecializedTasks.False;

public async Task<INavigableLocation?> GetLocationForSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, NavigationOptions options, bool allowInvalidSpan, CancellationToken cancellationToken)
public async Task<INavigableLocation?> GetLocationForSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
{
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
if (workspace is not InteractiveWindowWorkspace interactiveWorkspace)
Expand Down Expand Up @@ -68,7 +68,7 @@ public Task<bool> CanNavigateToPositionAsync(Workspace workspace, DocumentId doc
return null;
}

return new NavigableLocation(async cancellationToken =>
return new NavigableLocation(async (options, cancellationToken) =>
{
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
Expand All @@ -87,10 +87,10 @@ public Task<bool> CanNavigateToPositionAsync(Workspace workspace, DocumentId doc
});
}

public Task<INavigableLocation?> GetLocationForLineAndOffsetAsync(Workspace workspace, DocumentId documentId, int lineNumber, int offset, NavigationOptions options, CancellationToken cancellationToken)
public Task<INavigableLocation?> GetLocationForLineAndOffsetAsync(Workspace workspace, DocumentId documentId, int lineNumber, int offset, CancellationToken cancellationToken)
=> SpecializedTasks.Null<INavigableLocation>();

public Task<INavigableLocation?> GetLocationForPositionAsync(Workspace workspace, DocumentId documentId, int position, int virtualSpace, NavigationOptions options, CancellationToken cancellationToken)
public Task<INavigableLocation?> GetLocationForPositionAsync(Workspace workspace, DocumentId documentId, int position, int virtualSpace, CancellationToken cancellationToken)
=> SpecializedTasks.Null<INavigableLocation>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
Expand Down Expand Up @@ -79,7 +80,7 @@ private async Task NavigateAsync()
_definitions,
cancellationToken).ConfigureAwait(false);
if (location != null)
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false);
await location.NavigateToAsync(new NavigationOptions(PreferProvisionalTab: true, ActivateTab: true), cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ public void NavigateTo()
workspace,
document.Id,
_searchResult.NavigableItem.SourceSpan,
NavigationOptions.Default,
allowInvalidSpan: _searchResult.NavigableItem.IsStale,
CancellationToken.None).ConfigureAwait(false);
if (location != null)
await location.NavigateToAsync(CancellationToken.None).ConfigureAwait(false);
await location.NavigateToAsync(NavigationOptions.Default, CancellationToken.None).ConfigureAwait(false);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,7 @@ private async Task GetSuggestedActionsWorkerAsync(
// Collectors are in priority order. So just walk them from highest to lowest.
foreach (var collector in collectors)
{
var priority = collector.Priority switch
{
VisualStudio.Utilities.DefaultOrderings.Highest => CodeActionRequestPriority.High,
VisualStudio.Utilities.DefaultOrderings.Default => CodeActionRequestPriority.Normal,
VisualStudio.Utilities.DefaultOrderings.Lowest => CodeActionRequestPriority.Lowest,
_ => (CodeActionRequestPriority?)null,
};
var priority = TryGetPriority(collector.Priority);

if (priority != null)
{
Expand Down
45 changes: 30 additions & 15 deletions src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,27 +417,42 @@ await InvokeBelowInputPriorityAsync(() =>
CodeActionOptions options,
CancellationToken cancellationToken)
{
if (state.Target.Owner._codeFixService != null &&
state.Target.SubjectBuffer.SupportsCodeFixes())
foreach (var order in Orderings)
{
var result = await state.Target.Owner._codeFixService.GetMostSevereFixableDiagnosticAsync(
document, range.Span.ToTextSpan(), options, cancellationToken).ConfigureAwait(false);
var priority = TryGetPriority(order);
Contract.ThrowIfNull(priority);

if (result.HasFix)
{
Logger.Log(FunctionId.SuggestedActions_HasSuggestedActionsAsync);
return GetFixCategory(result.Diagnostic.Severity);
}
var result = await GetFixLevelAsync(priority.Value).ConfigureAwait(false);
if (result != null)
return result;
}

if (result.PartialResult)
return null;

async Task<string?> GetFixLevelAsync(CodeActionRequestPriority priority)
{
if (state.Target.Owner._codeFixService != null &&
state.Target.SubjectBuffer.SupportsCodeFixes())
{
// reset solution version number so that we can raise suggested action changed event
Volatile.Write(ref state.Target.LastSolutionVersionReported, InvalidSolutionVersion);
return null;
var result = await state.Target.Owner._codeFixService.GetMostSevereFixAsync(
document, range.Span.ToTextSpan(), priority, options, cancellationToken).ConfigureAwait(false);

if (result.HasFix)
{
Logger.Log(FunctionId.SuggestedActions_HasSuggestedActionsAsync);
return GetFixCategory(result.CodeFixCollection.FirstDiagnostic.Severity);
}

if (!result.UpToDate)
{
// reset solution version number so that we can raise suggested action changed event
Volatile.Write(ref state.Target.LastSolutionVersionReported, InvalidSolutionVersion);
return null;
}
}
}

return null;
return null;
}
}

private async Task<string?> TryGetRefactoringSuggestedActionCategoryAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tags;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
Expand All @@ -37,6 +37,11 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
[SuggestedActionPriority(DefaultOrderings.Lowest)]
internal partial class SuggestedActionsSourceProvider : ISuggestedActionsSourceProvider
{
public static readonly ImmutableArray<string> Orderings = ImmutableArray.Create(
DefaultOrderings.Highest,
DefaultOrderings.Default,
DefaultOrderings.Lowest);

private static readonly Guid s_CSharpSourceGuid = new Guid("b967fea8-e2c3-4984-87d4-71a38f49e16a");
private static readonly Guid s_visualBasicSourceGuid = new Guid("4de30e93-3e0c-40c2-a4ba-1124da4539f6");
private static readonly Guid s_xamlSourceGuid = new Guid("a0572245-2eab-4c39-9f61-06a6d8c5ddda");
Expand Down Expand Up @@ -100,5 +105,14 @@ public SuggestedActionsSourceProvider(
? new AsyncSuggestedActionsSource(_threadingContext, _globalOptions, this, textView, textBuffer, _suggestedActionCategoryRegistry)
: new SyncSuggestedActionsSource(_threadingContext, _globalOptions, this, textView, textBuffer, _suggestedActionCategoryRegistry);
}

private static CodeActionRequestPriority? TryGetPriority(string priority)
=> priority switch
{
DefaultOrderings.Highest => CodeActionRequestPriority.High,
DefaultOrderings.Default => CodeActionRequestPriority.Normal,
DefaultOrderings.Lowest => CodeActionRequestPriority.Lowest,
_ => (CodeActionRequestPriority?)null,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
Expand Down Expand Up @@ -194,7 +195,7 @@ private async Task ExecuteCommandWorkerAsync(
definitions,
cancellationToken).ConfigureAwait(false);
if (location != null)
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false);
await location.NavigateToAsync(new NavigationOptions(PreferProvisionalTab: true, ActivateTab: true), cancellationToken).ConfigureAwait(false);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ protected async Task NavigateToPositionAsync(Workspace workspace, DocumentId doc
{
var navigationService = workspace.Services.GetRequiredService<IDocumentNavigationService>();
var location = await navigationService.GetLocationForPositionAsync(
workspace, documentId, position, virtualSpace, NavigationOptions.Default, cancellationToken).ConfigureAwait(false);
workspace, documentId, position, virtualSpace, cancellationToken).ConfigureAwait(false);

if (location != null)
{
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false);
await location.NavigateToAsync(NavigationOptions.Default, cancellationToken).ConfigureAwait(false);
return;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public async Task<bool> TryNavigateToItemAsync(
var workspace = document.Project.Solution.Workspace;
var navigationService = workspace.Services.GetRequiredService<IDocumentNavigationService>();
var location = await navigationService.GetLocationForPositionAsync(
workspace, document.Id, navigationSpan.Start, virtualSpace: 0, NavigationOptions.Default, cancellationToken).ConfigureAwait(false);
workspace, document.Id, navigationSpan.Start, virtualSpace: 0, cancellationToken).ConfigureAwait(false);
return location != null &&
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false);
await location.NavigateToAsync(NavigationOptions.Default, cancellationToken).ConfigureAwait(false);
}

public bool ShowItemGrayedIfNear(NavigationBarItem item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ protected AbstractAsyncGoToDefinitionService(
var service = workspace.Services.GetRequiredService<IDocumentNavigationService>();

return service.GetLocationForPositionAsync(
workspace, document.Id, position, virtualSpace: 0,
new NavigationOptions(PreferProvisionalTab: true, ActivateTab: true), cancellationToken);
workspace, document.Id, position, virtualSpace: 0, cancellationToken);
}

public async Task<INavigableLocation?> FindDefinitionLocationAsync(Document document, int position, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
Expand Down Expand Up @@ -87,7 +88,8 @@ private async Task ExecuteCommandAsync(
{
var location = await asyncService.FindDefinitionLocationAsync(document, caretPosition, cancellationToken).ConfigureAwait(false);
var success = location != null &&
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false);
await location.NavigateToAsync(
new NavigationOptions(PreferProvisionalTab: true, ActivateTab: true), cancellationToken).ConfigureAwait(false);

if (success)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ internal static class IStreamingFindUsagesPresenterExtensions
definitionsBuilder.Add(item);
}

var options = new NavigationOptions(PreferProvisionalTab: true, ActivateTab: true);
var definitions = definitionsBuilder.ToImmutable();

// See if there's a third party external item we can navigate to. If so, defer
Expand All @@ -87,8 +86,7 @@ internal static class IStreamingFindUsagesPresenterExtensions
// If we're directly going to a location we need to activate the preview so
// that focus follows to the new cursor position. This behavior is expected
// because we are only going to navigate once successfully
var location = await item.GetNavigableLocationAsync(
workspace, options, cancellationToken).ConfigureAwait(false);
var location = await item.GetNavigableLocationAsync(workspace, cancellationToken).ConfigureAwait(false);
if (location != null)
return location;
}
Expand All @@ -103,14 +101,13 @@ internal static class IStreamingFindUsagesPresenterExtensions
// There was only one location to navigate to. Just directly go to that location. If we're directly
// going to a location we need to activate the preview so that focus follows to the new cursor position.

return await nonExternalItems[0].GetNavigableLocationAsync(
workspace, options, cancellationToken).ConfigureAwait(false);
return await nonExternalItems[0].GetNavigableLocationAsync(workspace, cancellationToken).ConfigureAwait(false);
}

if (presenter == null)
return null;

return new NavigableLocation(async cancellationToken =>
return new NavigableLocation(async (options, cancellationToken) =>
{
// Can only navigate or present items on UI thread.
await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private async Task TryNavigateToLocationOrStartRenameSessionAsync(
var location = await navigationService.GetLocationForPositionAsync(
workspace, navigationOperation.DocumentId, navigationOperation.Position, cancellationToken).ConfigureAwait(false);
if (location != null)
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false);
await location.NavigateToAsync(NavigationOptions.Default, cancellationToken).ConfigureAwait(false);
return;
}

Expand All @@ -322,7 +322,7 @@ private async Task TryNavigateToLocationOrStartRenameSessionAsync(
var location = await navigationService.GetLocationForPositionAsync(
workspace, documentId, navigationToken.Value.SpanStart, cancellationToken).ConfigureAwait(false);
if (location != null)
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false);
await location.NavigateToAsync(NavigationOptions.Default, cancellationToken).ConfigureAwait(false);
return;
}

Expand All @@ -349,7 +349,7 @@ private async Task TryNavigateToLocationOrStartRenameSessionAsync(
editorWorkspace, documentId, resolvedRenameToken.Span, cancellationToken).ConfigureAwait(false);

if (location != null &&
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false))
await location.NavigateToAsync(NavigationOptions.Default, cancellationToken).ConfigureAwait(false))
{
var openDocument = workspace.CurrentSolution.GetRequiredDocument(documentId);
var openRoot = await openDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public bool ExecuteCommand(ExtractInterfaceCommandArgs args, CommandExecutionCon
var location = await navigationService.GetLocationForPositionAsync(
workspace, result.NavigationDocumentId, 0, CancellationToken.None).ConfigureAwait(false);
if (location != null)
await location.NavigateToAsync(CancellationToken.None).ConfigureAwait(false);
await location.NavigateToAsync(NavigationOptions.Default, CancellationToken.None).ConfigureAwait(false);
});

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text.Adornments;
Expand Down Expand Up @@ -221,7 +222,7 @@ private static async Task NavigateToQuickInfoTargetAsync(
var location = await GoToDefinitionHelpers.GetDefinitionLocationAsync(
symbol, solution, threadingContext, streamingPresenter, cancellationToken).ConfigureAwait(false);
if (location != null)
await location.NavigateToAsync(cancellationToken).ConfigureAwait(false);
await location.NavigateToAsync(new NavigationOptions(PreferProvisionalTab: true, ActivateTab: true), cancellationToken).ConfigureAwait(false);
}
}
catch (OperationCanceledException)
Expand Down
Loading

0 comments on commit f67d2e5

Please sign in to comment.