Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'priority' concept to our code actions, and code refactoring/fix providers. #68511

Merged
merged 59 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
7b9dab4
Rename type
CyrusNajmabadi Jun 9, 2023
8b175b0
Rename type
CyrusNajmabadi Jun 9, 2023
72795ac
Add public api
CyrusNajmabadi Jun 9, 2023
be0075a
Rename properties
CyrusNajmabadi Jun 9, 2023
f00a244
Rename methods
CyrusNajmabadi Jun 9, 2023
38a8d57
Expose public entrypoints for setting priorities on providers
CyrusNajmabadi Jun 9, 2023
0ac048a
Add code action priority
CyrusNajmabadi Jun 9, 2023
8906650
Add priority property to code action
CyrusNajmabadi Jun 9, 2023
1a6240e
Switch to using new priority system
CyrusNajmabadi Jun 9, 2023
657bf1f
Move to using normal priority enum
CyrusNajmabadi Jun 9, 2023
5342a43
Move to using normal priority enum
CyrusNajmabadi Jun 9, 2023
ff293b1
delete unused member
CyrusNajmabadi Jun 9, 2023
b92df55
Renames
CyrusNajmabadi Jun 9, 2023
ff2b894
Move to normal priority system
CyrusNajmabadi Jun 9, 2023
cb2ae1b
Remove unnecessary action
CyrusNajmabadi Jun 9, 2023
741e7ad
Add default back in
CyrusNajmabadi Jun 9, 2023
81a4645
Add default back in
CyrusNajmabadi Jun 9, 2023
704b40e
Extract enum
CyrusNajmabadi Jun 9, 2023
8b8f3cc
Delete dead code
CyrusNajmabadi Jun 9, 2023
38e021c
No need for priority here
CyrusNajmabadi Jun 9, 2023
aff8526
Merge remote-tracking branch 'upstream/main' into codeActionPri
CyrusNajmabadi Jun 10, 2023
939e28b
Add equivalence key
CyrusNajmabadi Jun 10, 2023
7398b34
Use single enum
CyrusNajmabadi Jul 13, 2023
b33d117
Downstream impact
CyrusNajmabadi Jul 13, 2023
1ca450b
Add custom tag back
CyrusNajmabadi Jul 13, 2023
4e24505
in progress
CyrusNajmabadi Jul 14, 2023
3ac6bc1
Unify
CyrusNajmabadi Jul 14, 2023
974cf63
Unify
CyrusNajmabadi Jul 14, 2023
ce1286b
AnalyzeR
CyrusNajmabadi Jul 14, 2023
9abc31e
High pri
CyrusNajmabadi Jul 14, 2023
9334477
remove usingS
CyrusNajmabadi Jul 14, 2023
0624db5
F#
CyrusNajmabadi Jul 14, 2023
bdecd94
Delete
CyrusNajmabadi Jul 14, 2023
685ed9d
Delete
CyrusNajmabadi Jul 14, 2023
37a2b3f
Docs
CyrusNajmabadi Jul 14, 2023
178a730
Delete
CyrusNajmabadi Jul 14, 2023
e2a04c7
Remove none value
CyrusNajmabadi Jul 14, 2023
bdbf75e
IMplement
CyrusNajmabadi Jul 14, 2023
82a9e30
Merge remote-tracking branch 'upstream/main' into codeActionPri
CyrusNajmabadi Jul 14, 2023
11d72c1
Renames
CyrusNajmabadi Jul 14, 2023
0d59cca
Fixes
CyrusNajmabadi Jul 14, 2023
d95498b
Update src/Analyzers/Core/CodeFixes/UpgradeProject/AbstractUpgradePro…
CyrusNajmabadi Jul 14, 2023
39ed273
Preserve priority
CyrusNajmabadi Jul 14, 2023
923eac7
Simplify
CyrusNajmabadi Jul 14, 2023
b9cb2ab
Merge branch 'codeActionPri' of https://github.com/CyrusNajmabadi/ros…
CyrusNajmabadi Jul 14, 2023
7da1751
Simplify
CyrusNajmabadi Jul 14, 2023
71b1862
Simplify
CyrusNajmabadi Jul 14, 2023
c7f16db
API
CyrusNajmabadi Jul 14, 2023
dcb6052
API
CyrusNajmabadi Jul 14, 2023
138d3a3
Delete unneeded type
CyrusNajmabadi Jul 14, 2023
81458d9
revert
CyrusNajmabadi Jul 14, 2023
6d5c41b
revert
CyrusNajmabadi Jul 14, 2023
605ee29
revert
CyrusNajmabadi Jul 14, 2023
773e21c
revert
CyrusNajmabadi Jul 14, 2023
76e235b
revert
CyrusNajmabadi Jul 14, 2023
024a103
revert
CyrusNajmabadi Jul 14, 2023
8ced823
revert
CyrusNajmabadi Jul 14, 2023
72f86df
Simplify
CyrusNajmabadi Jul 14, 2023
ff02e51
Merge branch 'main' into codeActionPri
CyrusNajmabadi Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
// helpful, but shouldn't interfere with anything else the uesr is doing.
var priority = IsSubsequentSection(diagnostic)
? CodeActionPriority.Low
: CodeActionPriority.Medium;
: CodeActionPriority.Default;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lowest/Low/Default/High/Highest matches editor naming for this sort of thing (including the lightbulb priority class namign. so i aligned on that for our public API).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also preferred 'Default' (versus 'Normal' or 'Medium') as it prevented the need to have a duplicate 'Default' member, or to explain what the 'Default' value for these enums was. By just naming it that way, it all simplified (though it does impact the diff here).


