From 2d40b7e292da5bb959db2be0e8a1c25770996c61 Mon Sep 17 00:00:00 2001 From: bryankenote Date: Wed, 11 Oct 2023 14:14:01 -0700 Subject: [PATCH] remove brittle string replacing and retrieve value type from parser --- .../FsdDefinitionUtility.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Facility.LanguageServer/FsdDefinitionUtility.cs b/src/Facility.LanguageServer/FsdDefinitionUtility.cs index d7b7566..d14229c 100644 --- a/src/Facility.LanguageServer/FsdDefinitionUtility.cs +++ b/src/Facility.LanguageServer/FsdDefinitionUtility.cs @@ -41,7 +41,7 @@ public static IEnumerable GetReferencedServicePartsAtPosition(this .Select(field => { var part = field.GetPart(ServicePartKind.TypeName); - var typeName = GetFieldTypeName(field); + var typeName = service.GetFieldTypeName(field); return (part, typeName); }) @@ -53,7 +53,7 @@ public static IEnumerable 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(); @@ -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; } } }