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

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented May 29, 2024

Screen.Recording.2024-06-14.at.11.16.18.AM.mov

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label May 29, 2024
@captainsafia captainsafia force-pushed the safia/openapi-extensions-analyzer branch from d283852 to 411d738 Compare May 29, 2024 23:13
@captainsafia captainsafia added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework labels May 29, 2024
@captainsafia captainsafia force-pushed the safia/openapi-extensions-analyzer branch from 24a6324 to ab4bbe6 Compare June 3, 2024 21:28
@captainsafia captainsafia changed the title Add analyzer to install OpenAPI package from extension methods Add codefixer to install OpenAPI package from extension methods Jun 4, 2024
@captainsafia captainsafia marked this pull request as ready for review June 4, 2024 17:27
@captainsafia captainsafia requested a review from a team June 4, 2024 19:37
@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@BrennanConroy
Copy link
Member

This seems like a good general purpose fixer, do we plan on adding more of our methods to this?

@captainsafia
Copy link
Member Author

captainsafia commented Jun 5, 2024

This seems like a good general purpose fixer, do we plan on adding more of our methods to this?

We could -- there'd be some additional work to do to source all of the APIs that could be invoked here and provide them to this extension point in some way.

For expediency, I just focused on the APIs in the OpenAPI surface area here. I can file an issue to track making this more general purpose.

See #56092.

}

var targetThisAndExtensionMethod = new ThisAndExtensionMethod(symbolType, methodName);
if (_wellKnownExtensionMethodCache.TryGetValue(targetThisAndExtensionMethod, out var packageSourceAndNamespace))
Copy link
Member

Choose a reason for hiding this comment

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

Is a dictionary worthwhile for 2 members, or do we anticipate more in the near future?

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 anticipate that we'll have a larger collection here (see #56092). Whether or not Dictionary ends up being the right type for the complete set of extension methods remains to be seen but it seemed sufficient for now.

@davidfowl
Copy link
Member

We could -- there'd be some additional work to do to source all of the APIs that could be invoked here and provide them to this extension point in some way.

No could, we should. What is the work to make this work for all of the ASP.NET Core extension methods?

@captainsafia
Copy link
Member Author

No could, we should. What is the work to make this work for all of the ASP.NET Core extension methods?

Thanks for the grammar lesson. 🙃

#56092 tracks doing this for everything. Before we do that, we should pilot the package install fixer and a completion provider to recommend extension methods from external packages on primary types with the OpenAPI surface area.

As far as genericizing/automating this, we'll probably need to author some sort of script to scrape the metadata the analyzer consumes from the repo and feed it through.

@davidfowl
Copy link
Member

@IEvangelist Random question, what do the docs do to get this list https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.iapplicationbuilder?view=aspnetcore-8.0#extension-methods?

I am thinking maybe we can use a similar process to populate the list of methods and their packages.

@IEvangelist
Copy link
Member

IEvangelist commented Jun 7, 2024

@IEvangelist Random question, what do the docs do to get this list https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.iapplicationbuilder?view=aspnetcore-8.0#extension-methods?

I am thinking maybe we can use a similar process to populate the list of methods and their packages.

@davidfowl

I'm not sure how familiar you are with all of this, so I'll speak as if you're not familiar with any of it. This is something that is generated by the DocFx, specifically for the API docs. It uses a process similar to the following:

  • Reads a collection NuGet packages
  • Generates XML based on these packages
  • DocFx reads the XML files and then generates static HTML

But that's something that specific to API docs, not the conceptual content that I believe you're referring to. Do you like the format of the extensions, or what exactly are you thinking? Is the idea to generate reference content for extensions and then map their NuGet packages in the table? Also, I assume you're interested in something like this for .NET Aspire?

@captainsafia
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member Author

Choose a reason for hiding this comment

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

@JamesNK Can I get your review on this given your experience implementing completion providers in route tooling?

The goal is to add completions for extension methods defined in a separate package then provide an installation codefix for them.

Copy link
Member

Choose a reason for hiding this comment

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

It's been a minute since my head was in The Roslyn Zone. I'll do my best.


[ExportCompletionProvider(nameof(ExtensionMethodsCompletionProvider), LanguageNames.CSharp)]
[Shared]
public sealed class ExtensionMethodsCompletionProvider : CompletionProvider
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment summarizing what the provider's deal is.

Does it replace completion for known types or are values from the completion provider added to the auto-complete? Replacing auto-complete for some types (if that's how it works) feels pretty invasive.

Copy link
Member Author

Choose a reason for hiding this comment

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

The completion provider is additive (assuming I understand the intent of the context.AddItem method 😅 ) and is intended to augment the completions list with methods that we think might be helpful. I'll add a comment to this effect.

Copy link
Member

@JamesNK JamesNK Jun 14, 2024

Choose a reason for hiding this comment

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

What happens if the value is already present in auto-complete? For example, someone might already have a reference to the OpenAPI package. Do they see the AddOpenApi option from built-in autocomplete and a item from this provider?

Do items added by this provider look the same or different to other items? Could I see a screenshot?


[ExportCompletionProvider(nameof(ExtensionMethodsCompletionProvider), LanguageNames.CSharp)]
[Shared]
public sealed class ExtensionMethodsCompletionProvider : CompletionProvider
Copy link
Member

Choose a reason for hiding this comment

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

So excited! 🥳

@captainsafia captainsafia changed the title Add codefixer to install OpenAPI package from extension methods Add codefixer and completion provider to install OpenAPI package from extension methods Jun 11, 2024
Copy link
Member

@ReubenBond ReubenBond left a comment

Choose a reason for hiding this comment

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

LGTM. One small change suggested

@wtgodbe wtgodbe merged commit e558b05 into main Jun 14, 2024
23 of 26 checks passed
@wtgodbe wtgodbe deleted the safia/openapi-extensions-analyzer branch June 14, 2024 23:04
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview6 milestone Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants