Skip to content

Commit

Permalink
Remove fallbacks (3) (#74323)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jul 11, 2024
1 parent 718c6b5 commit c649fbb
Show file tree
Hide file tree
Showing 33 changed files with 126 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CSharp.CodeGeneration;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.Formatting;
using Microsoft.CodeAnalysis.CSharp.Simplification;

Expand All @@ -20,6 +19,5 @@ internal static class CSharpCodeActionOptions
SimplifierOptions = CSharpSimplifierOptions.Default
},
CodeGenerationOptions = CSharpCodeGenerationOptions.Default,
CodeStyleOptions = CSharpIdeCodeStyleOptions.Default
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.ImplementType;
using Microsoft.CodeAnalysis.VisualBasic.CodeGeneration;
using Microsoft.CodeAnalysis.VisualBasic.CodeStyle;
using Microsoft.CodeAnalysis.VisualBasic.Formatting;
using Microsoft.CodeAnalysis.VisualBasic.Simplification;

Expand All @@ -21,7 +20,6 @@ internal static class VisualBasicCodeActionOptions
SimplifierOptions = VisualBasicSimplifierOptions.Default,
},
CodeGenerationOptions = VisualBasicCodeGenerationOptions.Default,
CodeStyleOptions = VisualBasicIdeCodeStyleOptions.Default
};

public static CodeActionOptions With(this CodeActionOptions options, VisualBasicSyntaxFormattingOptions value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.ImplementAbstractClass

Protected Overrides Function TryGetNewDocument(
document As Document,
options As ImplementTypeGenerationOptions,
options As ImplementTypeOptions,
typeSyntax As TypeSyntax,
cancellationToken As CancellationToken
) As Document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.ImplementInterface

Protected Overrides Function TryGetNewDocument(
document As Document,
options As ImplementTypeGenerationOptions,
options As ImplementTypeOptions,
typeSyntax As TypeSyntax,
cancellationToken As CancellationToken
) As Document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers

Protected MustOverride Overloads Function TryGetNewDocument(
document As Document,
options As ImplementTypeGenerationOptions,
options As ImplementTypeOptions,
typeSyntax As TypeSyntax,
cancellationToken As CancellationToken) As Document

Expand Down Expand Up @@ -165,7 +165,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers
Return False
End If

Dim newDocument = TryGetNewDocument(document, _globalOptions.GetImplementTypeGenerationOptions(document.Project.Services), identifier, cancellationToken)
Dim newDocument = TryGetNewDocument(document, _globalOptions.GetImplementTypeOptions(document.Project.Language), identifier, cancellationToken)

If newDocument Is Nothing Then
Return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)

var actions = token.Parent.GetAncestorsOrThis<TypeSyntax>()
.Where(_interfaceName)
.Select(n => service.GetCodeActions(document, context.Options.GetImplementTypeGenerationOptions(document.Project.Services), model, n, cancellationToken))
.Select(n => service.GetCodeActions(document, context.Options.GetImplementTypeOptions(document.Project.Services), model, n, cancellationToken))
.FirstOrDefault(a => !a.IsEmpty);

if (actions.IsDefaultOrEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
return;

var data = await ImplementAbstractClassData.TryGetDataAsync(
document, classNode, GetClassIdentifier(classNode), context.Options.GetImplementTypeGenerationOptions(document.Project.Services), cancellationToken).ConfigureAwait(false);
document, classNode, GetClassIdentifier(classNode), context.Options.GetImplementTypeOptions(document.Project.Services), cancellationToken).ConfigureAwait(false);
if (data == null)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
namespace Microsoft.CodeAnalysis.ImplementAbstractClass;