RegisterCodeFix(context, CSharpCodeFixesResources.Remove_unreachable_code, nameof(CSharpCodeFixesResources.Remove_unreachable_code), priority);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)

var priority = diagnostic.Severity == DiagnosticSeverity.Hidden
? CodeActionPriority.Low
: CodeActionPriority.Medium;
: CodeActionPriority.Default;

var title = diagnostic.GetMessage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Microsoft.CodeAnalysis.CodeStyle
Expand Down Expand Up @@ -40,7 +39,7 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(ImmutableArray<DiagnosticDe
Debug.Assert(!supportedDiagnostics.Any(descriptor => descriptor.CustomTags.Any(t => t == WellKnownDiagnosticTags.Unnecessary)) || this is AbstractBuiltInUnnecessaryCodeStyleDiagnosticAnalyzer);
}

public virtual CodeActionRequestPriority RequestPriority => CodeActionRequestPriority.Normal;
public virtual bool IsHighPriority => false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the internal IBuiltInAnalyzer api. it currently only ever needs to know if something is high pri or not. It exists at a layer that can't reference Workspaces. So it was much simpler to just make this a boolean.

public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }

protected static DiagnosticDescriptor CreateDescriptorWithId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Simplification;
Expand All @@ -22,7 +21,7 @@ protected AbstractCodeQualityDiagnosticAnalyzer(
_generatedCodeAnalysisFlags = generatedCodeAnalysisFlags;
}

public CodeActionRequestPriority RequestPriority => CodeActionRequestPriority.Normal;
public bool IsHighPriority => false;
public sealed override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }

public sealed override void Initialize(AnalysisContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;

Expand Down Expand Up @@ -35,7 +33,7 @@ protected sealed override void InitializeWorker(AnalysisContext context)
/// them acting on an error reported in code, and can be computed fast as it only uses syntax not semantics.
/// It's also the 8th most common fix that people use, and is picked almost all the times it is shown.
/// </summary>
public override CodeActionRequestPriority RequestPriority => CodeActionRequestPriority.High;
public override bool IsHighPriority => true;

private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)

var priority = diagnostic.Severity == DiagnosticSeverity.Hidden
? CodeActionPriority.Low
: CodeActionPriority.Medium;
: CodeActionPriority.Default;

