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

Added support for @attribute directive #607

Merged
merged 4 commits into from
May 21, 2019

Conversation

ajaybhargavb
Copy link
Contributor

throw new ArgumentNullException(nameof(builder));
}

builder.AddDirective(Directive, FileKinds.Legacy, FileKinds.Component, FileKinds.ComponentImport);
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 assume we want this to work on non-blazor scenarios as well. I don't see why not.

Copy link
Member

Choose a reason for hiding this comment

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

Yes we do.

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.
Copy link
Contributor

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.

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 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, fair enough.

Copy link
Contributor

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

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

:shipit: once tests be green

@ajaybhargavb
Copy link
Contributor Author

🆙 📅

<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>
Copy link
Member

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.

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 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?

Copy link
Member

Choose a reason for hiding this comment

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

yeah I think so.

@rynowak
Copy link
Member

rynowak commented May 21, 2019

/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>
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same question as above.

@@ -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
Copy link
Member

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 });
}
Copy link
Member

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?

Copy link
Contributor Author

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.

@SteveSandersonMS
Copy link
Member

This was an amazingly quick response, @ajaybhargavb! Nice one :)

@ajaybhargavb
Copy link
Contributor Author

@aspnet/build all checks have passed but the actual required one isn't green. Is this a known issue?

@natemcmaster
Copy link
Contributor

I've seen this on other PRs too. Possible regression in the GitHub integration.

@ajaybhargavb
Copy link
Contributor Author

The workaround is to re-run until it succeeds?

@natemcmaster
Copy link
Contributor

Can you try a re-run just to see if this is a fluke?

@ajaybhargavb
Copy link
Contributor Author

I requested a re-run but nothing seems to be happening.

@natemcmaster
Copy link
Contributor

image

https://status.dev.azure.com/

@ajaybhargavb
Copy link
Contributor Author

@aspnet/build, squash and merge for me please?

@natemcmaster
Copy link
Contributor

@natemcmaster natemcmaster merged commit 67b8a83 into master May 21, 2019
@ghost ghost deleted the ajbaaska/attribute-directive branch May 21, 2019 22:43
@ajaybhargavb
Copy link
Contributor Author

Thanks @natemcmaster

JunTaoLuo pushed a commit to dotnet/aspnetcore that referenced this pull request May 17, 2020
dougbu pushed a commit to dougbu/razor-compiler that referenced this pull request Nov 17, 2021
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.

Add support for @attribute directive
5 participants