Closed RikkiGibson closed 2 years ago
@CyrusNajmabadi I assume you're good with this api proposal as well?
Yes i am.
Why are the common members abstract?
Why are the common members abstract?
I think this is a convention of syntax generation--for <Field>
s underneath <AbstractNode>
s in Syntax.xml, we produce only abstract properties. For situations where the subtypes of the abstract node have different numbers of child nodes, it probably helps us generate the implementation per our conventions--calling into GetRed with the right slot and so on.
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
Should 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.
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 FileScopeNamespaceDeclarationSyntax
, but I cannot reference it or its base class in my code...
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
@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.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
.