var (title, key) = diagnostic.Properties.ContainsKey(AddAccessibilityModifiersConstants.ModifiersAdded)
? (AnalyzersResources.Add_accessibility_modifiers, nameof(AnalyzersResources.Add_accessibility_modifiers))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ protected AbstractResolveConflictMarkerCodeFixProvider(
{
FixableDiagnosticIds = ImmutableArray.Create(diagnosticId);
_syntaxKinds = syntaxKinds;

#if !CODE_STYLE
// Backdoor that allows this provider to use the high-priority bucket.
this.CustomTags = this.CustomTags.Add(CodeAction.CanBeHighPriorityTag);
#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how we allow for only our own internal providers to use the 'high pri' bucket for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both the fix provider, and the fixes have to be marked 'high pri'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone who retursn .High pri from ComputeRequestPriority or who has a fix with .High pri needs to do soemthing like this. You'll see that in 4 features across thsi PR.

Copy link
Contributor

@mavasani mavasani Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this needs to be wrapped around #if !CODE_STYLE? I think we should allow even the code style layer to be able to specify high priority providers/code actions, otherwise adding a NuGet package reference to CodeStyle package would downgrade these fixers to normal priority. I thought the primary reason to move to custom tags to specify high priority was to allow third party providers to participate in this. As we don't want anything outside CodeStyle package to specify high priority for time being, if we want to be really stringent about it, we can add additional assembly name guards for the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both the fix provider, and the fixes have to be marked 'high pri'.

Why is this required for both providers and code actions?

Copy link
Contributor

@mavasani mavasani Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both the fix provider, and the fixes have to be marked 'high pri'.

Why is this required for both providers and code actions?

I see that we are requiring providers to have this custom tag for the clamping support. I can't recall our exact discussion about this in past, but I still feel CodeStyle Nuget package should be able to supply high priority code actions. Which means we need a couple of things:

  1. A well-known public API on CodeAction to specify priority, including high priority and
  2. A backdoor, not well-known or documented, but still public way to specify "please don't clamp me". This can be done via exposing CustomTags as a public property on either the code fix provider or code action (preferably latter). I think having a public CustomTags property is reasonable by itself, even outside this feature. I believe we also had an issue tracking adding such a public API in the past. If we don't like this approach and want a much more stricter check, then instead we can have a hard coded assembly name based check to decide whether or not to clamp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment https://github.com/dotnet/roslyn/pull/68511/files?diff=unified&w=1#r1264893170, which may be a good middle ground here, without requiring any additional public API or assembly name checks for clamping support.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a slow 3rd party high PRI provider would be detrimental to all our 1st party providers. This was the whole idea of keeping that to us for the time being.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this required for both providers and code actions?

See comment above for the reason for providers. We also want to limit code actions so that they do not show up ahead of our 1st party, high PRI, actions as the would break muscle memory. Like 'add using' is just that special (billions of invocations, orders of mag higher than the rest)

}

public override ImmutableArray<string> FixableDiagnosticIds { get; }

#if !CODE_STYLE

/// <summary>
/// 'Fix merge conflict markers' gets special privileges. A core user scenario around them is that a user does
/// a source control merge, gets conflicts, and then wants to open and edit them in the IDE very quickly.
Expand All @@ -59,11 +62,9 @@ protected AbstractResolveConflictMarkerCodeFixProvider(
/// them if they bring up the lightbulb on a <c>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</c> line, it should run ahead of
/// normal fix providers else so the user can quickly fix the conflict and move onto the next conflict.
/// </summary>
private protected override CodeActionRequestPriority ComputeRequestPriority()
protected override CodeActionRequestPriority ComputeRequestPriority()
=> CodeActionRequestPriority.High;

#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providing priority is no longer something CODE_STYLE cannot do.


public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
var cancellationToken = context.CancellationToken;
Expand Down Expand Up @@ -298,11 +299,14 @@ private static void RegisterCodeFixes(

static CodeAction CreateCodeAction(string title, Func<CancellationToken, Task<Document>> action, string equivalenceKey)
{
#if CODE_STYLE
return CodeAction.Create(title, action, equivalenceKey);
#else
return CodeAction.DocumentChangeAction.Create(title, action, equivalenceKey, CodeActionPriority.High);
var codeAction = CodeAction.Create(title, action, equivalenceKey, CodeActionPriority.High);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normal CodeAction methods to create a code action with priority.


#if !CODE_STYLE
// Backdoor that allows this provider to use the high-priority bucket.
codeAction.CustomTags = codeAction.CustomTags.Add(CodeAction.CanBeHighPriorityTag);
#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however, because it is high pri, the feature has to use this backdoor for that to be ok. it will be clamped otherwise.


return codeAction;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,43 @@ namespace Microsoft.CodeAnalysis.CodeStyle
{
internal abstract class AbstractFormattingCodeFixProvider : SyntaxEditorBasedCodeFixProvider
{
protected AbstractFormattingCodeFixProvider()
{
#if !CODE_STYLE
// Backdoor that allows this provider to use the high-priority bucket.
this.CustomTags = this.CustomTags.Add(CodeAction.CanBeHighPriorityTag);
#endif
}

public sealed override ImmutableArray<string> FixableDiagnosticIds
=> ImmutableArray.Create(IDEDiagnosticIds.FormattingDiagnosticId);

protected abstract ISyntaxFormatting SyntaxFormatting { get; }

#if !CODE_STYLE

/// <summary>
/// Fixing formatting is high priority. It's something the user wants to be able to fix quickly, is driven by
/// them acting on an error reported in code, and can be computed fast as it only uses syntax not semantics.
/// It's also the 8th most common fix that people use, and is picked almost all the times it is shown.
/// </summary>
private protected override CodeActionRequestPriority ComputeRequestPriority()
protected override CodeActionRequestPriority ComputeRequestPriority()
=> CodeActionRequestPriority.High;

#endif

public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
#if CODE_STYLE
context.RegisterCodeFix(
CodeAction.Create(
AnalyzersResources.Fix_formatting,
c => FixOneAsync(context, diagnostic, c),
nameof(AbstractFormattingCodeFixProvider)),
diagnostic);
#else
context.RegisterCodeFix(
CodeAction.DocumentChangeAction.Create(
AnalyzersResources.Fix_formatting,
c => FixOneAsync(context, diagnostic, c),
nameof(AbstractFormattingCodeFixProvider),
CodeActionPriority.High),
diagnostic);
var codeAction = CodeAction.Create(
AnalyzersResources.Fix_formatting,
c => FixOneAsync(context, diagnostic, c),
nameof(AbstractFormattingCodeFixProvider),
CodeActionPriority.High);

#if !CODE_STYLE
// Backdoor that allows this provider to use the high-priority bucket.
codeAction.CustomTags = codeAction.CustomTags.Add(CodeAction.CanBeHighPriorityTag);
#endif

context.RegisterCodeFix(codeAction, diagnostic);
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static void AccessSupportedDiagnostics(DiagnosticAnalyzer analyzer)

private class ThrowingDoNotCatchDiagnosticAnalyzer<TLanguageKindEnum> : ThrowingDiagnosticAnalyzer<TLanguageKindEnum>, IBuiltInAnalyzer where TLanguageKindEnum : struct
{
public CodeActionRequestPriority RequestPriority => CodeActionRequestPriority.Normal;
public bool IsHighPriority => false;

public bool OpenFileOnly(SimplifierOptions? options) => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,20 @@

namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions;

internal sealed class SuggestedActionPriorityProvider : ICodeActionRequestPriorityProvider
/// <param name="lowPriorityAnalyzers">
/// Set of de-prioritized analyzers that were moved down from 'Normal' to 'Low' priority bucket. Note that this set is
/// owned by the <see cref="SuggestedActionsSourceProvider.SuggestedActionsSource"/> and shared across priority buckets.
/// </param>
internal sealed class SuggestedActionPriorityProvider(
CodeActionRequestPriority priority,
ConcurrentSet<DiagnosticAnalyzer> lowPriorityAnalyzers)
: ICodeActionRequestPriorityProvider
{
/// <summary>
/// Set of de-prioritized analyzers that were moved down from 'Normal' to 'Low'
/// priority bucket.
/// Note that this set is owned by the <see cref="SuggestedActionsSourceProvider.SuggestedActionsSource"/>
/// and shared across priority buckets.
/// </summary>
private readonly ConcurrentSet<DiagnosticAnalyzer> _lowPriorityAnalyzers;

public SuggestedActionPriorityProvider(CodeActionRequestPriority priority, ConcurrentSet<DiagnosticAnalyzer> lowPriorityAnalyzers)
{
Priority = priority;
_lowPriorityAnalyzers = lowPriorityAnalyzers;
}

public CodeActionRequestPriority Priority { get; }
public CodeActionRequestPriority? Priority { get; } = priority;

public void AddDeprioritizedAnalyzerWithLowPriority(DiagnosticAnalyzer analyzer)
=> _lowPriorityAnalyzers.Add(analyzer);
=> lowPriorityAnalyzers.Add(analyzer);

public bool IsDeprioritizedAnalyzerWithLowPriority(DiagnosticAnalyzer analyzer)
=> _lowPriorityAnalyzers.Contains(analyzer);
=> lowPriorityAnalyzers.Contains(analyzer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ internal SuggestedAction(
CodeAction = codeAction;
}

internal virtual CodeActionPriority Priority => CodeAction.Priority;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never used. removed.


public virtual bool TryGetTelemetryId(out Guid telemetryId)
{
telemetryId = CodeAction.GetTelemetryId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public SuggestedActionsSourceProvider(
=> priority switch
{
DefaultOrderings.Highest => CodeActionRequestPriority.High,
DefaultOrderings.Default => CodeActionRequestPriority.Normal,
DefaultOrderings.Default => CodeActionRequestPriority.Default,
DefaultOrderings.Low => CodeActionRequestPriority.Low,
DefaultOrderings.Lowest => CodeActionRequestPriority.Lowest,
_ => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private async Task GetSuggestedActionsWorkerAsync(
{
SuggestedActionSetPriority.None => CodeActionRequestPriority.Lowest,
SuggestedActionSetPriority.Low => CodeActionRequestPriority.Low,
SuggestedActionSetPriority.Medium => CodeActionRequestPriority.Normal,
SuggestedActionSetPriority.Medium => CodeActionRequestPriority.Default,
SuggestedActionSetPriority.High => CodeActionRequestPriority.High,
_ => throw ExceptionUtilities.UnexpectedValue(set.Priority),
};
Expand Down Expand Up @@ -233,7 +233,7 @@ private async IAsyncEnumerable<SuggestedActionSet> GetCodeFixesAndRefactoringsAs

async Task<ImmutableArray<UnifiedSuggestedActionSet>> GetCodeFixesAsync()
{
using var _ = TelemetryLogging.LogBlockTimeAggregated(FunctionId.SuggestedAction_Summary, $"Total.Pri{(int)priorityProvider.Priority}.{nameof(GetCodeFixesAsync)}");
using var _ = TelemetryLogging.LogBlockTimeAggregated(FunctionId.SuggestedAction_Summary, $"Total.Pri{priorityProvider.Priority.GetPriorityInt()}.{nameof(GetCodeFixesAsync)}");

if (owner._codeFixService == null ||
!supportsFeatureService.SupportsCodeFixes(target.SubjectBuffer) ||
Expand All @@ -249,7 +249,7 @@ async Task<ImmutableArray<UnifiedSuggestedActionSet>> GetCodeFixesAsync()

async Task<ImmutableArray<UnifiedSuggestedActionSet>> GetRefactoringsAsync()
{
using var _ = TelemetryLogging.LogBlockTimeAggregated(FunctionId.SuggestedAction_Summary, $"Total.Pri{(int)priorityProvider.Priority}.{nameof(GetRefactoringsAsync)}");
using var _ = TelemetryLogging.LogBlockTimeAggregated(FunctionId.SuggestedAction_Summary, $"Total.Pri{priorityProvider.Priority.GetPriorityInt()}.{nameof(GetRefactoringsAsync)}");

if (!selection.HasValue)
{
Expand Down Expand Up @@ -325,7 +325,7 @@ static SuggestedActionSetPriority ConvertToSuggestedActionSetPriority(CodeAction
{
CodeActionPriority.Lowest => SuggestedActionSetPriority.None,
CodeActionPriority.Low => SuggestedActionSetPriority.Low,
CodeActionPriority.Medium => SuggestedActionSetPriority.Medium,
CodeActionPriority.Default => SuggestedActionSetPriority.Medium,
CodeActionPriority.High => SuggestedActionSetPriority.High,
_ => throw ExceptionUtilities.Unreachable(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
public DiagnosticAnalyzerCategory GetAnalyzerCategory()
=> DiagnosticAnalyzerCategory.SemanticDocumentAnalysis;

public CodeActionRequestPriority RequestPriority => CodeActionRequestPriority.Normal;
public bool IsHighPriority => false;

public bool OpenFileOnly(SimplifierOptions? options)
=> false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.RenameTracking
{
[ExportCodeRefactoringProvider(LanguageNames.CSharp, LanguageNames.VisualBasic,
Name = PredefinedCodeRefactoringProviderNames.RenameTracking), Shared]
[method: ImportingConstructor]
[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
internal class RenameTrackingCodeRefactoringProvider(
ITextUndoHistoryRegistry undoHistoryRegistry,
[ImportMany] IEnumerable<IRefactorNotifyService> refactorNotifyServices) : CodeRefactoringProvider
internal class RenameTrackingCodeRefactoringProvider : CodeRefactoringProvider
{
private readonly ITextUndoHistoryRegistry _undoHistoryRegistry = undoHistoryRegistry;
private readonly IEnumerable<IRefactorNotifyService> _refactorNotifyServices = refactorNotifyServices;
private readonly ITextUndoHistoryRegistry _undoHistoryRegistry;
private readonly IEnumerable<IRefactorNotifyService> _refactorNotifyServices;

[ImportingConstructor]
[SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
public RenameTrackingCodeRefactoringProvider(
ITextUndoHistoryRegistry undoHistoryRegistry,
[ImportMany] IEnumerable<IRefactorNotifyService> refactorNotifyServices)
{
_undoHistoryRegistry = undoHistoryRegistry;
_refactorNotifyServices = refactorNotifyServices;

// Backdoor that allows this provider to use the high-priority bucket.
this.CustomTags = this.CustomTags.Add(CodeAction.CanBeHighPriorityTag);
}

public override Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
Expand All @@ -41,7 +50,7 @@ public override Task ComputeRefactoringsAsync(CodeRefactoringContext context)
/// change the name of something and pop up the lightbulb without having to wait for the rest to
/// compute.
/// </summary>
private protected override CodeActionRequestPriority ComputeRequestPriority()
protected override CodeActionRequestPriority ComputeRequestPriority()
=> CodeActionRequestPriority.High;
}
}
Loading