Skip to content

Commit

Permalink
Add type descriptions to completions and hovers, support method hover…
Browse files Browse the repository at this point in the history
…s. (Azure#1915)
  • Loading branch information
anthony-c-martin committed Apr 9, 2021
1 parent 68147ea commit bdbaa87
Show file tree
Hide file tree
Showing 74 changed files with 1,377 additions and 693 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.bicep -text
*.ts text eol=lf
*.cs text eol=lf
*.cs text eol=lf
*.sh text eol=lf
2 changes: 1 addition & 1 deletion Bicep.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_SolutionItems", "_Solution
NuGet.config = NuGet.config
README.md = README.md
SECURITY.md = SECURITY.md
SetBaseline.ps1 = SetBaseline.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{895557F9-3D8B-4752-878A-5F0AAF2E405C}"
ProjectSection(SolutionItems) = preProject
scripts\bcode.ps1 = scripts\bcode.ps1
scripts\SetBaseline.ps1 = scripts\SetBaseline.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{78549F2A-4BF8-4105-B4BB-EF8B2EF0ACCD}"
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Many of the bicep integration tests rely on baseline test assertion files that a
#### Manually
* If you see a test failure with a message containing Windows and *nix copy commands, you have encountered such a test. You have the following options to fix the test:
1. Manually execute the provided command in a shell. This makes sense for a single test, but is extremely tedious otherwise.
1. Run the `SetBaseline.ps1` script at the repo root to execute the tests in `SetBaseLine` mode, which causes the baselines to be automatically updated in bulk for failing tests. You should see baseline file modifications in Git pending changes. (Make sure your Git pending changes are empty before doing so - your changes could get overwritten!).
1. Run [`./scripts/SetBaseline.ps1`](./scripts/SetBaseline.ps1) (Windows) or [`./scripts/SetBaseline.sh`](./scripts/SetBaseline.sh) (Linux/OSX) to execute the tests in `SetBaseLine` mode. This automatically updates the baselines in bulk for failing tests.
1. You should see baseline file modifications in Git pending changes. (Make sure your Git pending changes are empty before doing so - your changes could get overwritten!).
* Inspect the baseline assertion diffs to ensure changes are expected and match the code changes you have made. (If a pull request contains changes to baseline files that can't be explained, it will not be merged.)

#### Via GitHub Action
Expand All @@ -55,7 +56,7 @@ If you have an active branch pushed to your GitHub fork, you can use the "Update
* The name of the entry should match the name of the folder you create (same casing), and there should be a main.bicep file in that folder.
1. Make changes to main.bicep.
1. Create empty `main.<suffix>.bicep` assertion files in the folder. You need to create following suffixes: `diagnostics`, `formatted`, `symbols`, `syntax`, `tokens`
1. Run `SetBaseline.ps1` to fill out the assertion files.
1. Follow [Updating test baselines](#updating-test-baselines) to generate baseline files.
* The naming and file structure is important here as it's used by the test runner to assert e.g. whether the example should compile, and the end-of-line characters.
* For tests that deal with module, you may see some unexpected behavior because the test could be using a mock file resolver instead of the standard one. Similarly, some tests may be using a mock resource type provider instead of the standard ones - usually that explains why some types aren't recognized in tests.

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions scripts/SetBaseline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dotnet test -- 'TestRunParameters.Parameter(name="SetBaseLine", value="true")'
3 changes: 2 additions & 1 deletion src/Bicep.Core.IntegrationTests/DecoratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public void NonDecoratorFunction_MissingDeclaration_CannotBeUsedAsDecorator()
template.Should().NotHaveValue();
diagnostics.Should().HaveDiagnostics(new[] {
("BCP152", DiagnosticLevel.Error, "Function \"concat\" cannot be used as a decorator."),
("BCP152", DiagnosticLevel.Error, "Function \"resourceId\" cannot be used as a decorator."),
("BCP132", DiagnosticLevel.Error, "Expected a declaration after the decorator."),
("BCP152", DiagnosticLevel.Error, "Function \"resourceId\" cannot be used as a decorator.")
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Core.IntegrationTests/Emit/TemplateEmitterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void ValidBicep_TemplateEmiterShouldProduceExpectedTemplate(DataSet dataS

// emitting the template should be successful
var result = this.EmitTemplate(SyntaxTreeGroupingBuilder.Build(new FileResolver(), new Workspace(), PathHelper.FilePathToFileUrl(bicepFilePath)), compiledFilePath, BicepTestConstants.DevAssemblyFileVersion);
result.Status.Should().Be(EmitStatus.Succeeded);
result.Diagnostics.Should().BeEmptyOrContainDeprecatedDiagnosticOnly();
result.Status.Should().Be(EmitStatus.Succeeded);

var actual = JToken.Parse(File.ReadAllText(compiledFilePath));

Expand All @@ -57,8 +57,8 @@ public void TemplateEmitter_output_should_not_include_UTF8_BOM()

// emitting the template should be successful
var result = this.EmitTemplate(syntaxTreeGrouping, compiledFilePath, BicepTestConstants.DevAssemblyFileVersion);
result.Status.Should().Be(EmitStatus.Succeeded);
result.Diagnostics.Should().BeEmpty();
result.Status.Should().Be(EmitStatus.Succeeded);

var bytes = File.ReadAllBytes(compiledFilePath);
// No BOM at the start of the file
Expand Down Expand Up @@ -102,8 +102,8 @@ public void InvalidBicep_TemplateEmiterShouldNotProduceAnyTemplate(DataSet dataS

// emitting the template should fail
var result = this.EmitTemplate(SyntaxTreeGroupingBuilder.Build(new FileResolver(), new Workspace(), PathHelper.FilePathToFileUrl(bicepFilePath)), filePath, BicepTestConstants.DevAssemblyFileVersion);
result.Status.Should().Be(EmitStatus.Failed);
result.Diagnostics.Should().NotBeEmpty();
result.Status.Should().Be(EmitStatus.Failed);
}

[DataTestMethod]
Expand Down
19 changes: 19 additions & 0 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,5 +1524,24 @@ public void Test_Issue2009_expanded()
evaluated.Should().HaveValueAtPath("$.outputs['providersApiVersionFirst'].value", "3024-01-01");
evaluated.Should().HaveValueAtPath("$.outputs['providersLocationFirst'].value", "Earth");
}

[TestMethod]
public void Variable_loops_should_not_cause_infinite_recursion()
{
var result = CompilationHelper.Compile(@"
var loopInput = [
'one'
'two'
]
var arrayOfObjectsViaLoop = [for (name, i) in loopInput: {
index: i
name: name
value: 'prefix-${i}-${name}-suffix'
}]
");

result.Should().NotHaveDiagnostics();
result.Template.Should().NotBeNull();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Bicep.Core.UnitTests.Assertions;
using Bicep.Core.UnitTests.Utils;
using FluentAssertions;
using FluentAssertions.Execution;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bicep.Core.IntegrationTests.Semantics
Expand Down Expand Up @@ -158,7 +159,7 @@ public void FindReferencesResultsShouldIncludeAllSymbolReferenceSyntaxNodes(Data
.SelectMany(s => semanticModel.FindReferences(s!))
.Where(refSyntax => !(refSyntax is INamedDeclarationSyntax));

foundReferences.Should().BeEquivalentTo(symbolReferences);
symbolReferences.Should().BeSubsetOf(foundReferences);
}

private static List<SyntaxBase> GetAllBoundSymbolReferences(ProgramSyntax program, SemanticModel semanticModel)
Expand All @@ -168,7 +169,7 @@ private static List<SyntaxBase> GetAllBoundSymbolReferences(ProgramSyntax progra
new List<SyntaxBase>(),
(accumulated, current) =>
{
if (current is ISymbolReference symbolReference && TestSyntaxHelper.NodeShouldBeBound(symbolReference, semanticModel))
if (current is ISymbolReference symbolReference && TestSyntaxHelper.NodeShouldBeBound(symbolReference))
{
accumulated.Add(current);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"detail": "balance-similar-node-groups",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -32,7 +32,7 @@
"detail": "expander",
"documentation": {
"kind": "markdown",
"value": "Type: `'least-waste' | 'most-pods' | 'random'` \n"
"value": "Type: `'least-waste' | 'most-pods' | 'random'` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -53,7 +53,7 @@
"detail": "max-empty-bulk-delete",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -80,7 +80,7 @@
"detail": "max-graceful-termination-sec",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -107,7 +107,7 @@
"detail": "max-total-unready-percentage",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -134,7 +134,7 @@
"detail": "new-pod-scale-up-delay",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -161,7 +161,7 @@
"detail": "ok-total-unready-count",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -188,7 +188,7 @@
"detail": "scale-down-delay-after-add",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -215,7 +215,7 @@
"detail": "scale-down-delay-after-delete",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -242,7 +242,7 @@
"detail": "scale-down-delay-after-failure",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -269,7 +269,7 @@
"detail": "scale-down-unneeded-time",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -296,7 +296,7 @@
"detail": "scale-down-unready-time",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -323,7 +323,7 @@
"detail": "scale-down-utilization-threshold",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -350,7 +350,7 @@
"detail": "scan-interval",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -377,7 +377,7 @@
"detail": "skip-nodes-with-local-storage",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand All @@ -404,7 +404,7 @@
"detail": "skip-nodes-with-system-pods",
"documentation": {
"kind": "markdown",
"value": "Type: `string` \n"
"value": "Type: `string` \n \n"
},
"deprecated": false,
"preselect": false,
Expand Down
Loading

0 comments on commit bdbaa87

Please sign in to comment.