-
Notifications
You must be signed in to change notification settings - Fork 724
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
Block calls to scope functions in .biecpparam
files
#11903
Conversation
Test this change out locally with the following install scripts (Action run 6264671957) VSCode
Azure CLI
|
@@ -348,6 +337,17 @@ private static IEnumerable<FunctionOverload> GetAzOverloads(ResourceScope resour | |||
} | |||
else | |||
{ | |||
foreach (var (functionOverload, allowedScopes) in GetScopeFunctions()) |
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'm not suggesting you make this change now (more interested in just getting your thoughts on it), but in the long run, I've been wondering if it would be less error-prone (and possibly better user experience) to have a "usage" property on the function overload - e.g.:
new FunctionOverloadBuilder("resourceGroup")
.WithReturnResultBuilder(GetResourceGroupReturnResult, new ResourceGroupScopeType(Enumerable.Empty<FunctionArgumentSyntax>(), Enumerable.Empty<TypeProperty>()))
.WithGenericDescription(resourceGroupGenericDescription)
.WithDescription("Returns the current resource group scope.")
.WithPermittedUsage(FunctionUsage.BicepFileOnly)
// or .WithPermittedUsage(Usage.BicepParamsFileOnly)
.Build(),
AFAIK we already have a similar capability to restrict the usage of getSecret()
which we might be able to generalize more.
It also feels like it would generally be useful to shift in the direction of separating out "static" namespace functionality, rather than throwing away and rebuilding the namespace on every keypress (when profiling the LS, I this appeared to be one of the most expensive operations we do). Conceptually it's a bit weird that there are multiple different definitions of the namespace, depending on the Bicep file or e.g. targetScope
declarations.
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.
That approach makes sense to me, but we should be able to hold on to copies of static namespace types across compilations even with the current approach. Feature-flagged and file format-specific functionality will vary by path, but we would only need to rebuild namespace types in the LS if a bicepconfig.json
file were added or modified.
If we wanted to just hold onto a singleton, I think we would need to add a .WithRequiredFeatures(Func<IFeatureProvider, bool> predicate)
method in addition to .WithPermittedUsage(FunctionUsage usage)
.
Thanks for fixing this! |
0de3b56
to
198ac50
Compare
Resolves #11902
The error message currently shown when a scope function is used in a .bicepparam file is unhelpful. These functions should only be defined in
.bicep
files so that template authors get actionable error messages if they try to use one.Microsoft Reviewers: Open in CodeFlow