-
Notifications
You must be signed in to change notification settings - Fork 198
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
Introduce Extract to Code Behind #2039
Conversation
I switched it to a draft after publishing because I didn't see the option first 😅 |
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.
Overall design looks great! Left a few high level comments. Let us know once you're ready for a more in-depth review 😄
...crosoft.AspNetCore.Razor.LanguageServer/Refactoring/ExtractToCodeBehindCodeActionProvider.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/Refactoring/ExtractToCodeBehindCodeActionProvider.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/Refactoring/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/Refactoring/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/Refactoring/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RazorSyntaxExtensions.cs
Outdated
Show resolved
Hide resolved
It has always been that way. It's super useful for investigating flaky tests on the CI. |
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.
Mostly just nit-picks and stuff that probably gets cleaned up before you leave draft anyway, nothing foundational.
...crosoft.AspNetCore.Razor.LanguageServer/Refactoring/ExtractToCodeBehindCodeActionProvider.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/Refactoring/ExtractToCodeBehindCodeActionProvider.cs
Outdated
Show resolved
Hide resolved
...src/Microsoft.VisualStudio.LanguageServerClient.Razor/HtmlCSharp/DefaultLSPRequestInvoker.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/OOPTagHelperResolver.cs
Outdated
Show resolved
Hide resolved
...or/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/CodeActionEndpointTest.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/CodeActionResolutionEndpointTest.cs
Outdated
Show resolved
Hide resolved
...r/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/ExtractToCodeBehindTest.cs
Outdated
Show resolved
Hide resolved
753524c
to
9fd4ee9
Compare
afeb79e
to
2809fec
Compare
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.
Pretty much all of my comments are code-style nitpicks. The bones of the code look solid.
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
...or/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/CodeActionResolutionEndpoint.cs
Outdated
Show resolved
Hide resolved
...or/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/CodeActionResolutionEndpoint.cs
Outdated
Show resolved
Hide resolved
...or/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/CodeActionResolutionEndpoint.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RazorCodeActionProvider.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RazorCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RazorSyntaxExtensions.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/CodeActions/RazorCodeActionRunner.ts
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/RPC/SerializableWorkspaceEdit.ts
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorCodeActionResolutionParams.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorCodeActionResolutionResponse.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorCodeActionResolutionResponse.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/CodeActions/RazorCodeActionRunner.ts
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/CodeActions/RazorCodeActionRunner.ts
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/CodeActions/RazorCodeActionRunner.ts
Show resolved
Hide resolved
...or/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/CodeActionEndpointTest.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/CodeActionResolutionEndpointTest.cs
Outdated
Show resolved
Hide resolved
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.
Looks really good. I had a few question and mostly minor style comments.
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Constants.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionProvider.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionProvider.cs
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionProvider.cs
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IRazorCodeActionResolutionHandler.cs
Show resolved
Hide resolved
...or/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/RPC/SerializableWorkspaceEdit.ts
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/CodeActions/RazorCodeActionRunner.ts
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionProvider.cs
Show resolved
Hide resolved
private readonly FilePathNormalizer _filePathNormalizer; | ||
private readonly ILogger _logger; | ||
|
||
private static readonly Range StartOfDocumentRange = new Range(new Position(0, 0), new Position(0, 0)); |
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.
private static readonly Range StartOfDocumentRange = new Range(new Position(0, 0), new Position(0, 0)); | |
private static readonly Range StartOfDocumentRange = default; |
?
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
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.
Looks great! 👏
Just some minor comments / changes / formatting.
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
Outdated
Show resolved
Hide resolved
...or/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolutionEndpoint.cs
Outdated
Show resolved
Hide resolved
...or/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolutionEndpoint.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionProvider.cs
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/RPC/SerializableWorkspaceEdit.ts
Show resolved
Hide resolved
...spNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionProviderTest.cs
Show resolved
Hide resolved
...spNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionResolverTest.cs
Outdated
Show resolved
Hide resolved
...spNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionResolverTest.cs
Show resolved
Hide resolved
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.
Only minor comments. Looks super good Noah!
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
Show resolved
Hide resolved
...or/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolutionEndpoint.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionProvider.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/CodeActions/RazorCodeActionRunner.ts
Outdated
Show resolved
Hide resolved
This is still approved by me, but let me know before you merge this. I'm doing a VS insertion and I'm told this PR can't go in with that. |
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.
Looks great 🎉 🍾 . Just minor nits and one question for my own understanding.
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.VSCode/src/RPC/SerializableWorkspaceEdit.ts
Show resolved
Hide resolved
...or/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs
Outdated
Show resolved
Hide resolved
...crosoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs
Outdated
Show resolved
Hide resolved
...spNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionProviderTest.cs
Outdated
Show resolved
Hide resolved
...spNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionResolverTest.cs
Outdated
Show resolved
Hide resolved
...spNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionResolverTest.cs
Outdated
Show resolved
Hide resolved
a87dfc6
to
c6a4401
Compare
c6a4401
to
368d418
Compare
In order to support code action efficiently, this PR's main purpose is to integrate an additional dispatcher into the RZLS framework. Additionally, it contains a 'plugin' of sorts to this framework that handles extracting
@code
blocks from.razor
files into backing C#.I merged with master preemptively to double check compatibility, so please ignore diffs from that.
This PR registers two endpoints with the RZLS. The first is the
CodeActionEndpoint
, which is a part of the O# specifications. This endpoint asks all of its registered providers (right now there is only one for ExtractToCodeBehind, but in general they are dynamically registered asRazorCodeActionProvider
services) if they have any code actions to provide. All providers that apply return a command forrazor/runCodeAction
with params for a custom endpoint.If the user chooses any of the code actions provided this way, the
razor/runCodeAction
is executed by VSCode and a new query is sent to the language server to "resolve" or compute the full set of changes invoked by the aforementioned params. This is handled by theCodeActionResolutionEndpoint
, which passes the data in the params to a correspondingly registeredRazorCodeActionResolver
based on a sharedAction
constant. This returns a serialized WorkspaceEdit, which is applied on the client side.Addresses dotnet/aspnetcore#22239 (in this specific format)