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

Show tooltips on hover for type property definitions and type additional properties accesses #13546

Merged
merged 1 commit into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -31,7 +31,7 @@ public async Task ProviderNameAndVersionAreUsedAsCacheKeys()
var (clientFactory, _) = RegistryHelper.CreateMockRegistryClients(repositoryNames.Select(name => (registry, $"{repositoryPath}/{name}")).ToArray());

var services = new ServiceBuilder()
.WithFeatureOverrides(new(ExtensibilityEnabled: true, ProviderRegistry: true, DynamicTypeLoadingEnabled: true))
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true, ProviderRegistry: true, DynamicTypeLoadingEnabled: true))
jeskew marked this conversation as resolved.
Show resolved Hide resolved
.WithContainerRegistryClientFactory(clientFactory);

foreach (var repoName in repositoryNames)
Expand All @@ -46,7 +46,7 @@ public async Task ProviderNameAndVersionAreUsedAsCacheKeys()
"main.bicep",
@$"
provider 'br:example.azurecr.io/test/provider/foo@1.2.3' as foo

module mod './mod.bicep' = {{
name: 'mod'
params: {{ }}
Expand Down
59 changes: 54 additions & 5 deletions src/Bicep.Core/Semantics/SymbolHelper.cs
Expand Up @@ -21,7 +21,7 @@ public static class SymbolHelper
// The decision to pass in getDeclaredTypeFunc as a lambda rather than the ITypeManager interface is deliberate.
// We should be conscious about not introducing cyclic dependencies, as this code is also used within the type manager, but it only needs declared types.

static PropertySymbol? GetPropertySymbol(TypeSymbol? baseType, string property)
static PropertySymbol? GetPropertySymbol(TypeSymbol? baseType, string property, bool useAdditionalPropertiesType)
{
if (baseType is null)
{
Expand All @@ -37,12 +37,30 @@ public static class SymbolHelper

if (typeProperty is null)
{
if (useAdditionalPropertiesType)
{
return GetAdditionalPropertiesSymbol(baseType);
}

return null;
}

return new PropertySymbol(property, typeProperty.Description, typeProperty.TypeReference.Type);
}

static PropertySymbol? GetAdditionalPropertiesSymbol(TypeSymbol? baseType)
{
if (baseType is null ||
TypeAssignmentVisitor.UnwrapType(baseType) is not ObjectType objectType ||
objectType.AdditionalPropertiesType is null ||
objectType.AdditionalPropertiesFlags.HasFlag(TypePropertyFlags.FallbackProperty))
{
return null;
}

return new PropertySymbol("*", string.Empty, objectType.AdditionalPropertiesType.Type);
}

switch (syntax)
{
case InstanceFunctionCallSyntax ifc:
Expand All @@ -69,20 +87,33 @@ public static class SymbolHelper
return null;
}
case InstanceParameterizedTypeInstantiationSyntax iptic:
return GetPropertySymbol(getDeclaredTypeFunc(iptic.BaseExpression), iptic.PropertyName.IdentifierName);
return GetPropertySymbol(getDeclaredTypeFunc(iptic.BaseExpression), iptic.PropertyName.IdentifierName, true);
case PropertyAccessSyntax propertyAccess:
{
var baseType = getDeclaredTypeFunc(propertyAccess.BaseExpression);
var property = propertyAccess.PropertyName.IdentifierName;

return GetPropertySymbol(baseType, property);
return GetPropertySymbol(baseType, property, true);
}
case TypePropertyAccessSyntax typePropertyAccess:
{
var baseType = getDeclaredTypeFunc(typePropertyAccess.BaseExpression);
if (baseType is not null)
{
baseType = TypeAssignmentVisitor.UnwrapType(baseType);
}
var property = typePropertyAccess.PropertyName.IdentifierName;

return GetPropertySymbol(baseType, property);
return GetPropertySymbol(baseType, property, false);
}
case TypeAdditionalPropertiesAccessSyntax addlPropertiesAccess:
{
var baseType = getDeclaredTypeFunc(addlPropertiesAccess.BaseExpression);
if (baseType is not null)
{
baseType = TypeAssignmentVisitor.UnwrapType(baseType);
}
return GetAdditionalPropertiesSymbol(baseType);
}
case ObjectPropertySyntax objectProperty:
{
Expand All @@ -97,7 +128,25 @@ public static class SymbolHelper
return null;
}

return GetPropertySymbol(baseType, property);
return GetPropertySymbol(baseType, property, true);
}
case ObjectTypePropertySyntax objectTypeProperty:
{
if (objectTypeProperty.TryGetKeyText() is not string propertyName || binder.GetParent(objectTypeProperty) is not SyntaxBase parentSyntax)
{
return null;
}

return GetPropertySymbol(getDeclaredTypeFunc(parentSyntax), propertyName, false);
}
case ObjectTypeAdditionalPropertiesSyntax addlProperties:
{
if (binder.GetParent(addlProperties) is not SyntaxBase parentSyntax)
{
return null;
}

return GetAdditionalPropertiesSymbol(getDeclaredTypeFunc(parentSyntax));
}
}

Expand Down