Skip to content

Commit

Permalink
remove brittle string replacing and retrieve value type from parser
Browse files Browse the repository at this point in the history
  • Loading branch information
bryankenote committed Oct 11, 2023
1 parent 213daf1 commit 4f8de20
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Facility.LanguageServer/FsdDefinitionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this
.Select(field =>
{
var part = field.GetPart(ServicePartKind.TypeName);
var typeName = GetFieldTypeName(field);
var typeName = service.GetFieldTypeName(field);

return (part, typeName);
})
Expand All @@ -53,7 +53,7 @@ public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this
.Select(field =>
{
var part = field.GetPart(ServicePartKind.TypeName);
var typeName = GetFieldTypeName(field);
var typeName = service.GetFieldTypeName(field);

var type = service.GetFieldType(field);
var memberTypeName = type?.GetMemberTypeName();
Expand Down Expand Up @@ -84,14 +84,10 @@ private static string GetMemberTypeName(this ServiceTypeInfo type)
return null;
}

private static string GetFieldTypeName(this ServiceFieldInfo field)
private static string GetFieldTypeName(this ServiceInfo service, ServiceFieldInfo field)
{
return field.TypeName
.Replace("[]", "", StringComparison.Ordinal)
.Replace("map<", "", StringComparison.Ordinal)
.Replace("nullable<", "", StringComparison.Ordinal)
.Replace("result<", "", StringComparison.Ordinal)
.Replace(">", "", StringComparison.Ordinal);
var type = service.GetFieldType(field);
return type?.ValueType?.ToString() ?? type?.ToString() ?? field.TypeName;
}
}
}

0 comments on commit 4f8de20

Please sign in to comment.