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

Cohost code actions #11147

Merged
merged 23 commits into from
Nov 7, 2024

Conversation

davidwengier
Copy link
Contributor

Fixes #10742
Needs dotnet/roslyn#75711 before it will build
Also will need to merge in main once #11141 is merged

@davidwengier davidwengier requested a review from a team as a code owner November 4, 2024 05:20
@davidwengier davidwengier requested a review from a team as a code owner November 5, 2024 05:32
@davidwengier
Copy link
Contributor Author

Merged main and bumped to a real Roslyn build, so this is ready for review

@davidwengier davidwengier removed the request for review from a team November 5, 2024 05:32
@davidwengier
Copy link
Contributor Author

davidwengier commented Nov 5, 2024

@dotnet/razor-compiler Your Microsoft.AspNetCore.Razor.Language.Legacy.CSharpStatementTest.SwitchStatement_ListPattern test failed, I'm guessing due to some change in Roslyn this is bringing in inadvertently? Is this expected? Should I just regen the baselines?

@jjonescz
Copy link
Member

jjonescz commented Nov 5, 2024

@dotnet/razor-compiler Your Microsoft.AspNetCore.Razor.Language.Legacy.CSharpStatementTest.SwitchStatement_ListPattern test failed, I'm guessing due to some change in Roslyn this is bringing in inadvertently? Is this expected? Should I just regen the baselines?

Please try regenerating the baseline so we can see the diff, it's not very clear from the test results

@davidwengier
Copy link
Contributor Author

Please try regenerating the baseline so we can see the diff, it's not very clear from the test results

Spread changed to two dots? Seems odd to me, but not necessarily anything to worry about I suppose: https://github.com/dotnet/razor/pull/11147/files#diff-77d4727ed03808a308baf4eb6f7861529d0a9d23e86b2b51dda9eb9d719b62bd

@@ -23,7 +23,8 @@
Keyword;[case];
Whitespace;[ ];
LeftBracket;[[];
CSharpOperator;[..];
Dot;[.];
Dot;[.];
Copy link
Member

Choose a reason for hiding this comment

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

Looks like result of dotnet/roslyn#75549.

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

Looks very good!

Copy link
Member

Choose a reason for hiding this comment

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

This file looks super cool. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ehh, it's okay. I don't like that we have to just manually make sure this matches everything in the LSP server DI container.

Comment on lines 25 to 33
public async Task<string?> GetFormattedNewFileContentsAsync(IProjectSnapshot projectSnapshot, Uri csharpFileUri, string newFileContent, CancellationToken cancellationToken)
{
Debug.Assert(projectSnapshot is RemoteProjectSnapshot);
var project = ((RemoteProjectSnapshot)projectSnapshot).Project;

var document = project.AddDocument(RazorUri.GetDocumentFilePathFromUri(csharpFileUri), newFileContent);

return await ExternalHandlers.CodeActions.GetFormattedNewFileContentAsync(document, cancellationToken).ConfigureAwait(false);
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider not creating a new async state machine.

Suggested change
public async Task<string?> GetFormattedNewFileContentsAsync(IProjectSnapshot projectSnapshot, Uri csharpFileUri, string newFileContent, CancellationToken cancellationToken)
{
Debug.Assert(projectSnapshot is RemoteProjectSnapshot);
var project = ((RemoteProjectSnapshot)projectSnapshot).Project;
var document = project.AddDocument(RazorUri.GetDocumentFilePathFromUri(csharpFileUri), newFileContent);
return await ExternalHandlers.CodeActions.GetFormattedNewFileContentAsync(document, cancellationToken).ConfigureAwait(false);
}
public Task<string?> GetFormattedNewFileContentsAsync(IProjectSnapshot projectSnapshot, Uri csharpFileUri, string newFileContent, CancellationToken cancellationToken)
{
Debug.Assert(projectSnapshot is RemoteProjectSnapshot);
var project = ((RemoteProjectSnapshot)projectSnapshot).Project;
var document = project.AddDocument(RazorUri.GetDocumentFilePathFromUri(csharpFileUri), newFileContent);
return ExternalHandlers.CodeActions.GetFormattedNewFileContentAsync(document, cancellationToken);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, but I need to employ a ! because the Roslyn method returns Task<string>, so its not pretty. Unless I'm forgetting some other way to avoid the nullability compiler warning?

Copy link
Member

@DustinCampbell DustinCampbell Nov 6, 2024

Choose a reason for hiding this comment

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

Ahhh... I see. Yeah, that's unfortunate. However, if the Roslyn method returns a Task<string>, why does this return a Task<string?>? It doesn't look to me like this method can return null. Or, is the Roslyn method not annotated correctly? Or, can this also return a Task<string>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the non-cohost impl. It makes an LSP call, so can always be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had a shower thought, I can make this non-nullable by moving the bit that handles null into the non-cohost impl. Thank you for the brain spark :D

@davidwengier
Copy link
Contributor Author

@dotnet/razor-compiler for second sign off on test baseline changes

@jjonescz
Copy link
Member

jjonescz commented Nov 7, 2024

@dotnet/razor-compiler for second sign off on test baseline changes

Test changes should be good to go with just one sign off.

@davidwengier davidwengier merged commit 40d2a6f into dotnet:main Nov 7, 2024
12 checks passed
@davidwengier davidwengier deleted the dev/dawengie/CodeActionsPart5 branch November 7, 2024 11:22
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Nov 7, 2024
@jjonescz jjonescz modified the milestones: Next, 17.13 P2 Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port CodeActions endpoints to cohosting
3 participants