-
Notifications
You must be signed in to change notification settings - Fork 195
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
Added support for @attribute directive #607
Conversation
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
builder.AddDirective(Directive, FileKinds.Legacy, FileKinds.Component, FileKinds.ComponentImport); |
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.
I assume we want this to work on non-blazor scenarios as well. I don't see why not.
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.
Yes we do.
src/Razor/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs
Outdated
Show resolved
Hide resolved
if (tokenKind == DirectiveTokenKind.Attribute) | ||
{ | ||
// We don't need to do anything special here. | ||
// We let the Roslyn take care of providing syntax errors for C# attributes. |
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.
This means you get 0 C# completion for attributes that don't make it into the generated C#. In practice we don't have to worry about this because our @attribute
directive always gets represented in codegen; however, given that you added this to the extensible directive system anyone else extending is not guaranteed to have proper DesignTime bits generated for them.
Can you think of any way to include extensible directive attributes at this layer to ensure C# mappings are generated? If not I don't want to rat hole because in practice almost no one extends this portion of the Razor system; however, if it's easily addable It'd be worth doing.
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.
I can't think of a simple way of doing this correctly. Because if I create a dummy class and put it on top of this, it might show have usage errors depending on the AttributeUsage
of that attribute.
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.
Alright, fair enough.
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.
once tests be green
3094cd5
to
a4f7a53
Compare
🆙 📅 |
<value>Attribute</value> | ||
</data> | ||
<data name="AttributeDirective_Description" xml:space="preserve"> | ||
<value>Specifies the C# attribute that will be applied to the current document.</value> |
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.
This should say that it applies to the generated class.
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.
I said document because that is what we say for @implements
directive which also applies to the class. Should we change that to say class as well?
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.
yeah I think so.
/cc @SteveSandersonMS also @DamianEdwards who has been wanting this for some time 😁 |
<value>Attribute</value> | ||
</data> | ||
<data name="AttributeDirective_Description" xml:space="preserve"> | ||
<value>Specifies the C# attribute that will be applied to the current document.</value> |
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.
This should say that it applies to the generated class. I think it's important to specifcially say that it goes on the class, even those that's obvious to us.
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.
Same question as above.
src/Razor/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs
Outdated
Show resolved
Hide resolved
@@ -19,7 +19,7 @@ RazorDocument - [0..22)::22 - [@{LF @DateTime..LF}] | |||
Transition;[@]; | |||
CSharpImplicitExpressionBody - [9..19)::10 | |||
CSharpCodeBlock - [9..19)::10 | |||
CSharpExpressionLiteral - [9..19)::10 - [DateTime..] - Gen<Expr> - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[ATD];K21 | |||
CSharpExpressionLiteral - [9..19)::10 - [DateTime..] - Gen<Expr> - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[ATD];K22 |
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.
It's really annoything that these numbers show up in the diffs. Next time this comes up we should nuke that from orbit.
// Act & Assert | ||
ParseDocumentTest("@custom Serializable]", | ||
new[] { descriptor }); | ||
} |
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.
What tests do we need for error cases?
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.
Not sure what you mean. It creates a diag.txt
with the error.
This was an amazingly quick response, @ajaybhargavb! Nice one :) |
3e67f0f
to
3be9d08
Compare
@aspnet/build all checks have passed but the actual required one isn't green. Is this a known issue? |
I've seen this on other PRs too. Possible regression in the GitHub integration. |
The workaround is to re-run until it succeeds? |
Can you try a re-run just to see if this is a fluke? |
I requested a re-run but nothing seems to be happening. |
@aspnet/build, squash and merge for me please? |
Overriding GitHub requirements due to https://developercommunity.visualstudio.com/content/problem/576899/github-pull-request-does-not-report-a-check-for-th.html and merging. |
Thanks @natemcmaster |
\n\nCommit migrated from dotnet/razor@67b8a83
\n\nCommit migrated from dotnet/razor@67b8a83 Commit migrated from dotnet/aspnetcore@72d017cc1b8e
Fixes dotnet/aspnetcore#10393