public static ITypeElement GetTypeElement([NotNull] this FSharpEntity entity, [NotNull] IPsiModule psiModule) { if (((FSharpSymbol)entity).DeclarationLocation == null || entity.IsByRef || entity.IsProvidedAndErased) { return(null); } if (!entity.IsFSharpAbbreviation) { var clrTypeName = entity.GetClrName(); if (clrTypeName == null) { return(null); } var typeElements = psiModule.GetSymbolScope().GetTypeElementsByCLRName(clrTypeName); if (typeElements.IsEmpty()) { return(null); } if (typeElements.Length == 1) { return(typeElements[0]); } var assemblySimpleName = entity.Assembly?.SimpleName; return(assemblySimpleName != null ? typeElements.FirstOrDefault(typeElement => typeElement.Module.DisplayName == assemblySimpleName) : null); } var symbolScope = psiModule.GetSymbolScope(); while (entity.IsFSharpAbbreviation) { // FCS returns Clr names for non-abbreviated types only, using fullname var typeElement = TryFindByNames(GetPossibleNames(entity), symbolScope); if (typeElement != null) { return(typeElement); } var abbreviatedType = entity.AbbreviatedType; if (!abbreviatedType.HasTypeDefinition) { return(null); } entity = entity.AbbreviatedType.TypeDefinition; } return(entity.GetTypeElement(psiModule)); }
public static ITypeElement GetTypeElement([NotNull] this FSharpEntity entity, [NotNull] IPsiModule psiModule) { if (((FSharpSymbol)entity).DeclarationLocation == null || entity.IsByRef || entity.IsProvidedAndErased) { return(null); } if (!entity.IsFSharpAbbreviation) { var clrTypeName = entity.GetClrName(); if (clrTypeName == null) { return(null); } var typeElements = psiModule.GetSymbolScope().GetTypeElementsByCLRName(clrTypeName); if (typeElements.IsEmpty()) { return(null); } if (typeElements.Length == 1) { return(typeElements[0]); } // If there are multiple entities with given FQN, try to choose one based on assembly name or entity kind. var fcsAssemblySimpleName = entity.Assembly?.SimpleName; if (fcsAssemblySimpleName == null) { return(null); } var isModule = entity.IsFSharpModule; return(typeElements.FirstOrDefault(typeElement => { if (typeElement.Module.DisplayName != fcsAssemblySimpleName) { return false; } // Happens when there are an exception and a module with the same name. // It's now allowed, but we want keep resolve working where possible. if (typeElement is IFSharpDeclaredElement) { return isModule == typeElement is IFSharpModule; } return true; })); } var symbolScope = psiModule.GetSymbolScope(); while (entity.IsFSharpAbbreviation) { // FCS returns Clr names for non-abbreviated types only, using fullname var typeElement = TryFindByNames(GetPossibleNames(entity), symbolScope); if (typeElement != null) { return(typeElement); } var abbreviatedType = entity.AbbreviatedType; if (!abbreviatedType.HasTypeDefinition) { return(null); } entity = entity.AbbreviatedType.TypeDefinition; } return(entity.GetTypeElement(psiModule)); }