Skip to content

Commit

Permalink
Show tooltips on hover for type property definitions and type propert…
Browse files Browse the repository at this point in the history
…y accesses
  • Loading branch information
jeskew committed Mar 7, 2024
1 parent 9fd452e commit ee2931a
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 81 deletions.
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))
.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

0 comments on commit ee2931a

Please sign in to comment.