internal sealed class ImplementAbstractClassData(
Document document, ImplementTypeGenerationOptions options, SyntaxNode classNode, SyntaxToken classIdentifier,
Document document, ImplementTypeOptions options, SyntaxNode classNode, SyntaxToken classIdentifier,
INamedTypeSymbol classType, INamedTypeSymbol abstractClassType,
ImmutableArray<(INamedTypeSymbol type, ImmutableArray<ISymbol> members)> unimplementedMembers)
{
private readonly Document _document = document;
private readonly ImplementTypeGenerationOptions _options = options;
private readonly ImplementTypeOptions _options = options;
private readonly SyntaxNode _classNode = classNode;
private readonly SyntaxToken _classIdentifier = classIdentifier;
private readonly ImmutableArray<(INamedTypeSymbol type, ImmutableArray<ISymbol> members)> _unimplementedMembers = unimplementedMembers;
Expand All @@ -38,7 +38,7 @@ internal sealed class ImplementAbstractClassData(
public readonly INamedTypeSymbol AbstractClassType = abstractClassType;

public static async Task<ImplementAbstractClassData?> TryGetDataAsync(
Document document, SyntaxNode classNode, SyntaxToken classIdentifier, ImplementTypeGenerationOptions options, CancellationToken cancellationToken)
Document document, SyntaxNode classNode, SyntaxToken classIdentifier, ImplementTypeOptions options, CancellationToken cancellationToken)
{
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
if (semanticModel.GetDeclaredSymbol(classNode, cancellationToken) is not INamedTypeSymbol classType)
Expand Down Expand Up @@ -68,7 +68,7 @@ internal sealed class ImplementAbstractClassData(
}

public static async Task<Document?> TryImplementAbstractClassAsync(
Document document, SyntaxNode classNode, SyntaxToken classIdentifier, ImplementTypeGenerationOptions options, CancellationToken cancellationToken)
Document document, SyntaxNode classNode, SyntaxToken classIdentifier, ImplementTypeOptions options, CancellationToken cancellationToken)
{
var data = await TryGetDataAsync(document, classNode, classIdentifier, options, cancellationToken).ConfigureAwait(false);
if (data == null)
Expand All @@ -81,8 +81,8 @@ public async Task<Document> ImplementAbstractClassAsync(
ISymbol? throughMember, bool? canDelegateAllMembers, CancellationToken cancellationToken)
{
var compilation = await _document.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false);
var memberDefinitions = GenerateMembers(compilation, throughMember, _options.ImplementTypeOptions.PropertyGenerationBehavior, cancellationToken);
var groupMembers = _options.ImplementTypeOptions.InsertionBehavior == ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind;
var memberDefinitions = GenerateMembers(compilation, throughMember, _options.PropertyGenerationBehavior, cancellationToken);
var groupMembers = _options.InsertionBehavior == ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind;

// If we're implementing through one of our members, but we can't delegate all members
// through it, then give an error message on the class decl letting the user know.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ internal partial class ImplementInterfaceCodeAction : CodeAction
private readonly bool _onlyRemaining;
protected readonly ISymbol? ThroughMember;
protected readonly Document Document;
protected readonly ImplementTypeGenerationOptions Options;
protected readonly ImplementTypeOptions Options;
protected readonly State State;
protected readonly AbstractImplementInterfaceService Service;
private readonly string _equivalenceKey;

internal ImplementInterfaceCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state,
bool explicitly,
bool abstractly,
Expand All @@ -59,7 +59,7 @@ internal ImplementInterfaceCodeAction(
public static ImplementInterfaceCodeAction CreateImplementAbstractlyCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state)
{
return new ImplementInterfaceCodeAction(service, document, options, state, explicitly: false, abstractly: true, onlyRemaining: true, throughMember: null);
Expand All @@ -68,7 +68,7 @@ public static ImplementInterfaceCodeAction CreateImplementAbstractlyCodeAction(
public static ImplementInterfaceCodeAction CreateImplementCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state)
{
return new ImplementInterfaceCodeAction(service, document, options, state, explicitly: false, abstractly: false, onlyRemaining: true, throughMember: null);
Expand All @@ -77,7 +77,7 @@ public static ImplementInterfaceCodeAction CreateImplementCodeAction(
public static ImplementInterfaceCodeAction CreateImplementExplicitlyCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state)
{
return new ImplementInterfaceCodeAction(service, document, options, state, explicitly: true, abstractly: false, onlyRemaining: false, throughMember: null);
Expand All @@ -86,7 +86,7 @@ public static ImplementInterfaceCodeAction CreateImplementExplicitlyCodeAction(
public static ImplementInterfaceCodeAction CreateImplementThroughMemberCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state,
ISymbol throughMember)
{
Expand All @@ -96,7 +96,7 @@ public static ImplementInterfaceCodeAction CreateImplementThroughMemberCodeActio
public static ImplementInterfaceCodeAction CreateImplementRemainingExplicitlyCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state)
{
return new ImplementInterfaceCodeAction(service, document, options, state, explicitly: true, abstractly: false, onlyRemaining: true, throughMember: null);
Expand Down Expand Up @@ -197,13 +197,13 @@ protected async Task<Document> GetUpdatedDocumentAsync(
var isComImport = unimplementedMembers.Any(static t => t.type.IsComImport);

var memberDefinitions = GenerateMembers(
compilation, tree.Options, unimplementedMembers, Options.ImplementTypeOptions.PropertyGenerationBehavior);
compilation, tree.Options, unimplementedMembers, Options.PropertyGenerationBehavior);

// Only group the members in the destination if the user wants that *and*
// it's not a ComImport interface. Member ordering in ComImport interfaces
// matters, so we don't want to much with them.
var groupMembers = !isComImport &&
Options.ImplementTypeOptions.InsertionBehavior == ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind;
Options.InsertionBehavior == ImplementTypeInsertionBehavior.WithOtherMembersOfTheSameKind;

return await CodeGenerator.AddMemberDeclarationsAsync(
new CodeGenerationSolutionContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static bool ShouldImplementDisposePattern(State state, bool explicitly)
private sealed class ImplementInterfaceWithDisposePatternCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state,
bool explicitly,
bool abstractly,
Expand All @@ -97,7 +97,7 @@ private sealed class ImplementInterfaceWithDisposePatternCodeAction(
public static ImplementInterfaceWithDisposePatternCodeAction CreateImplementWithDisposePatternCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state)
{
return new ImplementInterfaceWithDisposePatternCodeAction(service, document, options, state, explicitly: false, abstractly: false, throughMember: null);
Expand All @@ -106,7 +106,7 @@ public static ImplementInterfaceWithDisposePatternCodeAction CreateImplementWith
public static ImplementInterfaceWithDisposePatternCodeAction CreateImplementExplicitlyWithDisposePatternCodeAction(
AbstractImplementInterfaceService service,
Document document,
ImplementTypeGenerationOptions options,
ImplementTypeOptions options,
State state)
{
return new ImplementInterfaceWithDisposePatternCodeAction(service, document, options, state, explicitly: true, abstractly: false, throughMember: null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected AbstractImplementInterfaceService()
protected abstract SyntaxNode CreateFinalizer(SyntaxGenerator generator, INamedTypeSymbol classType, string disposeMethodDisplayString);

public async Task<Document> ImplementInterfaceAsync(
Document document, ImplementTypeGenerationOptions options, SyntaxNode node, CancellationToken cancellationToken)
Document document, ImplementTypeOptions options, SyntaxNode node, CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.Refactoring_ImplementInterface, cancellationToken))
{
Expand All @@ -60,14 +60,14 @@ public async Task<Document> ImplementInterfaceAsync(
}
}

public ImmutableArray<CodeAction> GetCodeActions(Document document, ImplementTypeGenerationOptions options, SemanticModel model, SyntaxNode node, CancellationToken cancellationToken)
public ImmutableArray<CodeAction> GetCodeActions(Document document, ImplementTypeOptions options, SemanticModel model, SyntaxNode node, CancellationToken cancellationToken)
{
var state = State.Generate(this, document, model, node, cancellationToken);
return GetActions(document, options, state, cancellationToken).ToImmutableArray();
}

private IEnumerable<CodeAction> GetActions(
Document document, ImplementTypeGenerationOptions options, State state, CancellationToken cancellationToken)
Document document, ImplementTypeOptions options, State state, CancellationToken cancellationToken)
{
if (state == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ namespace Microsoft.CodeAnalysis.ImplementInterface;

internal interface IImplementInterfaceService : ILanguageService
{
Task<Document> ImplementInterfaceAsync(Document document, ImplementTypeGenerationOptions options, SyntaxNode node, CancellationToken cancellationToken);
ImmutableArray<CodeAction> GetCodeActions(Document document, ImplementTypeGenerationOptions options, SemanticModel model, SyntaxNode node, CancellationToken cancellationToken);
Task<Document> ImplementInterfaceAsync(Document document, ImplementTypeOptions options, SyntaxNode node, CancellationToken cancellationToken);
ImmutableArray<CodeAction> GetCodeActions(Document document, ImplementTypeOptions options, SemanticModel model, SyntaxNode node, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ImplementInterface
Dim service = document.GetLanguageService(Of IImplementInterfaceService)()
Dim actions = service.GetCodeActions(
document,
context.Options.GetImplementTypeGenerationOptions(document.Project.Services),
context.Options.GetImplementTypeOptions(document.Project.Services),
Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False),
typeNode,
cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.CodeGeneration;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.ExtractMethod;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.ImplementType;
using Microsoft.CodeAnalysis.Options;
Expand All @@ -22,7 +20,6 @@ public static CodeActionOptions GetCodeActionOptions(this IGlobalOptionService g
{
CleanupOptions = globalOptions.GetCodeCleanupOptions(languageServices),
CodeGenerationOptions = globalOptions.GetCodeGenerationOptions(languageServices),
CodeStyleOptions = globalOptions.GetCodeStyleOptions(languageServices),
SearchOptions = globalOptions.GetSymbolSearchOptions(languageServices.Language),
ImplementTypeOptions = globalOptions.GetImplementTypeOptions(languageServices.Language),
HideAdvancedMembers = globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, languageServices.Language),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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 Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.ImplementType
Expand All @@ -16,10 +15,6 @@ public static ImplementTypeOptions GetImplementTypeOptions(this IGlobalOptionSer
PropertyGenerationBehavior = globalOptions.GetOption(PropertyGenerationBehavior, language)
};

public static ImplementTypeGenerationOptions GetImplementTypeGenerationOptions(this IGlobalOptionService globalOptions, LanguageServices languageServices)
=> new(globalOptions.GetImplementTypeOptions(languageServices.Language),
globalOptions.CreateProvider());

private static readonly OptionGroup s_implementTypeGroup = new(name: "implement_type", description: "");

public static readonly PerLanguageOption2<ImplementTypeInsertionBehavior> InsertionBehavior =
Expand Down
Loading

0 comments on commit c649fbb

Please sign in to comment.