Skip to content

Commit 3f3d1eb

Browse files
Ensure low-pri fixes go in the right async lightbulb bucket.
1 parent 1ab5763 commit 3f3d1eb

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/EditorFeatures/Core.Wpf/Suggestions/AsyncSuggestedActionsSource.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ private async Task GetSuggestedActionsWorkerAsync(
9797
// items should be pushed higher up, and less important items shouldn't take up that much space.
9898
var currentActionCount = 0;
9999

100+
using var _ = ArrayBuilder<SuggestedActionSet>.GetInstance(out var lowPrioritySets);
101+
100102
// Collectors are in priority order. So just walk them from highest to lowest.
101103
foreach (var collector in collectors)
102104
{
@@ -122,8 +124,27 @@ private async Task GetSuggestedActionsWorkerAsync(
122124

123125
await foreach (var set in allSets)
124126
{
125-
currentActionCount += set.Actions.Count();
126-
collector.Add(set);
127+
if (priority == CodeActionRequestPriority.High && set.Priority == SuggestedActionSetPriority.Low)
128+
{
129+
// if we're processing the high pri bucket, but we get action sets for lower pri
130+
// groups, then keep track of them and add them in later when we get to that group.
131+
lowPrioritySets.Add(set);
132+
}
133+
else
134+
{
135+
currentActionCount += set.Actions.Count();
136+
collector.Add(set);
137+
}
138+
}
139+
140+
if (priority == CodeActionRequestPriority.Normal)
141+
{
142+
// now, add any low pri items we've been waiting on to the final group.
143+
foreach (var set in lowPrioritySets)
144+
{
145+
currentActionCount += set.Actions.Count();
146+
collector.Add(set);
147+
}
127148
}
128149
}
129150

src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpCodeActions.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#nullable disable
66

7-
using System;
8-
using System.Collections.Generic;
97
using System.Collections.Immutable;
108
using System.Linq;
119
using System.Threading;
@@ -19,7 +17,6 @@
1917
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
2018
using Roslyn.Test.Utilities;
2119
using Xunit;
22-
using Xunit.Abstractions;
2320
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
2421

2522
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
@@ -574,6 +571,38 @@ static void Main(string[] args)
574571
VisualStudio.Editor.Verify.TextContains("implicit");
575572
}
576573

574+
[WorkItem(57157, "https://github.com/dotnet/roslyn/issues/57157")]
575+
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsAddImport)]
576+
public void AddFuzzyUsingAfterGenerateVariable()
577+
{
578+
SetUpEditor(@"
579+
namespace X
580+
{
581+
class Formatter
582+
{
583+
}
584+
}
585+
class Program
586+
{
587+
void Main()
588+
{
589+
$$formatter = new GooFormatter();
590+
}
591+
}
592+
class GooFormatter
593+
{
594+
}");
595+
596+
VisualStudio.Editor.InvokeCodeActionList();
597+
var expectedItems = new[]
598+
{
599+
"Generate variable 'formatter'",
600+
"Formatter - using X;",
601+
};
602+
603+
VisualStudio.Editor.Verify.CodeActions(expectedItems, ensureExpectedItemsAreOrdered: true);
604+
}
605+
577606
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsAddImport)]
578607
public void OrderFixesByCursorProximityLeft()
579608
{

0 commit comments

Comments
 (0)