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

Explicitly pass formatting options to Roslyn APIs (via External Access) #6166

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tmat
Copy link
Member

@tmat tmat commented Mar 10, 2022

@tmat
Copy link
Member Author

tmat commented Mar 10, 2022

@davidwengier Does this look reasonable?

@davidwengier
Copy link
Contributor

@allisonchou who did the initial work on formatting options here.

The approach seems fine in general, but perhaps one thing that seems a little inconsistent. On the roslyn side the document is used to get the formatting options, and the syntax root. On the razor side we construct the document but no longer set any formatting options, so it almost seems like maybe we don't need the document at all? Would it be better or worse to just have the razor side pass the syntax root and formatting options only, and remove all of the adhoc workspace and document creation stuff? Unless its used by something else I'm not remembering of course, but we do already have other places in razor where we parse the generated text to get a syntax tree.

@tmat
Copy link
Member Author

tmat commented Mar 10, 2022

, so it almost seems like maybe we don't need the document at all?

The document is needed to get formatting options from editorconfig

@davidwengier
Copy link
Contributor

That works?!

To be clear, I mean the document created in GetCSharpDocument().. the one in the adhoc workspace, with no file path, in the project with no file path, so it's a bit surprising that editorconfig would work at all.

@tmat
Copy link
Member Author

tmat commented Mar 10, 2022

I didn't know there is no file path. Is that true for all the documents from the formatting context? Shouldn't they have file path from DocumentUri sent by the LSP client?

@davidwengier
Copy link
Contributor

At the moment yes.

Razor basically doesn't support editorconfig yet (tracked by #4406) and presumably we need to design what it means (do we honour *.cs settings for code analysis, or *.razor? Presumably *.razor for indentation etc. and we'll need to pass that through to C# for generated code etc.)

@tmat
Copy link
Member Author

tmat commented Mar 11, 2022

OK, so if we don't need to support editorconfig then I can simplify this a bit.
The new options design will make it easy to pass in whatever formatting options Razor decides to use in future.

@tmat
Copy link
Member Author

tmat commented Apr 29, 2022

@davidwengier Should be good to merge now, provided that tests pass.

@davidwengier
Copy link
Contributor

provided that tests pass.

@tmat they did not. Did you mean to bump the Roslyn version or something? The Razor EA is throwing

@DustinCampbell
Copy link
Member

@tmat / @davidwengier: Does this PR need to be resurrected or closed?

# Conflicts:
#	src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormatter.cs
#	src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingLanguageServerClient.cs
#	src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/FormattingTestBase.cs
@davidwengier
Copy link
Contributor

I've merged in latest and fixed the conflicts. I think it still makes sense to take this, for future usage, but I think it needs updating, for sure. @tmat in the last commit you added a parameter to CSharpFormattingPass, but there is no way to satisfy it via DI, so a different approach would be needed.

@maryamariyan
Copy link
Member

As per @davidwengier 's last comment it seems more work is needed to update this PR and we have some file conflicts.

@tmat given that this hasn't been updated for a while, would it make sense to close this PR and reopen once it's updated?

@tmat
Copy link
Member Author

tmat commented Mar 15, 2023

Yes, more work is needed but why not keep the PR open in draft mode?

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.

None yet

4 participants