Skip to content

Commit

Permalink
Remove the block on Bicep parameters files (Azure#10191)
Browse files Browse the repository at this point in the history
* Remove the block on Bicep parameters files

* Fix tests
  • Loading branch information
anthony-c-martin committed Mar 24, 2023
1 parent 2a92166 commit f1c10aa
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 77 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ jobs:
run: npm ci
working-directory: ./src/vscode-bicep

# we don't run this step on official builds
- name: Enable params
run: npm run params
working-directory: ./src/vscode-bicep

- name: Run lint
run: npm run lint
working-directory: ./src/vscode-bicep
Expand Down
8 changes: 4 additions & 4 deletions src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Bicep.Cli.IntegrationTests
{

[TestClass]
public class BuildParamsComa : TestBase
public class BuildParamsCommandTests : TestBase
{

[NotNull]
Expand All @@ -38,7 +38,7 @@ public async Task Build_Params_Without_Feature_Flag_Disabled_ShouldFail_WithExpe

result.Should().Be(1);
output.Should().BeEmpty();
error.Should().Contain($"The specified input \"{bicepparamsPath}\" could not be compiled. Compilation of files with extension .bicepparam is only supported if experimental feature \"{nameof(ExperimentalFeaturesEnabled.ParamsFiles)}\" is enabled.");
error.Should().Contain($"{bicepparamsPath}(1,1) : Error BCP336: Using a Bicep Parameters file requires enabling EXPERIMENTAL feature \"{nameof(ExperimentalFeaturesEnabled.ParamsFiles)}\". [https://aka.ms/bicep/config]");
}

[TestMethod]
Expand Down Expand Up @@ -114,7 +114,7 @@ public async Task Build_Params_Bicep_File_Reference_Mismatch_And_Other_Diagnosti

var(output, error, result) = await Bicep(settings, "build-params", bicepparamsPath,"--bicep-file", otherBicepPath, "--outfile", outputFilePath);

var diagnostics = await GetAllParamDiagnostics(bicepparamsPath, BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var diagnostics = await GetAllParamDiagnostics(bicepparamsPath);

result.Should().Be(1);
output.Should().BeEmpty();
Expand Down Expand Up @@ -181,7 +181,7 @@ public async Task Build_Invalid_Single_Params_File_ShouldFail_WithExpectedErrorM
var data = baselineData.GetData(TestContext);

var settings = new InvocationSettings(new(TestContext, ParamsFilesEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var diagnostics = await GetAllParamDiagnostics(data.Parameters.OutputFilePath, BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var diagnostics = await GetAllParamDiagnostics(data.Parameters.OutputFilePath);

var (output, error, result) = await Bicep(settings, "build-params", data.Parameters.OutputFilePath, "--bicep-file", data.Bicep.OutputFilePath);

Expand Down
6 changes: 4 additions & 2 deletions src/Bicep.Cli.IntegrationTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ protected static async Task<IEnumerable<string>> GetAllDiagnostics(string bicepF
return output;
}

protected static async Task<IEnumerable<string>> GetAllParamDiagnostics(string paramFilePath, IContainerRegistryClientFactory clientFactory, ITemplateSpecRepositoryFactory templateSpecRepositoryFactory)
protected static async Task<IEnumerable<string>> GetAllParamDiagnostics(string paramFilePath)
{
var compilation = await CreateCompiler(clientFactory, templateSpecRepositoryFactory).CreateCompilation(PathHelper.FilePathToFileUrl(paramFilePath));
var compiler = new ServiceBuilder().WithEmptyAzResources().WithFeatureOverrides(new(ParamsFilesEnabled: true)).Build().GetCompiler();

var compilation = await compiler.CreateCompilation(PathHelper.FilePathToFileUrl(paramFilePath));

var semanticModel = compilation.GetEntrypointSemanticModel();

Expand Down
9 changes: 0 additions & 9 deletions src/Bicep.Cli/CliResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/Bicep.Cli/CliResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,4 @@
<value>The specified input "{0}" was not recognized as a bicep file. Bicep files must use the .bicep extension.</value>
<comment>{0} input file path</comment>
</data>
<data name="UnableToCompileParamsFile" xml:space="preserve">
<value>The specified input "{0}" could not be compiled. Compilation of files with extension .bicepparam is only supported if experimental feature "{1}" is enabled.</value>
<comment>{0} input file path {1} feature name</comment>
</data>
</root>
6 changes: 0 additions & 6 deletions src/Bicep.Cli/Commands/BuildParamsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ public async Task<int> RunAsync(BuildParamsArguments args)
throw new CommandLineException($"{bicepFileArgPath} is not a bicep file");
}

if(!features.ParamsFilesEnabled)
{
logger.LogError(CliResources.UnableToCompileParamsFile, paramsInputPath, nameof(ExperimentalFeaturesEnabled.ParamsFiles));
return 1;
}

if (!IsBicepparamsFile(paramsInputPath))
{
logger.LogError(CliResources.UnrecognizedFileExtensionMessage, paramsInputPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void Valid_bicepparam_TemplateEmiter_should_produce_expected_template(Bas
data.Compiled.Should().NotBeNull();

var sourceFileGrouping = SourceFileGroupingBuilder.Build(BicepTestConstants.FileResolver, BicepTestConstants.ModuleDispatcher, new Workspace(), PathHelper.FilePathToFileUrl(data.Parameters.OutputFilePath));
var result = this.EmitParam(sourceFileGrouping, new(), data.Compiled!.OutputFilePath);
var result = this.EmitParam(sourceFileGrouping, new(ParamsFilesEnabled: true), data.Compiled!.OutputFilePath);

result.Diagnostics.Should().NotHaveErrors();
result.Status.Should().Be(EmitStatus.Succeeded);
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4345,7 +4345,7 @@ public void Test_Issue9467()
output vaultId string = CertificateVault.id
";

var (parameters, _, _) = CompilationHelper.CompileParams(Services.WithFeatureOverrides(new(UserDefinedTypesEnabled: true)), ("parameters.bicepparam", bicepparamText), ("main.bicep", bicepTemplateText));
var (parameters, _, _) = CompilationHelper.CompileParams(Services.WithFeatureOverrides(new(UserDefinedTypesEnabled: true, ParamsFilesEnabled: true)), ("parameters.bicepparam", bicepparamText), ("main.bicep", bicepTemplateText));

var result = CompilationHelper.Compile(Services.WithFeatureOverrides(new(UserDefinedTypesEnabled: true)), bicepTemplateText);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class ParamsSemanticModelTests
[NotNull]
public TestContext? TestContext { get; set; }

private SemanticModel CreateSemanticModel(string paramsFilePath)
private SemanticModel CreateSemanticModel(ServiceBuilder services, string paramsFilePath)
{
var configuration = BicepTestConstants.BuiltInConfiguration;
var sourceFileGrouping = Services.Build().BuildSourceFileGrouping(PathHelper.FilePathToFileUrl(paramsFilePath));
var compilation = Services.Build().BuildCompilation(sourceFileGrouping);
var sourceFileGrouping = services.Build().BuildSourceFileGrouping(PathHelper.FilePathToFileUrl(paramsFilePath));
var compilation = services.Build().BuildCompilation(sourceFileGrouping);

return compilation.GetEntrypointSemanticModel();
}
Expand All @@ -40,7 +40,7 @@ public void ProgramsShouldProduceExpectedDiagnostic(BaselineData_Bicepparam base
{
var data = baselineData.GetData(TestContext);

var model = CreateSemanticModel(data.Parameters.OutputFilePath);
var model = CreateSemanticModel(Services.WithFeatureOverrides(new(ParamsFilesEnabled: true)), data.Parameters.OutputFilePath);

// use a deterministic order
var diagnostics = model.GetAllDiagnostics()
Expand All @@ -62,7 +62,7 @@ public void ProgramsShouldProduceExpectedUserDeclaredSymbols(BaselineData_Bicepp
{
var data = baselineData.GetData(TestContext);

var model = CreateSemanticModel(data.Parameters.OutputFilePath);
var model = CreateSemanticModel(Services, data.Parameters.OutputFilePath);

var symbols = SymbolCollector
.CollectSymbols(model)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"experimentalFeaturesEnabled": {
"userDefinedTypes": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"experimentalFeaturesEnabled": {
"userDefinedTypes": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"experimentalFeaturesEnabled": {
"userDefinedTypes": true
}
}
3 changes: 1 addition & 2 deletions src/Bicep.Core.UnitTests/Utils/CompilationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public static CompilationResult Compile(ServiceBuilder services, string fileCont

public static ParamsCompilationResult CompileParams(params (string fileName, string fileContents)[] files)
{
var features = BicepTestConstants.FeatureOverrides;
var services = new ServiceBuilder().WithFeatureOverrides(features);
var services = new ServiceBuilder().WithFeatureOverrides(new(ParamsFilesEnabled: true));
return CompileParams(services, files);
}

Expand Down
6 changes: 6 additions & 0 deletions src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,12 @@ public ErrorDiagnostic IndexOutOfBounds(string typeName, long tupleLength, long
DiagnosticLevel.Warning,
"BCP335",
$"The provided value {(sourceMaxLength.HasValue ? $"may have a length as large as {sourceMaxLength.Value}" : "has no configured maximum length")} and may be too long to assign to a target with a configured maximum length of {targetMaxLength}.");

public ErrorDiagnostic ParametersFileUnsupported() => new(
TextSpan,
"BCP336",
$@"Using a Bicep Parameters file requires enabling EXPERIMENTAL feature ""{nameof(ExperimentalFeaturesEnabled.ParamsFiles)}"".",
new Uri("https://aka.ms/bicep/config"));
}

public static DiagnosticBuilderInternal ForPosition(TextSpan span)
Expand Down
7 changes: 7 additions & 0 deletions src/Bicep.Core/Semantics/SemanticModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ private IEnumerable<IDiagnostic> GetAdditionalParamsSemanticDiagnostics()
return Enumerable.Empty<IDiagnostic>();
}

if (!this.Features.ParamsFilesEnabled)
{
// prompt the user to enable the experimental feature before showing any other diagnostics
var paramsFileUnsupportedDiag = DiagnosticBuilder.ForDocumentStart().ParametersFileUnsupported();
return paramsFileUnsupportedDiag.AsEnumerable();
}

// try to get the bicep file's semantic model
if(!this.Root.TryGetBicepFileSemanticModelViaUsing(out var bicepSemanticModel, out var failureDiagnostic))
{
Expand Down
5 changes: 0 additions & 5 deletions src/vscode-bicep/enableParams.js

This file was deleted.

24 changes: 22 additions & 2 deletions src/vscode-bicep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"$activationEvents.comment": "When we start requiring VS Code 1.75.0 or higher, we can remove the onCommand and onLanguage activation events but will still need the onWebviewPanel event (see https://code.visualstudio.com/api/references/activation-events#onLanguage)",
"activationEvents": [
"onLanguage:bicep",
"onLanguage:bicep-params",
"onCommand:bicep.build",
"onCommand:bicep.decompile",
"onCommand:bicep.generateParams",
Expand Down Expand Up @@ -145,6 +146,21 @@
"filenames": [
"bicepconfig.json"
]
},
{
"id": "bicep-params",
"aliases": [
"Bicep Parameters (Experimental)",
"Bicep Params (Experimental)"
],
"extensions": [
".bicepparam"
],
"configuration": "./syntaxes/language-configuration.json",
"icon": {
"light": "./icons/bicepparam-file.svg",
"dark": "./icons/bicepparam-file.svg"
}
}
],
"grammars": [
Expand All @@ -162,6 +178,11 @@
"language": "bicep",
"scopeName": "source.bicep",
"path": "./syntaxes/bicep.tmlanguage"
},
{
"language": "bicep-params",
"scopeName": "source.bicep",
"path": "./syntaxes/bicep.tmlanguage"
}
],
"commands": [
Expand Down Expand Up @@ -602,8 +623,7 @@
"testlocal:e2e": "(export BICEP_LANGUAGE_SERVER_PATH=${INIT_CWD}/../Bicep.LangServer/bin/Debug/net7.0/Bicep.LangServer.dll || set BICEP_LANGUAGE_SERVER_PATH=%INIT_CWD%/../Bicep.LangServer/bin/Debug/net7.0/Bicep.LangServer.dll) && npm run build && npm run build:e2e && npm run test:e2e",
"clean": "rimraf ./out ./coverage",
"package": "npm run clean && nbgv-setversion && vsce package --githubBranch main --out ./vscode-bicep.vsix && nbgv-setversion --reset",
"packagelocal": "rimraf ./bicepLanguageServer && cp -r ../Bicep.LangServer/bin/Debug/net7.0 ./bicepLanguageServer && npm run package",
"params": "node ./enableParams.js"
"packagelocal": "rimraf ./bicepLanguageServer && cp -r ../Bicep.LangServer/bin/Debug/net7.0 ./bicepLanguageServer && npm run package"
},
"devDependencies": {
"@types/cytoscape": "^3.19.9",
Expand Down
31 changes: 0 additions & 31 deletions src/vscode-bicep/package.params.json

This file was deleted.

0 comments on commit f1c10aa

Please sign in to comment.