-
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
Stop allowing FileKind to be set on a RazorCodeDocument independently from the RazorParserOptions #11612
Conversation
Move the GetFileKind and SetFileKind extension methods to RazorCodeDocument and make them instance methods backed by a simple field.
Add a RazorParserOptions.Create(...) convenience factory method to make it easier to create RazorParserOptions with different RazorLanguageVersion and FileKind values.
RazorCodeDocument already exposes ParserOptions.FileKind, so a separate mechanism for getting and setting the file kind is both unneeded and a potential source of bugs. Most of the changes are in tooling tests, which have unfortunately proliferated a bit of an anti-pattern for constructing code documents through copy-paste. I'll take a look at cleaning that up in a follow-up pull request. This change tries to keep test clean up to a minimum.
This is a purely mechanical change that makes the RazorCodeDocument.GetFileKind() a readonly, computed property that delegates to ParserOptions.FileKind.
This property is unused and it is less error-prone to only define it in a single place, i.e. RazorParserOptions.
There's just one use of RazorCodeGenerationOptions.Builder.LanguageVersion blocking its removal, and it can easily be removed.
This property is unused and it is less error-prone to only define it in a single place, i.e. RazorParserOptions.
For consistency with RazorParserOptions, add a RazorCodeGenerationOptions.Create(...) convenience factory method to make it easier to create new RazorCodeGenerationOptions.
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.
Compiler changes LGTM
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorCodeDocumentExtensionsTest.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.
tooling LGTM
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 one way to skin a cat? How can anyone work in these conditions!
There are two extension methods targeting
RazorCodeDocument
that allow consumers to set or get the file kind for the document. However, this can result in inconsistencies because that file kind value (stored inRazorCodeDocument.Items
) is independent fromRazorCodeDocument.ParserOptions.FileKind
. This PR removes both methods in favorRazorParserOptions.FileKind
.Summary of changes:
GetFileKind()
andSetFileKind(...)
extension methods and expose a convenienceRazorCodeDocument.FileKind
property that delegates toParserOptions.FileKind
.RazorParserOptions.Create(...)
andRazorCodeGenerationOptions.Create(...)
convenience factory methods.LanguageVersion
andFileKind
fromRazorCodeGenerationOptions
to avoid the possibility of aRazorCodeDocument
containing parser options and code generation options that disagree about these values.SetFileKind(...)
and pass the value as part ofRazorCodeDocument
creation.Note
GetFileKind()
andSetFileKind(...)
are public extension methods but are not used by the RazorSdk, so they should be safe to remove.