-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Further cleanup of the code action api (5) #80215
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
Changes from all commits
e40e783
9e0eee7
18a3e8a
c264856
8710969
d9c4363
3e285aa
5677016
2f32052
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,9 @@ | |
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.CodeActions; | ||
| using Microsoft.CodeAnalysis.CodeFixes; | ||
| using Microsoft.CodeAnalysis.CodeFixesAndRefactorings; | ||
| using Microsoft.CodeAnalysis.CodeRefactorings; | ||
| using Microsoft.CodeAnalysis.Editor.Shared.Utilities; | ||
| using Microsoft.CodeAnalysis.Internal.Log; | ||
| using Microsoft.VisualStudio.Language.Intellisense; | ||
|
|
@@ -24,28 +26,28 @@ internal sealed class RefactorOrFixAllSuggestedAction( | |
| ITextBuffer subjectBuffer, | ||
| IRefactorOrFixAllState fixAllState, | ||
| CodeAction originalCodeAction, | ||
| string? diagnosticTelemetryId, | ||
| AbstractFixAllCodeAction fixAllCodeAction) | ||
| string? diagnosticTelemetryId) | ||
| : SuggestedAction(threadingContext, | ||
| sourceProvider, | ||
| originalSolution, | ||
| subjectBuffer, | ||
| fixAllState.FixAllProvider, | ||
| fixAllCodeAction), | ||
| fixAllState switch | ||
| { | ||
| FixAllState state => new FixAllCodeAction(state), | ||
| RefactorAllState state => new RefactorAllCodeAction(state), | ||
| _ => throw ExceptionUtilities.UnexpectedValue(fixAllState) | ||
| }), | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this typeswitching goes away and gets nice in a later PR in this series. |
||
| ITelemetryDiagnosticID<string?> | ||
| { | ||
| public CodeAction OriginalCodeAction { get; } = originalCodeAction; | ||
|
|
||
| public IRefactorOrFixAllState FixAllState { get; } = fixAllState; | ||
|
|
||
| public string? GetDiagnosticID() => diagnosticTelemetryId; | ||
|
|
||
| public override bool TryGetTelemetryId(out Guid telemetryId) | ||
| { | ||
| // We get the telemetry id for the original code action we are fixing, | ||
| // not the special 'FixAllCodeAction'. that is the .CodeAction this | ||
| // SuggestedAction is pointing at. | ||
| telemetryId = OriginalCodeAction.GetTelemetryId(FixAllState.Scope); | ||
| telemetryId = originalCodeAction.GetTelemetryId(fixAllState.Scope); | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -54,15 +56,15 @@ protected override async Task InnerInvokeAsync( | |
| { | ||
| await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); | ||
|
|
||
| var fixAllKind = FixAllState.FixAllKind; | ||
| var fixAllKind = fixAllState.FixAllKind; | ||
| var functionId = fixAllKind switch | ||
| { | ||
| FixAllKind.CodeFix => FunctionId.CodeFixes_FixAllOccurrencesSession, | ||
| FixAllKind.Refactoring => FunctionId.Refactoring_FixAllOccurrencesSession, | ||
| _ => throw ExceptionUtilities.UnexpectedValue(fixAllKind) | ||
| }; | ||
|
|
||
| using (Logger.LogBlock(functionId, FixAllLogger.CreateCorrelationLogMessage(FixAllState.CorrelationId), cancellationToken)) | ||
| using (Logger.LogBlock(functionId, FixAllLogger.CreateCorrelationLogMessage(fixAllState.CorrelationId), cancellationToken)) | ||
| { | ||
| await base.InnerInvokeAsync(progress, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,25 +287,20 @@ async Task<ImmutableArray<UnifiedSuggestedActionSet>> GetRefactoringsAsync() | |
| ISuggestedAction ConvertToSuggestedAction(UnifiedSuggestedAction unifiedSuggestedAction) | ||
| => unifiedSuggestedAction switch | ||
| { | ||
| UnifiedCodeFixSuggestedAction codeFixAction => new CodeFixSuggestedAction( | ||
| UnifiedCodeFixSuggestedAction codeFixAction => new SuggestedActionWithNestedFlavors( | ||
| _threadingContext, owner, originalDocument, subjectBuffer, | ||
| codeFixAction.CodeFix, codeFixAction.Provider, codeFixAction.OriginalCodeAction, | ||
| ConvertToSuggestedActionSet(codeFixAction.FixAllFlavors, originalDocument)), | ||
| UnifiedCodeRefactoringSuggestedAction codeRefactoringAction => new CodeRefactoringSuggestedAction( | ||
| codeFixAction.Provider, codeFixAction.OriginalCodeAction, | ||
| ConvertToSuggestedActionSet(codeFixAction.FixAllFlavors, originalDocument), | ||
| codeFixAction.CodeFix.PrimaryDiagnostic), | ||
| UnifiedCodeRefactoringSuggestedAction codeRefactoringAction => new SuggestedActionWithNestedFlavors( | ||
| _threadingContext, owner, originalDocument, subjectBuffer, | ||
| codeRefactoringAction.Provider, codeRefactoringAction.OriginalCodeAction, | ||
| ConvertToSuggestedActionSet(codeRefactoringAction.FixAllFlavors, originalDocument)), | ||
| UnifiedFixAllCodeFixSuggestedAction fixAllAction | ||
| ConvertToSuggestedActionSet(codeRefactoringAction.FixAllFlavors, originalDocument), | ||
| diagnostic: null), | ||
| UnifiedRefactorOrFixAllSuggestedAction refactorOrFixAllAction | ||
| => new RefactorOrFixAllSuggestedAction( | ||
| _threadingContext, owner, originalSolution, subjectBuffer, | ||
| fixAllAction.FixAllState, fixAllAction.OriginalCodeAction, fixAllAction.TelemetryId, | ||
| new FixAllCodeAction(fixAllAction.FixAllState)), | ||
| UnifiedRefactorAllCodeRefactoringSuggestedAction fixAllCodeRefactoringAction | ||
| => new RefactorOrFixAllSuggestedAction( | ||
| _threadingContext, owner, originalSolution, subjectBuffer, | ||
| fixAllCodeRefactoringAction.FixAllState, fixAllCodeRefactoringAction.OriginalCodeAction, | ||
| diagnosticTelemetryId: null, | ||
| new RefactorAllCodeRefactoringCodeAction(fixAllCodeRefactoringAction.FixAllState)), | ||
| refactorOrFixAllAction.FixAllState, refactorOrFixAllAction.OriginalCodeAction, refactorOrFixAllAction.TelemetryId), | ||
| UnifiedSuggestedActionWithNestedActions nestedAction => new SuggestedActionWithNestedActions( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code will collapse even further in following PRs. |
||
| _threadingContext, owner, originalSolution, subjectBuffer, | ||
| nestedAction.Provider, nestedAction.OriginalCodeAction, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.CodeRefactorings; | |
| /// <summary> | ||
| /// Fix all code action for a code action registered by a <see cref="CodeRefactoringProvider"/>. | ||
| /// </summary> | ||
| internal sealed class RefactorAllCodeRefactoringCodeAction(IRefactorOrFixAllState fixAllState) | ||
| internal sealed class RefactorAllCodeAction(IRefactorOrFixAllState fixAllState) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. named this akin to FixAllCodeAction. NOte: a following PR merges those into one RefactorOrFixAllCodeAction. |
||
| : AbstractFixAllCodeAction(fixAllState, showPreviewChangesDialog: true) | ||
| { | ||
| protected override IRefactorOrFixAllContext CreateFixAllContext(IRefactorOrFixAllState fixAllState, IProgress<CodeAnalysisProgress> progressTracker, CancellationToken cancellationToken) | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Folded CodeRefactoring suggested actions and CodeFix suggested actions into this common type.