Skip to content

Commit

Permalink
Merge pull request #53180 from CyrusNajmabadi/simplifySAS
Browse files Browse the repository at this point in the history
Simplify suggested action computation.
  • Loading branch information
CyrusNajmabadi authored May 5, 2021
2 parents a528168 + a2e2922 commit dc24c3d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,7 @@ public bool TryGetTelemetryId(out Guid telemetryId)
document, selection, addOperationScope, cancellationToken);

var filteredSets = UnifiedSuggestedActionsSource.FilterAndOrderActionSets(fixes, refactorings, selection);
if (!filteredSets.HasValue)
{
return null;
}

return filteredSets.Value.SelectAsArray((s, arg) => ConvertToSuggestedActionSet(s, arg.Owner, arg.SubjectBuffer), (state.Target.Owner, state.Target.SubjectBuffer)).WhereNotNull();
return filteredSets.SelectAsArray(s => ConvertToSuggestedActionSet(s, state.Target.Owner, state.Target.SubjectBuffer)).WhereNotNull();
}
}

Expand Down Expand Up @@ -265,7 +260,7 @@ private ImmutableArray<UnifiedSuggestedActionSet> GetCodeFixes(

return UnifiedSuggestedActionsSource.GetFilterAndOrderCodeFixesAsync(
workspace, state.Target.Owner._codeFixService, document, range.Span.ToTextSpan(),
includeSuppressionFixes, isBlocking: true, addOperationScope, cancellationToken).WaitAndGetResult(cancellationToken);
includeSuppressionFixes, isBlocking: true, addOperationScope, cancellationToken).AsTask().WaitAndGetResult(cancellationToken);
}

private static string GetFixCategory(DiagnosticSeverity severity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class UnifiedSuggestedActionsSource
/// <summary>
/// Gets, filters, and orders code fixes.
/// </summary>
public static async Task<ImmutableArray<UnifiedSuggestedActionSet>> GetFilterAndOrderCodeFixesAsync(
public static async ValueTask<ImmutableArray<UnifiedSuggestedActionSet>> GetFilterAndOrderCodeFixesAsync(
Workspace workspace,
ICodeFixService codeFixService,
Document document,
Expand Down Expand Up @@ -520,7 +520,7 @@ private static UnifiedSuggestedActionSetPriority GetUnifiedSuggestedActionSetPri
/// Should be called with the results from <see cref="GetFilterAndOrderCodeFixesAsync"/>
/// and <see cref="GetFilterAndOrderCodeRefactoringsAsync"/>.
/// </summary>
public static ImmutableArray<UnifiedSuggestedActionSet>? FilterAndOrderActionSets(
public static ImmutableArray<UnifiedSuggestedActionSet> FilterAndOrderActionSets(
ImmutableArray<UnifiedSuggestedActionSet> fixes,
ImmutableArray<UnifiedSuggestedActionSet> refactorings,
TextSpan? selectionOpt)
Expand All @@ -529,9 +529,7 @@ private static UnifiedSuggestedActionSetPriority GetUnifiedSuggestedActionSetPri
// ordered against each other.
var result = GetInitiallyOrderedActionSets(selectionOpt, fixes, refactorings);
if (result.IsEmpty)
{
return null;
}
return ImmutableArray<UnifiedSuggestedActionSet>.Empty;

// Now that we have the entire set of action sets, inline, sort and filter
// them appropriately against each other.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ public static async Task<VSCodeAction[]> GetVSCodeActionsAsync(
{
var actionSets = await GetActionSetsAsync(
document, codeFixService, codeRefactoringService, request.Range, cancellationToken).ConfigureAwait(false);
if (!actionSets.HasValue)
{
if (actionSets.IsDefaultOrEmpty)
return Array.Empty<VSCodeAction>();
}

await codeActionsCache.UpdateActionSetsAsync(document, request.Range, actionSets.Value, cancellationToken).ConfigureAwait(false);
await codeActionsCache.UpdateActionSetsAsync(document, request.Range, actionSets, cancellationToken).ConfigureAwait(false);
var documentText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

// Each suggested action set should have a unique set number, which is used for grouping code actions together.
Expand Down Expand Up @@ -166,18 +164,10 @@ public static async Task<ImmutableArray<CodeAction>> GetCodeActionsAsync(
{
var actionSets = await GetActionSetsAsync(
document, codeFixService, codeRefactoringService, selection, cancellationToken).ConfigureAwait(false);
if (!actionSets.HasValue)
{
actionSets = await GetActionSetsAsync(
document, codeFixService, codeRefactoringService, selection, cancellationToken).ConfigureAwait(false);
if (actionSets.IsDefaultOrEmpty)
return ImmutableArray<CodeAction>.Empty;

if (!actionSets.HasValue)
{
return ImmutableArray<CodeAction>.Empty;
}

await codeActionsCache.UpdateActionSetsAsync(document, selection, actionSets.Value, cancellationToken).ConfigureAwait(false);
}
await codeActionsCache.UpdateActionSetsAsync(document, selection, actionSets, cancellationToken).ConfigureAwait(false);

var _ = ArrayBuilder<CodeAction>.GetInstance(out var codeActions);
foreach (var set in actionSets)
Expand Down Expand Up @@ -221,7 +211,7 @@ private static CodeAction GetNestedActionsFromActionSet(IUnifiedSuggestedAction
codeAction.Title, nestedActions.ToImmutable(), codeAction.IsInlinable, codeAction.Priority);
}

private static async Task<ImmutableArray<UnifiedSuggestedActionSet>?> GetActionSetsAsync(
private static async ValueTask<ImmutableArray<UnifiedSuggestedActionSet>> GetActionSetsAsync(
Document document,
ICodeFixService codeFixService,
ICodeRefactoringService codeRefactoringService,
Expand Down

0 comments on commit dc24c3d

Please sign in to comment.