File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff 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 ( )
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments