-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[DRAFT] Add Code Action Provider Name to CodeAction.Data #48951
Changes from 3 commits
0512fd5
02a8da8
a637d17
b9cdf56
3a09488
a52b3c0
f477ac0
337d594
a16be50
d47cd0b
c109013
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 |
---|---|---|
|
@@ -25,13 +25,24 @@ internal class CodeActionResolveData | |
/// </remarks> | ||
public string UniqueIdentifier { get; } | ||
|
||
/// <summary> | ||
/// Identifies the Code Action Provider which produced this Code Action. | ||
/// </summary> | ||
/// <remarks> | ||
/// The unique identifier is currently set as: | ||
/// name of top level code action provider + '|' + name of code action provider implementation | ||
/// e.g. 'Add Await Code Action Provider | GetTitleWithConfigureAwait' | ||
/// </remarks> | ||
public string ProviderName { get; } | ||
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. Needs to be added to published API. 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. Ah, I don't think we need the 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. Wouldn't we need this property here to ensure the
In-between Razor get's the 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 might be misunderstanding how things work here. Could you explain what Razor is doing in between Roslyn's My initial impression was that per our conversation with Miguel, Razor would provide Roslyn with a list ProviderNames through a custom property to Roslyn's 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.
This was definitely one of the proposals we were discussing, but we ended up deciding against it for now in the interest of simplicity and reduce coupling. This also required potential LSP Spec changes, whereas annotating the 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. That was a great explanation, thank you! In that case, yeah, I definitely think the data payload needs the provider name. |
||
|
||
public LSP.Range Range { get; } | ||
|
||
public LSP.TextDocumentIdentifier TextDocument { get; } | ||
|
||
public CodeActionResolveData(string uniqueIdentifier, LSP.Range range, LSP.TextDocumentIdentifier textDocument) | ||
public CodeActionResolveData(string uniqueIdentifier, string providerName, LSP.Range range, LSP.TextDocumentIdentifier textDocument) | ||
{ | ||
UniqueIdentifier = uniqueIdentifier; | ||
ProviderName = providerName; | ||
Range = range; | ||
TextDocument = textDocument; | ||
} | ||
|
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.
Mirroring format of above
UniqueIdentifier
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.
GetTitleWithConfigureAwait
is localized, which I believe would likely be problematic if Razor is trying to avoid localization issues.I'm wondering if ProviderName can simply be made up of PredefinedCodeFixProviderNames and PredefinedCodeRefactoringProviderNames?
This would mean that you wouldn't be able to filter out specific code actions from a provider, but it would be simpler and would avoid localization issues.
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.
Note; we're doing
nameof(GetTitleWithConfigureAwait)
not using the result of the call.It appears the method name isn't localized, however the resource value is. In that case would we still run into localization issues?
With regard to making things simpler, I agree removing it would reduce the complexity. Would you prefer that approach?
My reasoning for specifying the implementation was, there may be cases where Razor may support one implementation of a provider, but not another. Granted, no specific example jumps out at me right now so this may be premature.
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.
Oh whoops, my bad, I totally missed that. 😅 Yeah, I don't think using
nameof
should have any localization issues.In general, I do think the simpler approach would definitely be more ideal if that works for Razor. I don't think every code action provider will have something similar to
GetTitleWithConfigureAwait
, for example the Add Parameter code fix provider seems to have different logic for displaying their code actions.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.
Makes sense, thanks for the clarification! Will remove the implementation from the ProviderName.
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.
You will need to define helper types say,
RazorPredefinedCodeRefactoringProviderNames
andRazorPredefinedCodeFixProviderNames
with constant string fields that forward to the internal typesPredefinedCodeRefactoringProviderNames
andPredefinedCodeFixProviderNames
respectively. Something similar to https://github.com/dotnet/roslyn/blob/master/src/Tools/ExternalAccess/FSharp/Diagnostics/FSharpIDEDiagnosticIds.cs. I presume the new files will go https://github.com/dotnet/roslyn/tree/master/src/Tools/ExternalAccess/Razor?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.
What's the difference in the code (refactoring/fix) providers in the
PredefinedCodeRefactoringProviderNames
andPredefinedCodeFixProviderNames
and something like theAdd Null Checks
code action we have both theAddNullChecksId
(private field) as well as the Add Null Checks Feature Resource?Ie. For the Razor external access, should the private
AddNullChecksId
be used or theFeatureResources
?@mavasani
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.
For Razor external access, can just the
PredefinedCodeRefactoringProviderNames
andPredefinedCodeFixProviderNames
be exposed? I guess I'm not understanding whyAddNullChecksId
orFeatureResources
might be necessary to expose. For example, forAddNullChecksId
, is Razor able to simply use the overarchingPredefinedCodeRefactoringProviderNames.GenerateConstructorFromMembers
?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.
Ah, I wasn't aware that
AddNullChecks
would be a part of theGenerateConstructorFromMembers
. I tried annotating the associated abstract classes ofGenerateConstructorFromMembers
but that didn't actually annotate theAdd Null Check
CodeAction.Data payload with the expected provider name. Is there a specific (inherited) code action I may have missed annotating?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.
Ah, wait. The "Add null checks" feature resource you linked isn't actually its own separate code action, I believe it's just part of the Generate constructor dialog (see number 4 image at https://docs.microsoft.com/en-us/visualstudio/ide/reference/generate-constructor?view=vs-2019).
Sorry, didn't catch that before. It might also be important to note that Roslyn currently filters out any code actions with dialogs/options in LSP, since LSP currently doesn't support them.
When you say you want "Add null check" code action, are you possibly thinking of the action associated with the AbstractAddParameterCheckCodeRefactoringProvider? http://sourceroslyn.io/#Microsoft.CodeAnalysis.Features/InitializeParameter/AbstractAddParameterCheckCodeRefactoringProvider.cs,96