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

Fix OmniSharp formatting issue #8669

Merged
merged 6 commits into from
May 8, 2023

Conversation

davidwengier
Copy link
Contributor

Fixes dotnet/vscode-csharp#5561

Took the opportunity to clean up some of this, because it was a bit odd. Have left comments in the PR to explain what the changes are.

@davidwengier davidwengier requested a review from a team as a code owner May 4, 2023 07:26
Comment on lines -32 to -34
public const string RazorDocumentFormattingEndpoint = "textDocument/formatting";

public const string RazorDocumentOnTypeFormattingEndpoint = "textDocument/onTypeFormatting";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were using the per-spec LSP methods, but for internal comms between our language servers. Bad mojo. This is where I started because I assumed this would be the issue, but I was totally wrong, but figured it was still good to fix this. Most of the changes are due to this clean up :)

@@ -5,32 +5,28 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common;

internal static class RazorLanguageServerCustomMessageTargets
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided to re-org this file, so we can track how we're going on the path to single server everywhere. Further along than I thought!

Comment on lines -182 to -184
// Our OnTypeFormatter doesn't do anything at the moment, but it's needed so
// VS Code doesn't throw an exception when it tries to send us an
// OnTypeFormatting request.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our on type formatter now does do something, but also I wasn't getting any actual hits on breakpoints in it, so not sure what is going on here. Still investigating this.

Copy link
Contributor Author

@davidwengier davidwengier May 5, 2023

Choose a reason for hiding this comment

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

Okay, this was just the big "do on type formatting" setting in VS Code. With that on, this works, though VS Code didn't want to send back any edits, but I think its probably better to just leave this in place, should they start. The server should handle the edits fine.

@@ -254,63 +254,6 @@ public override async Task<RazorDocumentRangeFormattingResponse> HtmlOnTypeForma
return response;
}

public override async Task<RazorDocumentRangeFormattingResponse> RazorRangeFormattingAsync(RazorDocumentRangeFormattingParams request, CancellationToken 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.

We moved away from range formatting ages ago, but this was never cleaned up. Nothing ever called this

@davidwengier
Copy link
Contributor Author

davidwengier commented May 4, 2023

Just had a thought. @allisonchou is it better to do this sort of thing as two PRs, one for the server, one for the extension, so I can also bump version numbers or something? Or is the version number stuff all in the O# repo?

Copy link
Contributor

@allisonchou allisonchou left a comment

Choose a reason for hiding this comment

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

🎉 !!!

Just had a thought. @allisonchou is it better to do this sort of thing as two PRs, one for the server, one for the extension, so I can also bump version numbers or something? Or is the version number stuff all in the O# repo?

The version numbers are in the O# repo so we should be good here

@@ -38,6 +49,12 @@ export class FormattingHandler {
return this.emptyFormattingResponse;
}

const textDocument = await vscode.workspace.openTextDocument(razorDocumentUri);
Copy link
Contributor

@allisonchou allisonchou May 5, 2023

Choose a reason for hiding this comment

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

Also, is this line needed? I think documentManager.getDocument already opens the document for us

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not actually needing the document opening part of this, but this was the only API I could find that gave me a TextDocument I needed to call the document synchronizer. If there is another/better way to do this, I'm all ears. I copied this from another PR I had, which I'm unable to link to, so could be a few spots to update if there is a better one.


const serializableTextEdit = convertTextEditToSerializable(textEdit);
serializableTextEdits.push(serializableTextEdit);
const textDocument = await vscode.workspace.openTextDocument(razorDocumentUri);
Copy link
Contributor

Choose a reason for hiding this comment

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

(same question here as above)

Copy link
Contributor

@allisonchou allisonchou left a comment

Choose a reason for hiding this comment

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

(Resolved concerns offline with David)

@davidwengier davidwengier merged commit e696ba1 into dotnet:main May 8, 2023
@davidwengier davidwengier deleted the OmniSharpFormatting branch May 8, 2023 21:35
dibarbet pushed a commit to dibarbet/vscode-csharp that referenced this pull request Jun 8, 2023
This is the Blue/Green version of dotnet/razor#8669. I literally just copied the code over from one repo to the other. Also testsed in Blue because I couldn't test in O# locally for some reason.

Fixes dotnet#5561 for Blue/Green
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.

Formatting Razor File errors with "Request textDocument/formatting failed"
3 participants