-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Syntax API for FileScopedNamespaces #54674
Comments
@CyrusNajmabadi I assume you're good with this api proposal as well? |
Yes i am. |
Why are the common members abstract? |
I think this is a convention of syntax generation--for Lines 9302 to 9336 in 5d28e29
Lines 9181 to 9227 in 5d28e29
If you ctrl+f for "abstract partial class" in the file linked above you'll find that the abstract classes don't declare fields or concrete properties, only the non-abstract subtypes do. I do not know if it would be possible to sometimes push fields into the parent type and de-virtualize some of the properties, for example, but I think it would be a new and separate thing. |
Yup. This is just an affectation of how the generator works. It might be possible to change this, but there hasn't been a need yet |
NotesShape / nestingShould this really be a nesting node, or an independent node. There has been discussion about this in LDM, and the decision was made to represent it this way, so we should keep as it. It matches the 'spirit' of the spec, so seems appropriate. Breaking change?This will break users of the syntax model, but either way we do it they will have to change code, so it doesn't matter either way. There is some evidence from the FXCop analyzers that handling this kind of base class extraction change is fairly painless, so we think its ok. |
Has this been released? In preview mode I am debugging and see |
This has not been released. The issue will be closed when implemented. |
You'll have to reference a recent 4.0.0 version of the Roslyn packages to use the new types in your code. |
@RikkiGibson @333fred has this been addressed by API review? Getting very close to the release now and want to make sure we don't let this slip through |
Yes, this has the api-approved label. It's ready to be implemented. |
Since this is just describing the syntax model for the feature as it was implemented, and the feature has been merged, we're all done here. |
@RikkiGibson Can we close this issue? |
Background and Motivation
The file scoped namespaces feature #49000 introduces new syntax nodes. Those syntax nodes are naturally part of the public API.
Proposed API
Usage Examples
Alternative Designs
We might be able to pack the new syntax into the existing
NamespaceDeclarationSyntax
. However, to do this while maintaining invariants is a bit clumsy, and it more or less violates our guidelines around using the same node to represent two different things.namespace Microsoft.CodeAnalysis.CSharp.Syntax { public sealed partial class NamespaceDeclarationSyntax : MemberDeclarationSyntax { public SyntaxToken NamespaceKeyword { get; } public NameSyntax Name { get; } + public SyntaxToken LeadingSemicolonToken { get; } public SyntaxToken OpenBraceToken { get; } public SyntaxList<ExternAliasDirectiveSyntax> Externs { get; } public SyntaxList<UsingDirectiveSyntax> Usings { get; } public SyntaxList<MemberDeclarationSyntax> Members { get; } public SyntaxToken CloseBraceToken { get; } public SyntaxToken SemicolonToken { get; } } }
Note particularly that this alternative design would require keeping the existing, optional SemicolonToken which trails the closing brace of the namespace, as well as adding a new LeadingSemicolonToken, which precedes the list of externs+usings+members in the namespace.
Risks
If we ship the suggested design, users will have to react by changing their code:
SyntaxKind.NamespaceDeclaration
, they will probably want to look for bothSyntaxKind.NamespaceDeclaration
andSyntaxKind.FileScopedNamespaceDeclaration
NamespaceDeclarationSyntax
, they will probably want to switch toBaseNamespaceDeclarationSyntax
CSharpSyntaxVisitor
, they will probably want to override bothVisit(NamespaceDeclarationSyntax)
andVisit(FileScopedNamespaceDeclarationSyntax)
, likely delegating to the same method for both.However, there are some cases we've spotted internally, like the normalizer and formatter, where we definitely wouldn't want to treat these nodes the same for determining indent depth, for example.
This design also matches some past changes to the syntax design, such as for
RecordDeclaration
orForEachStatement
.The text was updated successfully, but these errors were encountered: