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 codefixer and completion provider to install OpenAPI package from extension methods #55963

Merged
merged 10 commits into from
Jun 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class AddPackageFixer : CodeFixProvider
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
if (root == null)
{
return;
}

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
if (semanticModel == null)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,20 @@

namespace Microsoft.AspNetCore.Analyzers;

internal record struct ThisAndExtensionMethod(ITypeSymbol thisType, string extensionMethod);
internal readonly struct ThisAndExtensionMethod(ITypeSymbol thisType, string extensionMethod)
{
public ITypeSymbol ThisType { get; } = thisType;
public string ExtensionMethod { get; } = extensionMethod;

public override bool Equals(object obj)
{
return obj is ThisAndExtensionMethod other &&
SymbolEqualityComparer.Default.Equals(ThisType, other.ThisType) &&
ExtensionMethod == other.ExtensionMethod;
}

public override int GetHashCode()
{
return HashCode.Combine(ThisType, ExtensionMethod);
captainsafia marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
<InternalsVisibleTo Include="Microsoft.AspNetCore.App.Analyzers.Test" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\HashCode.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ public async Task CanFixMissingExtensionMethodForBuilder()

public class MockAddPackageFixer : AddPackageFixer
{
/// <remarks>
/// This static property allows us to verify that the fixer was
/// able to successfully resolve the symbol and call into the
/// package install APIs. This is a workaround for the fact that
/// the package install APIs are not readily mockable. Note: this
/// is not intended for use across test classes.
/// </remarks>
internal static bool Invoked { get; set; }

internal override Task<CodeAction> TryCreateCodeActionAsync(
Document document,
int position,
Expand Down
Loading