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

Compile-time type imports #11298

Merged
merged 30 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c3cabe1
Rename Import* syntax kinds to Provider*
jeskew Jun 14, 2023
cb03a8d
Add support for compile-time imports to parser
jeskew Jun 27, 2023
594547f
Add feature flag for compile-time imports
jeskew Jun 27, 2023
1ef9d68
Add @export() decorator for types
jeskew Jun 29, 2023
e4e489e
Integrate imports into type system and module dispatcher
jeskew Jul 5, 2023
df81fb6
Tweak merge
jeskew Jul 17, 2023
232a832
Add support for LS completions
jeskew Jul 19, 2023
41fe9dd
Emit imported type symbols in compiled template
jeskew Jul 24, 2023
de138d7
Try to break import closure info calculation into separate steps
jeskew Jul 25, 2023
25e4f49
Move inner classes into separate files
jeskew Jul 25, 2023
0318593
Ensure @export() is targeting top-level type statement
jeskew Jul 25, 2023
4d0a2e2
Merge branch 'main' into jeskew/imports
jeskew Jul 25, 2023
2308e26
Improve compile-time import diagnostic messaging
jeskew Jul 26, 2023
d4bdc01
Implement go to definition for import symbols
jeskew Jul 26, 2023
928ccba
Regenerate baselines and fix failing tests
jeskew Jul 26, 2023
ecbb177
Augment compile time import completions
jeskew Jul 26, 2023
7206eb4
Fixup message formatting
jeskew Jul 27, 2023
b6eabe8
Fix failing tests
jeskew Jul 27, 2023
aa0f8f5
Use an incrementing counter rather than hashes to create unique names…
jeskew Jul 27, 2023
2a691da
Augment hover support on imported symbols and properties thereof
jeskew Jul 27, 2023
9a6329d
Ensure registry module restoration works as expected for `import` and…
jeskew Jul 27, 2023
700884d
Add ARM source template support for go-to-definition on imported symbols
jeskew Jul 27, 2023
69d84ac
Merge branch 'main' into jeskew/imports
jeskew Jul 30, 2023
e6cfd34
Inject import origin info into type definition metadata for imported …
jeskew Jul 30, 2023
c4b435f
Merge branch 'main' into jeskew/imports
jeskew Aug 1, 2023
9224888
Merge branch 'main' into jeskew/imports
jeskew Aug 2, 2023
6bf9e25
Merge branch 'main' into jeskew/imports
jeskew Aug 2, 2023
838d75c
Merge branch 'main' into jeskew/imports
jeskew Aug 3, 2023
0b292b2
Use ToImmutableDictionary instead of CreateRange
jeskew Aug 4, 2023
41e11e0
Merge branch 'main' into jeskew/imports
jeskew Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ensure @export() is targeting top-level type statement
  • Loading branch information
jeskew committed Jul 25, 2023
commit 0318593dead2efc071ffafb3369b4a2c9b377546
16 changes: 16 additions & 0 deletions src/Bicep.Core.IntegrationTests/CompileTimeImportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ public void Importing_unexported_symbol_should_raise_diagnostic()
});
}

[TestMethod]
public void Exporting_type_property_should_raise_diagnostic()
{
var result = CompilationHelper.Compile(ServicesWithCompileTimeTypeImports, """
type foo = {
@export()
property: string
}
""");

result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP358", DiagnosticLevel.Error, "The \"@export()\" decorator must target a top-level statement.")
});
}

[TestMethod]
public void Importing_non_template_should_raise_diagnostic()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,11 @@ public ErrorDiagnostic RuntimeValueNotAllowedInFunctionDeclaration(string? acces
TextSpan,
"BCP357",
$"The '{symbolName}' symbol was not found in (or was not exported by) the imported template.");

public ErrorDiagnostic ExportDecoratorMustTargetStatement() => new(
TextSpan,
"BCP358",
@"The ""@export()"" decorator must target a top-level statement.");
}

public static DiagnosticBuilderInternal ForPosition(TextSpan span)
Expand Down
12 changes: 11 additions & 1 deletion src/Bicep.Core/Semantics/Namespaces/SystemNamespaceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Bicep.Core.FileSystem;
using Bicep.Core.Intermediate;
using Bicep.Core.Modules;
using Bicep.Core.Navigation;
using Bicep.Core.Parsing;
using Bicep.Core.Syntax;
using Bicep.Core.TypeSystem;
Expand Down Expand Up @@ -1441,11 +1442,20 @@ static void ValidateLength(string decoratorName, DecoratorSyntax decoratorSyntax
yield return new DecoratorBuilder(LanguageConstants.ExportPropertyName)
.WithDescription("Allows the type to be imported into other templates.")
.WithFlags(FunctionFlags.TypeDecorator)
.WithEvaluator((functionCall, decorated) => decorated switch
.WithEvaluator(static (functionCall, decorated) => decorated switch
{
DeclaredTypeExpression declaredType => declaredType with { Exported = functionCall },
_ => decorated,
})
.WithValidator(static (decoratorName, decoratorSyntax, _, _, binder, _, diagnosticWriter) =>
{
var decoratorTarget = binder.GetParent(decoratorSyntax);

if (decoratorTarget is not ITopLevelNamedDeclarationSyntax)
{
diagnosticWriter.Write(DiagnosticBuilder.ForPosition(decoratorSyntax).ExportDecoratorMustTargetStatement());
}
})
.Build();

yield return new DecoratorBuilder(LanguageConstants.ParameterAllowedPropertyName)
Expand Down