コード例 #1
0
        public static string GetEntityHighlightingAttributeId([NotNull] this FSharpEntity entity)
        {
            if (entity.IsNamespace)
            {
                return(HighlightingAttributeIds.NAMESPACE_IDENTIFIER_ATTRIBUTE);
            }

            if (entity.IsEnum)
            {
                return(HighlightingAttributeIds.TYPE_ENUM_ATTRIBUTE);
            }

            if (entity.IsValueType)
            {
                return(HighlightingAttributeIds.TYPE_STRUCT_ATTRIBUTE);
            }

            if (entity.IsDelegate)
            {
                return(HighlightingAttributeIds.TYPE_DELEGATE_ATTRIBUTE);
            }

            if (entity.IsFSharpModule)
            {
                return(HighlightingAttributeIds.TYPE_STATIC_CLASS_ATTRIBUTE);
            }

            return(entity.IsInterface
        ? HighlightingAttributeIds.TYPE_INTERFACE_ATTRIBUTE
        : HighlightingAttributeIds.TYPE_CLASS_ATTRIBUTE);
        }
コード例 #2
0
        public static string GetEntityHighlightingAttributeId([NotNull] this FSharpEntity entity)
        {
            if (entity.IsNamespace)
            {
                return(FSharpHighlightingAttributeIdsModule.Namespace);
            }

            if (entity.IsEnum)
            {
                return(FSharpHighlightingAttributeIdsModule.Enum);
            }

            if (entity.IsDelegate)
            {
                return(FSharpHighlightingAttributeIdsModule.Delegate);
            }

            if (entity.IsFSharpModule)
            {
                return(FSharpHighlightingAttributeIdsModule.Module);
            }

            if (entity.IsFSharpUnion)
            {
                return(FSharpHighlightingAttributeIdsModule.Union);
            }

            if (entity.IsFSharpRecord)
            {
                return(FSharpHighlightingAttributeIdsModule.Record);
            }

            if (entity.IsMeasure)
            {
                return(FSharpHighlightingAttributeIdsModule.UnitOfMeasure);
            }

            if (entity.IsInterface)
            {
                return(FSharpHighlightingAttributeIdsModule.Interface);
            }

            if (entity.IsClass)
            {
                return(FSharpHighlightingAttributeIdsModule.Class);
            }

            if (entity.IsValueType || entity.HasMeasureParameter())
            {
                return(FSharpHighlightingAttributeIdsModule.Struct);
            }

            if (entity.IsFSharpAbbreviation && entity.AbbreviatedType.IsFunctionType)
            {
                return(FSharpHighlightingAttributeIdsModule.Delegate);
            }

            return(FSharpHighlightingAttributeIdsModule.Class);
        }
コード例 #3
0
        private static IEnumerable <string> GetPossibleNames([NotNull] FSharpEntity entity)
        {
            yield return(entity.AccessPath + "." + entity.DisplayName);

            yield return(entity.AccessPath + "." + entity.LogicalName);

            yield return(((FSharpSymbol)entity).FullName);
        }
コード例 #4
0
        private static INamespace GetDeclaredNamespace([NotNull] FSharpEntity entity, IPsiModule psiModule)
        {
            var name = entity.LogicalName;
            var containingNamespace = entity.Namespace?.Value;
            var fullName            = containingNamespace != null ? containingNamespace + "." + name : name;
            var elements            = psiModule.GetSymbolScope().GetElementsByQualifiedName(fullName);

            return(elements.FirstOrDefault() as INamespace);
        }
コード例 #5
0
        public static IDeclaredType GetBaseType([NotNull] FSharpEntity entity,
                                                IList <ITypeParameter> typeParamsFromContext, [NotNull] IPsiModule psiModule)
        {
            var fsBaseType = GetFSharpBaseType(entity);

            return(fsBaseType != null
        ? GetType(fsBaseType.Value, typeParamsFromContext, psiModule) as IDeclaredType
        : TypeFactory.CreateUnknownType(psiModule));
        }
