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

Lexically scoped child resources #1516

Merged
merged 1 commit into from
Mar 6, 2021

Conversation

rynowak
Copy link
Contributor

@rynowak rynowak commented Feb 10, 2021

Fixes: #1363

This change add support for lexical scoping/nesting of child resources.
That it, for a resource type: My.RP/someType@2020-01-01 there's now a
simplified syntax for including a resource:
My.RP/someType/childType@2020-01-01 inside the body of the parent.

This syntax also allows simplication of the type name of the child,
limits its scope/visibility and implies an automatic dependsOn to the
parent resource. The goal is to be the most idiomatic way to declare
multiple resources to be deployed with a parent/child/grandchild/etc
relationship.

This also includes the new "nested resource access" operator which
allows lookup of a nested resource:

output someOutput string = parent:child.properties.size

I still need to:

  • Update documentation
  • Add completion for resource keyword inside an ObjectSyntax
  • Make : into a commit character for variables when the completion refers to a resource name
  • Update completion for a nested resource to use a single type segment
  • Add completion for resource access operator
  • Address nesting + for loops by blocking it for now in ForSyntaxValidatorVisitor
  • Look into DeployTimeConstantVisitor
  • Address PR feedback about LanguageExpression instead of syntax
  • Address some issues with failing integration tests

Contributing a feature

  • I have opened a new issue for the proposal, or commented on an existing one, and ensured that the bicep maintainers are good with the design of the feature being implemented
  • I have included "Fixes #{issue_number}" in the PR description, so GitHub can link to the issue and close it when the PR is merged
  • I have appropriate test coverage of my new feature

@rynowak rynowak force-pushed the rynowak/lexical-nesting branch from 8362edc to 9133b4c Compare February 16, 2021 02:44
@codecov-io
Copy link

codecov-io commented Feb 16, 2021

Codecov Report

Merging #1516 (ed21c97) into main (6f2d440) will decrease coverage by 0.17%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1516      +/-   ##
==========================================
- Coverage   95.26%   95.08%   -0.18%     
==========================================
  Files         364      370       +6     
  Lines       20455    21379     +924     
  Branches       15       15              
==========================================
+ Hits        19486    20328     +842     
- Misses        969     1051      +82     
Flag Coverage Δ
dotnet 95.53% <100.00%> (-0.21%) ⬇️
typescript 26.61% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...Tests/Assertions/DiagnosticCollectionExtensions.cs 85.71% <ø> (+2.38%) ⬆️
...ep.Core.UnitTests/Parsing/ExpressionTestVisitor.cs 100.00% <ø> (ø)
src/Bicep.Core.UnitTests/Parsing/ParserTests.cs 100.00% <ø> (ø)
...e.UnitTests/Resource/ResourceTypeReferenceTests.cs 100.00% <ø> (ø)
src/Bicep.Core.UnitTests/Utils/ParserHelper.cs 100.00% <ø> (ø)
src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs 100.00% <ø> (ø)
src/Bicep.Core/Emit/EmitLimitationCalculator.cs 100.00% <ø> (ø)
src/Bicep.Core/Emit/ExpressionConverter.cs 94.65% <ø> (-1.70%) ⬇️
src/Bicep.Core/Emit/ExpressionEmitter.cs 98.72% <ø> (+<0.01%) ⬆️
src/Bicep.Core/Emit/ForSyntaxValidatorVisitor.cs 100.00% <ø> (ø)
... and 83 more

@rynowak rynowak force-pushed the rynowak/lexical-nesting branch from 9133b4c to 46a7009 Compare February 16, 2021 23:22
@rynowak rynowak force-pushed the rynowak/lexical-nesting branch 2 times, most recently from f490edf to 2188cce Compare February 16, 2021 23:54
@rynowak rynowak force-pushed the rynowak/lexical-nesting branch 3 times, most recently from f7a4879 to 6ce2fb2 Compare March 2, 2021 01:29
Copy link
Member

@anthony-c-martin anthony-c-martin left a comment

Choose a reason for hiding this comment

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

Looks great! Just a few minor comments

@majastrz
Copy link
Member

majastrz commented Mar 2, 2021

There's something going on with property access completions. Starting with this file:

resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
  
  resource subnet 'subnets' = {
    name: 'test'
  }

}

resource subnet2 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = {
  
}

output hmm string = subnet2.properties.

output hmmmm string = vnet:subnet.properties.

There's a difference in completions offered. Standalone subnet:
image

Nested subnet:
image

else if (symbol is null || symbol is not ResourceSymbol)
{
// symbol could be null in the case of an incomplete expression during parsing like `a:`
var error = new ErrorSymbol(DiagnosticBuilder.ForPosition(syntax.ResourceName).ResourceRequiredForResourceAccess(symbol?.Kind.ToString() ?? LanguageConstants.ErrorName));
Copy link
Member

Choose a reason for hiding this comment

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

image

Should the error span be on the base expression? The root cause of the error is the fact that the base expression isn't bound to a resource symbol. On the other hand, the squiggle would cover the entire base expression, which could get kind of nasty if the expression is complicated.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what about on the colon? The error in this case is the operator you're using - which doesn't apply to the type on the LHS. Or is that too subtle?

Where would the span be for something like:

var test = 42
var wrong = 42.foo

Copy link
Member

Choose a reason for hiding this comment

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

For the above, we do this:
image

Yeah I think : would be too subtle but it is also one of the possible causes of the error. I guess for consistency we could leave it where it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI what I'm doing here is consistent with property access on a non-object type. I'm going to leave it for now unless there's a strong reason to revisit.

image

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me!

@rynowak rynowak force-pushed the rynowak/lexical-nesting branch 2 times, most recently from 9f20a88 to 51c32ae Compare March 4, 2021 02:09
@rynowak
Copy link
Contributor Author

rynowak commented Mar 4, 2021

There's something going on with property access completions.

Fixed this issue. There was a problem with declared type assignment for resource access. Property completion expects the resource body type, and I was assigning the resource type.

@rynowak
Copy link
Contributor Author

rynowak commented Mar 4, 2021

@anthony-c-martin @majastrz - updated

Copy link
Member

@majastrz majastrz left a comment

Choose a reason for hiding this comment

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

SHIP IT!

@rynowak rynowak force-pushed the rynowak/lexical-nesting branch from b2bce85 to bfc0c44 Compare March 4, 2021 19:55
@rynowak
Copy link
Contributor Author

rynowak commented Mar 4, 2021

@anthony-c-martin @majastrz - know what's up with the failing build? Other than that should be ready to go.

Fixes: Azure#1363

This change add support for lexical scoping/nesting of child resources.
That it, for a resource type: `My.RP/someType@2020-01-01` there's now a
simplified syntax for including a resource:
`My.RP/someType/childType@2020-01-01` inside the body of the parent.

This syntax also allows simplication of the type name of the child,
limits its scope/visibility and implies an automatic `dependsOn` to the
parent resource. The goal is to be the most idiomatic way to declare
multiple resources to be deployed with a parent/child/grandchild/etc
relationship.

This also includes the new "nested resource access" operator which
allows lookup of a nested resource:

```
output someOutput string = parent:child.properties.size
``
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.

Support nested resources with lexical scoping
6 participants