Skip to content

Commit 0029139

Browse files
committed
Order Razor code actions by the Order property
1 parent 9162078 commit 0029139

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionsService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private static async Task<ImmutableArray<RazorVSInternalCodeAction>> Consolidate
246246
{
247247
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
248248

249-
using var codeActions = new PooledArrayBuilder<RazorVSInternalCodeAction>();
249+
using var codeActions = new PooledArrayBuilder<RazorVSInternalCodeAction>(capacity: tasks.Length);
250250

251251
cancellationToken.ThrowIfCancellationRequested();
252252

@@ -255,7 +255,7 @@ private static async Task<ImmutableArray<RazorVSInternalCodeAction>> Consolidate
255255
codeActions.AddRange(result);
256256
}
257257

258-
return codeActions.ToImmutable();
258+
return codeActions.DrainToImmutableOrderedBy(static r => r.Order);
259259
}
260260

261261
private static ImmutableHashSet<string> GetAllAvailableCodeActionNames()

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorVSInternalCodeAction.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ internal sealed class RazorVSInternalCodeAction : VSInternalCodeAction
1313
[JsonPropertyName("name")]
1414
[DataMember(Name = "name")]
1515
public string? Name { get; set; }
16+
17+
/// <summary>
18+
/// The order code actions should appear. This is not serialized as its just used in the code actions service
19+
/// </summary>
20+
[JsonIgnore]
21+
public int Order { get; set; }
1622
}

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public static RazorVSInternalCodeAction CreateAddComponentUsing(string @namespac
5050
TelemetryId = s_addComponentUsingTelemetryId,
5151
Priority = VSInternalPriorityLevel.High,
5252
Name = LanguageServerConstants.CodeActions.AddUsing,
53+
// Adding a using for an existing component should be first
54+
Order = -1000,
5355
};
5456
return codeAction;
5557
}
@@ -63,6 +65,8 @@ public static RazorVSInternalCodeAction CreateFullyQualifyComponent(string fully
6365
TelemetryId = s_fullyQualifyComponentTelemetryId,
6466
Priority = VSInternalPriorityLevel.High,
6567
Name = LanguageServerConstants.CodeActions.FullyQualify,
68+
// Fully qualifying an existing component should be very high, but not quite as high as Add Using
69+
Order = -900,
6670
};
6771
return codeAction;
6872
}
@@ -102,6 +106,8 @@ public static RazorVSInternalCodeAction CreateExtractToComponent(RazorCodeAction
102106
Data = data,
103107
TelemetryId = s_createExtractToComponentTelemetryId,
104108
Name = LanguageServerConstants.CodeActions.ExtractToNewComponentAction,
109+
// Since Extract to Component is offered basically everywhere, always offer it last
110+
Order = 9999
105111
};
106112
return codeAction;
107113
}

0 commit comments

Comments
 (0)