-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Don't provide CodeActionWithDialog if option service is null #67951
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -113,9 +113,13 @@ private async Task HandleNonSelectionAsync( | |||
GetExistingMemberInfo( | ||||
containingType, out var hasEquals, out var hasGetHashCode); | ||||
|
||||
var globalOptions = document.Project.Solution.Services.GetService<ILegacyGlobalOptionsWorkspaceService>(); | ||||
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. ❓ Is it possible to leverage #66798 instead? 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. Oh I don't know this service exists 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. I don't see it provides reading these values
It seems like it has a fall back of CodeCleanUpOptions, but the values used here are not part of it, like https://sourceroslyn.io/#Microsoft.CodeAnalysis.Workspaces/Options/ILegacyGlobalOptionsWorkspaceService.cs,ebbb686a0c6361c3,references |
||||
if (globalOptions == null) | ||||
return; | ||||
|
||||
var actions = await CreateActionsAsync( | ||||
document, typeDeclaration, containingType, viableMembers, fallbackOptions, | ||||
hasEquals, hasGetHashCode, withDialog: true, cancellationToken).ConfigureAwait(false); | ||||
hasEquals, hasGetHashCode, withDialog: true, globalOptions, cancellationToken).ConfigureAwait(false); | ||||
|
||||
context.RegisterRefactorings(actions, textSpan); | ||||
} | ||||
|
@@ -190,7 +194,7 @@ public async Task<ImmutableArray<CodeAction>> GenerateEqualsAndGetHashCodeFromMe | |||
|
||||
return await CreateActionsAsync( | ||||
document, typeDeclaration, info.ContainingType, info.SelectedMembers, fallbackOptions, | ||||
hasEquals, hasGetHashCode, withDialog: false, cancellationToken).ConfigureAwait(false); | ||||
hasEquals, hasGetHashCode, withDialog: false, globalOptions: null, cancellationToken).ConfigureAwait(false); | ||||
} | ||||
} | ||||
|
||||
|
@@ -201,7 +205,7 @@ public async Task<ImmutableArray<CodeAction>> GenerateEqualsAndGetHashCodeFromMe | |||
private async Task<ImmutableArray<CodeAction>> CreateActionsAsync( | ||||
Document document, SyntaxNode typeDeclaration, INamedTypeSymbol containingType, ImmutableArray<ISymbol> selectedMembers, | ||||
CleanCodeGenerationOptionsProvider fallbackOptions, | ||||
bool hasEquals, bool hasGetHashCode, bool withDialog, CancellationToken cancellationToken) | ||||
bool hasEquals, bool hasGetHashCode, bool withDialog, ILegacyGlobalOptionsWorkspaceService? globalOptions, CancellationToken cancellationToken) | ||||
{ | ||||
using var _ = ArrayBuilder<Task<CodeAction>>.GetInstance(out var tasks); | ||||
|
||||
|
@@ -215,42 +219,50 @@ private async Task<ImmutableArray<CodeAction>> CreateActionsAsync( | |||
// the user would need to bother just generating that member without also | ||||
// generating 'Equals' as well. | ||||
tasks.Add(CreateCodeActionAsync( | ||||
document, typeDeclaration, containingType, selectedMembers, fallbackOptions, | ||||
document, typeDeclaration, containingType, selectedMembers, fallbackOptions, globalOptions, | ||||
generateEquals: true, generateGetHashCode: false, withDialog, cancellationToken)); | ||||
tasks.Add(CreateCodeActionAsync( | ||||
document, typeDeclaration, containingType, selectedMembers, fallbackOptions, | ||||
document, typeDeclaration, containingType, selectedMembers, fallbackOptions, globalOptions, | ||||
generateEquals: true, generateGetHashCode: true, withDialog, cancellationToken)); | ||||
} | ||||
else if (!hasEquals) | ||||
{ | ||||
tasks.Add(CreateCodeActionAsync( | ||||
document, typeDeclaration, containingType, selectedMembers, fallbackOptions, | ||||
document, typeDeclaration, containingType, selectedMembers, fallbackOptions, globalOptions, | ||||
generateEquals: true, generateGetHashCode: false, withDialog, cancellationToken)); | ||||
} | ||||
else if (!hasGetHashCode) | ||||
{ | ||||
tasks.Add(CreateCodeActionAsync( | ||||
document, typeDeclaration, containingType, selectedMembers, fallbackOptions, | ||||
document, typeDeclaration, containingType, selectedMembers, fallbackOptions, globalOptions, | ||||
generateEquals: false, generateGetHashCode: true, withDialog, cancellationToken)); | ||||
} | ||||
|
||||
var codeActions = await Task.WhenAll(tasks).ConfigureAwait(false); | ||||
return codeActions.ToImmutableArray(); | ||||
|
||||
} | ||||
|
||||
private Task<CodeAction> CreateCodeActionAsync( | ||||
Document document, SyntaxNode typeDeclaration, INamedTypeSymbol containingType, ImmutableArray<ISymbol> members, | ||||
CleanCodeGenerationOptionsProvider fallbackOptions, | ||||
CleanCodeGenerationOptionsProvider fallbackOptions, ILegacyGlobalOptionsWorkspaceService? globalOptions, | ||||
bool generateEquals, bool generateGetHashCode, bool withDialog, CancellationToken cancellationToken) | ||||
{ | ||||
return withDialog | ||||
? CreateCodeActionWithDialogAsync(document, typeDeclaration, containingType, members, fallbackOptions, generateEquals, generateGetHashCode, cancellationToken) | ||||
: CreateCodeActionWithoutDialogAsync(document, typeDeclaration, containingType, members, fallbackOptions, generateEquals, generateGetHashCode, cancellationToken); | ||||
if (withDialog) | ||||
{ | ||||
// We can't create dialog code action if globalOptions is null | ||||
Contract.ThrowIfNull(globalOptions); | ||||
return CreateCodeActionWithDialogAsync(document, typeDeclaration, containingType, members, fallbackOptions, globalOptions, generateEquals, generateGetHashCode, cancellationToken); | ||||
} | ||||
else | ||||
{ | ||||
return CreateCodeActionWithoutDialogAsync(document, typeDeclaration, containingType, members, fallbackOptions, generateEquals, generateGetHashCode, cancellationToken); | ||||
} | ||||
} | ||||
|
||||
private async Task<CodeAction> CreateCodeActionWithDialogAsync( | ||||
Document document, SyntaxNode typeDeclaration, INamedTypeSymbol containingType, ImmutableArray<ISymbol> members, | ||||
CleanCodeGenerationOptionsProvider fallbackOptions, | ||||
CleanCodeGenerationOptionsProvider fallbackOptions, ILegacyGlobalOptionsWorkspaceService globalOptions, | ||||
bool generateEquals, bool generateGetHashCode, CancellationToken cancellationToken) | ||||
{ | ||||
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); | ||||
|
@@ -259,7 +271,6 @@ private async Task<CodeAction> CreateCodeActionWithDialogAsync( | |||
|
||||
if (CanImplementIEquatable(semanticModel, containingType, out var equatableTypeOpt)) | ||||
{ | ||||
var globalOptions = document.Project.Solution.Services.GetRequiredService<ILegacyGlobalOptionsWorkspaceService>(); | ||||
var value = globalOptions.GetGenerateEqualsAndGetHashCodeFromMembersImplementIEquatable(document.Project.Language); | ||||
|
||||
var displayName = equatableTypeOpt.ToDisplayString(new SymbolDisplayFormat( | ||||
|
@@ -274,7 +285,6 @@ private async Task<CodeAction> CreateCodeActionWithDialogAsync( | |||
|
||||
if (!HasOperators(containingType)) | ||||
{ | ||||
var globalOptions = document.Project.Solution.Services.GetRequiredService<ILegacyGlobalOptionsWorkspaceService>(); | ||||
var value = globalOptions.GetGenerateEqualsAndGetHashCodeFromMembersGenerateOperators(document.Project.Language); | ||||
|
||||
pickMembersOptions.Add(new PickMembersOption( | ||||
|
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.
The core of the change