-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0512fd5
WIP
TanayParikh 02a8da8
Merge branch 'master' into dev/taparik/addCodeActionProviderName
TanayParikh a637d17
Provider, Implementation
TanayParikh b9cdf56
Merge branch 'master' into dev/taparik/addCodeActionProviderName
TanayParikh 3a09488
Merge branch 'master' into dev/taparik/addCodeActionProviderName
TanayParikh a52b3c0
Feedback
TanayParikh f477ac0
Fix missing func
TanayParikh 337d594
Merge branch 'master' into dev/taparik/addCodeActionProviderName
TanayParikh a16be50
WIP
TanayParikh d47cd0b
Merge branch 'master' into dev/taparik/addCodeActionProviderName
TanayParikh c109013
External Access
TanayParikh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Tools/ExternalAccess/Razor/RazorPredefinedCodeFixProviderNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// 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.CodeFixes; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor | ||
{ | ||
internal static class CSharpPredefinedCodefixProviderNames | ||
{ | ||
public static string ImplementAbstractClass => PredefinedCodeFixProviderNames.ImplementAbstractClass; | ||
public static string ImplementInterface => PredefinedCodeFixProviderNames.ImplementInterface; | ||
public static string SpellCheck => PredefinedCodeFixProviderNames.SpellCheck; | ||
public static string FullyQualify => PredefinedCodeFixProviderNames.FullyQualify; | ||
public static string AddImport => PredefinedCodeFixProviderNames.AddImport; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Tools/ExternalAccess/Razor/RazorPredefinedCodeRefactoringProviderNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// 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.CodeRefactorings; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor | ||
{ | ||
internal static class CSharpPredefinedCodeRefactoringProviderNames | ||
{ | ||
public static string AddAwait => PredefinedCodeRefactoringProviderNames.AddAwait; | ||
public static string GenerateConstructorFromMembers => PredefinedCodeRefactoringProviderNames.GenerateConstructorFromMembers; | ||
public static string GenerateDefaultConstructors => PredefinedCodeRefactoringProviderNames.GenerateDefaultConstructors; | ||
public static string GenerateEqualsAndGetHashCodeFromMembers => PredefinedCodeRefactoringProviderNames.GenerateEqualsAndGetHashCodeFromMembers; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,14 @@ public abstract class CodeAction | |
/// </remarks> | ||
public virtual string? EquivalenceKey => null; | ||
|
||
/// <summary> | ||
/// Identifies the Code Action Provider which produced this Code Action. | ||
/// </summary> | ||
/// <remarks> | ||
/// e.g. 'Add Await Code Action Provider' | ||
/// </remarks> | ||
internal virtual string? ProviderName => null; | ||
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. We may want to consider exposing this property as a public API - this is something that can be made part of the code action telemetry and we can resolve the long outstanding issue #4919. @allisonchou do you mind bringing it to the design meeting? |
||
|
||
internal virtual bool IsInlinable => false; | ||
|
||
internal virtual CodeActionPriority Priority => CodeActionPriority.Medium; | ||
|
@@ -358,14 +366,16 @@ public static CodeAction Create(string title, ImmutableArray<CodeAction> nestedA | |
|
||
internal abstract class SimpleCodeAction : CodeAction | ||
{ | ||
public SimpleCodeAction(string title, string? equivalenceKey) | ||
public SimpleCodeAction(string title, string? equivalenceKey, string? providerName = null) | ||
{ | ||
Title = title; | ||
EquivalenceKey = equivalenceKey; | ||
ProviderName = providerName; | ||
} | ||
|
||
public sealed override string Title { get; } | ||
public sealed override string? EquivalenceKey { get; } | ||
internal sealed override string? ProviderName { get; } | ||
} | ||
|
||
internal class CodeActionWithNestedActions : SimpleCodeAction | ||
|
@@ -410,8 +420,8 @@ internal class DocumentChangeAction : SimpleCodeAction | |
{ | ||
private readonly Func<CancellationToken, Task<Document>> _createChangedDocument; | ||
|
||
public DocumentChangeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument, string? equivalenceKey = null) | ||
: base(title, equivalenceKey) | ||
public DocumentChangeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument, string? equivalenceKey = null, string? providerName = null) | ||
: base(title, equivalenceKey, providerName) | ||
{ | ||
_createChangedDocument = createChangedDocument; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Needs to be added to published API.
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 don't think we need the
ProviderName
property in this file actually. The properties inCodeActionResolveData
are just used to carry over necessary information from ourCodeActionHandler
class to ourCodeActionResolveHandler
class. SinceCodeActionHandler
is the class that tells LSP what code actions are available, I don't think we need to carry over theProviderName
information to the resolve handler, since all the resolve handler does is populate the code action edits.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.
Wouldn't we need this property here to ensure the
CodeAction.Data
payload actually carries the provider name?In-between Razor get's the
CodeActionResolveData
and that's where I was intending to inspect the payload to consume the ProviderName. Is there a better way to ensure razor get's the provider name?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.
I might be misunderstanding how things work here. Could you explain what Razor is doing in between Roslyn's
CodeActionsHandler
andCodeActionResolveHandler
?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
CodeActionsHandler
. Roslyn would then filter code actions based on these provider names, and only return back a filtered set of code actions. Later, Roslyn would get code action resolve requests for each of the filtered code actions, and then would populate these code actions with the edit data.^Is this correct? Please feel free to correct me if not.
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.
textDocument/codeAction
request to the RoslynCodeActionsHandler
.CodeAction.CodeActionResolveData
with theProviderName
property.CodeAction.CodeActionResolveData.ProviderName
to identify the code action, determine whether or not it is supported, and take the appropriate action to display it to the user in a razor compatible manner.textDocument/codeActionResolve
request to Roslyn'sCodeActionResolveHandler
with the initialCodeAction.CodeActionResolveData
.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
CodeActionResolveData
payload does not as the spec just specifies anobject Data;
. The goal of this PR was to take the approach steps detailed above. I hope that helps clarify things, let me know if there are any other questions :)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.
That was a great explanation, thank you! In that case, yeah, I definitely think the data payload needs the provider name.