コード例 #6
0
        private static IClrDeclaredElement GetDeclaredNamespace([NotNull] FSharpEntity entity, IPsiModule psiModule)
        {
            Assertion.Assert(entity.IsNamespace, "entity.IsNamespace");
            var name           = entity.CompiledName;
            var containingName = entity.Namespace?.Value;
            var fullName       = containingName != null ? containingName + "." + name : name;
            var symbolScope    = psiModule.GetPsiServices().Symbols.GetSymbolScope(psiModule, true, true);

            return(symbolScope.GetElementsByQualifiedName(fullName).FirstOrDefault() as INamespace);
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        public static string GetEntityHighlightingAttributeId([NotNull] this FSharpEntity entity)
        {
            if (entity.IsNamespace)
            {
                return(FSharpHighlightingAttributeIds.Namespace);
            }

            if (entity.IsEnum)
            {
                return(FSharpHighlightingAttributeIds.Enum);
            }

            if (entity.IsValueType)
            {
                return(FSharpHighlightingAttributeIds.Struct);
            }

            if (entity.IsDelegate)
            {
                return(FSharpHighlightingAttributeIds.Delegate);
            }

            if (entity.IsFSharpModule)
            {
                return(FSharpHighlightingAttributeIds.Module);
            }

            if (entity.IsFSharpUnion)
            {
                return(FSharpHighlightingAttributeIds.Union);
            }

            if (entity.IsFSharpRecord)
            {
                return(FSharpHighlightingAttributeIds.Record);
            }

            return(entity.IsInterface
        ? FSharpHighlightingAttributeIds.Interface
        : FSharpHighlightingAttributeIds.Class);
        }
コード例 #9
0
        public static string GetClrName([NotNull] FSharpEntity entity)
        {
            // F# 4.0 specs 5.1.4
            if (entity.IsArrayType)
            {
                return(ArrayClrName);
            }

            // qualified name may include assembly name, public key, etc and separated with comma, e.g. for unit it returns
            // "Microsoft.FSharp.Core.Unit, FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            try
            {
                return(entity.QualifiedBaseName);
            }
            catch (Exception e)
            {
                Logger.LogMessage(LoggingLevel.WARN, "Could not map FSharpEntity: {0}", entity);
                Logger.LogExceptionSilently(e);
                return(null);
            }
        }
コード例 #10
0
 private static ImmutableArray <string> FromEntity(FSharpEntity entity)
 {
     if (entity.IsNamespace)
     {
         return(Namespace);
     }
     if (entity.IsClass)
     {
         return(Class);
     }
     if (entity.IsInterface)
     {
         return(Interface);
     }
     if (entity.IsDelegate)
     {
         return(Delegate);
     }
     if (entity.IsEnum)
     {
         return(Enum);
     }
     if (entity.IsFSharpUnion)
     {
         return(Union);
     }
     if (entity.IsValueType)
     {
         return(Structure);
     }
     if (entity.IsFSharpModule)
     {
         return(Module);
     }
     if (entity.IsFSharpAbbreviation)
     {
         return(FromEntity(entity.AbbreviatedType.TypeDefinition));
     }
     return(ImmutableArray <string> .Empty);
 }
コード例 #11
0
        internal static ITypeElement GetTypeElement([NotNull] FSharpEntity entity, [NotNull] IPsiModule psiModule)
        {
            if (((FSharpSymbol)entity).DeclarationLocation == null || entity.IsByRef || entity.IsProvidedAndErased)
            {
                return(null);
            }

            if (!entity.IsFSharpAbbreviation)
            {
                var clrName = FSharpTypesUtil.GetClrName(entity);
                return(clrName != null
          ? TypeFactory.CreateTypeByCLRName(clrName, psiModule).GetTypeElement()
          : 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;
            }

            var name = FSharpTypesUtil.GetClrName(entity);

            return(name != null?TypeFactory.CreateTypeByCLRName(name, psiModule).GetTypeElement() : null);
        }
コード例 #12
0
        public static IEnumerable <IDeclaredType> GetSuperTypes([NotNull] FSharpEntity entity,
                                                                IList <ITypeParameter> typeParamsFromContext, [NotNull] IPsiModule psiModule)
        {
            var interfaces = entity.DeclaredInterfaces;
            var types      = new List <IDeclaredType>(interfaces.Count + 1);

            foreach (var entityInterface in interfaces)
            {
                if (GetType(entityInterface, typeParamsFromContext, psiModule) is IDeclaredType declaredType)
                {
                    types.Add(declaredType);
                }
            }

            var baseType = GetBaseType(entity, typeParamsFromContext, psiModule);

            if (baseType != null)
            {
                types.Add(baseType);
            }
            return(types);
        }
コード例 #13
0
        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));
        }
コード例 #14
0
 public static IDeclaredType MapBaseType([NotNull] this FSharpEntity entity, IList <ITypeParameter> typeParams,
                                         [NotNull] IPsiModule psiModule) =>
 entity.BaseType?.Value is var baseType && baseType != null
コード例 #15
0
 private static FSharpOption <FSharpType> GetFSharpBaseType([NotNull] FSharpEntity entity)
 {
     lock (ourFcsLock)
         return(entity.BaseType);
 }