Skip to content

Add CustomTags to CodeAction#51456

Merged
JoeRobich merged 13 commits intodotnet:mainfrom
JoeRobich:add-customtags-to-codeaction
Mar 24, 2021
Merged

Add CustomTags to CodeAction#51456
JoeRobich merged 13 commits intodotnet:mainfrom
JoeRobich:add-customtags-to-codeaction

Conversation

@JoeRobich
Copy link
Member

@JoeRobich JoeRobich commented Feb 24, 2021

Part of the work to support #4919

Adds a CustomTags property to CodeActions which will be included as part of the CodeActionResolveData.

@JoeRobich JoeRobich requested a review from a team as a code owner February 24, 2021 23:47
@ghost ghost added the Area-IDE label Feb 24, 2021
/// <summary>
/// Gets custom tags for the CodeAction.
/// </summary>
public virtual ImmutableArray<string> CustomTags => ImmutableArray<string>.Empty;
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be public?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in the design meeting we decided that we will expose this as a public API, is that correct @jasonmalinowski? Also, if we are exposing this public property, we should also expose new Code.Create overloads that take custom tags argument.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like we discussed this on the 12/7/2020 design meeting; I don't recall the details (and the conclusion from the written notes isn't clear), but my memory matches @mavasani's in that we were OK making a public API like this. Especially since we already have one on Diagnostic and have good experience with it.

@CyrusNajmabadi
Copy link
Contributor

I don't see what code is actually populating this.

@JoeRobich
Copy link
Member Author

I don't see what code is actually populating this.

Yup, that is listed as a todo in the description. Wanted to open this in its current state to get feedback. Updating each provider to set this will take me a bit.

@CyrusNajmabadi
Copy link
Contributor

Can you show a single example? That would be helpful.

@JoeRobich
Copy link
Member Author

Can you show a single example? That would be helpful.

Sure, I welcome ideas on how to do this more efficiently.

 private sealed class MyCodeAction : CustomCodeActions.DocumentChangeAction
 {
     public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
-        : base(CSharpAnalyzersResources.Add_braces, createChangedDocument, CSharpAnalyzersResources.Add_braces)
+        : base(CSharpAnalyzersResources.Add_braces, createChangedDocument, CSharpAnalyzersResources.Add_braces, customTags: ImmutableArray.Create(PredefinedCodeFixProviderNames.AddBraces))
     {
     }
 }

@CyrusNajmabadi
Copy link
Contributor

Sure, I welcome ideas on how to do this more efficiently.

What probably makes more sense is to require CustomCodeActions.DocumentChangeAction (and its peers) to take in the actual provider instance that created them. Then in the base type, just grab whatever data we needed off of that provider and store that in the code action.

@CyrusNajmabadi
Copy link
Contributor

Basically, we would an approach that would force us to remember to do this in all cases. So forcing the clients to always pass in themselves when creating these special code action subclasses would be good way to enforce that.

@JoeRobich
Copy link
Member Author

What probably makes more sense is to require CustomCodeActions.DocumentChangeAction (and its peers) to take in the actual provider instance that created them. Then in the base type, just grab whatever data we needed off of that provider and store that in the code action.

Great idea as most providers already set this in their ExportCodeFixProvider attribute. So glad I opened this PR early. Thanks =)

@CyrusNajmabadi
Copy link
Contributor

I'd also be fine with us just grabbing the type name of provider. That way we can work across all providers.

@JoeRobich
Copy link
Member Author

I'd also be fine with us just grabbing the type name of provider. That way we can work across all providers.

I may do that as a fallback if the Name property isn't set on the attribute. There were concerns about renames breaking partners who may take dependeny on this information.

@CyrusNajmabadi
Copy link
Contributor

There were concerns about renames breaking partners who may take dependeny on this information.

Er... what partners would those be? I would not ever want to make this into a contract. We definitely may change impls/refactor/etc. there.

what are we trying to use this for? If we know that, it can help us drive what an appropriate solution is here.

@TanayParikh
Copy link
Contributor

what are we trying to use this for?

Razor will be using these identifiers to help process Code Actions within the Razor Language Server.

I believe there was also a telemetry use case for this (not sure of the specifics on this though).

Base automatically changed from master to main March 3, 2021 23:53
Copy link
Member Author

Choose a reason for hiding this comment

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

These are not in the same style as previous Names. Would be happy to standardize on either format if requested.

Copy link
Member

Choose a reason for hiding this comment

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

Presumably these aren't displayed anywhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

As in they just use nameof instead spacing? I think it's fine personally. These are not customer facing names, just identifiers for us to use and read.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I figured they weren't displayed anywhere too exciting since they're not localized, but I thought maybe they were possibly shown in a yellow bar, where localization would be annoying, but perhaps spaces were the convention.

@JoeRobich JoeRobich force-pushed the add-customtags-to-codeaction branch from a73b0f6 to c61f64b Compare March 19, 2021 00:18
@JoeRobich JoeRobich force-pushed the add-customtags-to-codeaction branch from db17d9c to b733708 Compare March 19, 2021 20:32
Copy link
Contributor

@TanayParikh TanayParikh left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

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

Requesting changes to clarify behavior in this comment https://github.com/dotnet/roslyn/pull/51456/files#r599268301

Once we decide on that I think everything else looks good

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Auto-approval

@JoeRobich JoeRobich merged commit a02ee4e into dotnet:main Mar 24, 2021
@ghost ghost added this to the Next milestone Mar 24, 2021
@allisonchou allisonchou modified the milestones: Next, 16.10.P2 Mar 29, 2021
@JoeRobich JoeRobich deleted the add-customtags-to-codeaction branch March 14, 2025 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants