示例#1
0
        public override ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            // todo: type abbreviations
            if (declaredElement is IFSharpLocalDeclaration localDeclaration)
            {
                return(mySearchDomainFactory.CreateSearchDomain(localDeclaration.GetSourceFile()));
            }

            if (declaredElement is IFSharpSymbolElement fsSymbolElement)
            {
                var fsSymbol = fsSymbolElement.Symbol;
                if (!(fsSymbol is FSharpActivePatternCase activePatternCase))
                {
                    return(EmptySearchDomain.Instance);
                }

                if (fsSymbolElement is ResolvedFSharpSymbolElement)
                {
                    var patternEntity = activePatternCase.Group.DeclaringEntity?.Value;
                    if (patternEntity != null)
                    {
                        var patternTypeElement = FSharpElementsUtil.GetDeclaredElement(patternEntity, fsSymbolElement.Module);
                        return(patternTypeElement != null
              ? myClrSearchFactory.GetDeclaredElementSearchDomain(patternTypeElement)
              : EmptySearchDomain.Instance);
                    }
                }
            }

            if (declaredElement is TopActivePatternCase activePatternCaseElement)
            {
                var declaration = activePatternCaseElement.GetDeclaration();
                if (declaration?.GetContainingNode <IFSharpLocalDeclaration>() != null)
                {
                    return(mySearchDomainFactory.CreateSearchDomain(declaration.GetSourceFile()));
                }

                var containingMemberDeclaration = declaration?.GetContainingNode <ITypeMemberDeclaration>();
                var containingMember            = containingMemberDeclaration?.DeclaredElement;
                if (containingMember != null)
                {
                    return(myClrSearchFactory.GetDeclaredElementSearchDomain(containingMember));
                }
            }

            if (declaredElement is CompiledActivePatternCase compiledActivePatternCase)
            {
                return(myClrSearchFactory.GetDeclaredElementSearchDomain(compiledActivePatternCase.Origin));
            }

            if (declaredElement is IFSharpAnonRecordFieldProperty fieldProperty)
            {
                return(mySearchDomainFactory.CreateSearchDomain(fieldProperty.Module));
            }

            return(EmptySearchDomain.Instance);
        }
示例#2
0
        public override Tuple <ICollection <IDeclaredElement>, bool> GetNavigateToTargets(IDeclaredElement element)
        {
            if (element is ResolvedFSharpSymbolElement resolvedSymbolElement &&
                resolvedSymbolElement.Symbol is FSharpActivePatternCase activePatternCase)
            {
                var activePattern = activePatternCase.Group;

                var entityOption      = activePattern.DeclaringEntity;
                var patternNameOption = activePattern.Name;
                if (entityOption == null || patternNameOption == null)
                {
                    return(null);
                }

                var typeElement = FSharpElementsUtil.GetTypeElement(entityOption.Value, resolvedSymbolElement.Module);
                var pattern     = typeElement.EnumerateMembers(patternNameOption.Value, true).FirstOrDefault() as IDeclaredElement;
                if (pattern is IFSharpTypeMember)
                {
                    if (!(pattern.GetDeclarations().FirstOrDefault() is IFSharpDeclaration patternDecl))
                    {
                        return(null);
                    }

                    var caseElement = patternDecl.GetActivePatternByIndex(activePatternCase.Index);
                    if (caseElement != null)
                    {
                        return(CreateTarget(caseElement));
                    }
                }
                else if (pattern != null)
                {
                    return(CreateTarget(pattern));
                }
            }

            if (element is IFSharpGeneratedFromOtherElement generated && generated.OriginElement is IDeclaredElement origin)
            {
                return(CreateTarget(origin));
            }

            if (!(element is IFSharpTypeMember fsTypeMember) || fsTypeMember.CanNavigateTo)
            {
                return(null);
            }

            return(fsTypeMember.GetContainingType() is IDeclaredElement containingType
        ? CreateTarget(containingType)
        : null);
        }
        public Tuple <ICollection <IDeclaredElement>, bool> GetNavigateToTargets(IDeclaredElement element)
        {
            // todo: for union cases navigate to case declarations

            var resolvedSymbolElement = element as ResolvedFSharpSymbolElement;

            if (resolvedSymbolElement?.Symbol is FSharpActivePatternCase activePatternCase)
            {
                var activePattern = activePatternCase.Group;

                var entityOption      = activePattern.DeclaringEntity;
                var patternNameOption = activePattern.Name;
                if (entityOption == null || patternNameOption == null)
                {
                    return(null);
                }

                var typeElement = FSharpElementsUtil.GetTypeElement(entityOption.Value, resolvedSymbolElement.Module);
                var pattern     = typeElement.EnumerateMembers(patternNameOption.Value, true).FirstOrDefault() as IDeclaredElement;
                if (pattern is IFSharpTypeMember)
                {
                    var patternDecl = pattern.GetDeclarations().FirstOrDefault();
                    if (patternDecl == null)
                    {
                        return(null);
                    }

                    var caseElement = FSharpImplUtil.GetActivePatternByIndex(patternDecl, activePatternCase.Index);
                    if (caseElement != null)
                    {
                        return(Tuple.Create(new[] { caseElement }.AsCollection(), false));
                    }
                }
                else if (pattern != null)
                {
                    return(Tuple.Create(new[] { pattern }.AsCollection(), false));
                }
            }

            if (!(element is IFSharpTypeMember fsTypeMember) || fsTypeMember.IsVisibleFromFSharp)
            {
                return(null);
            }

            return(fsTypeMember.GetContainingType() is IDeclaredElement containingType
        ? Tuple.Create(new[] { containingType }.AsCollection(), false)
        : null);
        }
        public override ResolveResultWithInfo ResolveWithoutCache()
        {
            if (!myOwner.IsValid())
            {
                return(ResolveResultWithInfo.Ignore);
            }

            var symbol  = GetSymbolUse()?.Symbol;
            var element = symbol != null
        ? FSharpElementsUtil.GetDeclaredElement(symbol, myOwner.GetPsiModule(), myOwner)
        : null;

            return(element != null
        ? new ResolveResultWithInfo(new SimpleResolveResult(element), ResolveErrorType.OK) // todo: add substitutions
        : ResolveResultWithInfo.Ignore);
        }
        public override ISearchDomain GetDeclaredElementSearchDomain(IDeclaredElement declaredElement)
        {
            // todo: type abbreviations
            if (declaredElement is ILocalDeclaration localDeclaration)
            {
                return(mySearchDomainFactory.CreateSearchDomain(localDeclaration.GetSourceFile()));
            }

            if (declaredElement is IFSharpSymbolElement fsSymbolElement)
            {
                var fsSymbol = fsSymbolElement.Symbol;
                if (!(fsSymbol is FSharpActivePatternCase activePatternCase))
                {
                    return(EmptySearchDomain.Instance);
                }

                if (fsSymbolElement is ResolvedFSharpSymbolElement)
                {
                    var patternEntity = activePatternCase.Group.DeclaringEntity?.Value;
                    if (patternEntity != null)
                    {
                        var patternTypeElement = FSharpElementsUtil.GetDeclaredElement(patternEntity, fsSymbolElement.Module);
                        if (patternTypeElement == null)
                        {
                            return(EmptySearchDomain.Instance);
                        }

                        return(myClrSearchFactory.GetDeclaredElementSearchDomain(patternTypeElement));
                    }
                }

                if (fsSymbolElement is ActivePatternCase activePatternCaseElement)
                {
                    var declaration    = activePatternCaseElement.GetDeclaration();
                    var containingType = ((ITypeDeclaration)declaration?.GetContainingTypeDeclaration())?.DeclaredElement;
                    if (containingType != null)
                    {
                        return(myClrSearchFactory.GetDeclaredElementSearchDomain(containingType));
                    }
                }
            }

            return(EmptySearchDomain.Instance);
        }
        public override ResolveResultWithInfo ResolveWithoutCache()
        {
            if (!myOwner.IsValid())
            {
                return(ResolveResultWithInfo.Ignore);
            }

            var psiModule = myOwner.GetPsiModule();
            var offset    = myOwner.GetTreeStartOffset().Offset;
            var symbol    = (myOwner.GetContainingFile() as IFSharpFile)?.GetSymbolUse(offset);

            var element = symbol != null
        ? FSharpElementsUtil.GetDeclaredElement(symbol, psiModule, myOwner)
        : null;

            return(element != null
        ? new ResolveResultWithInfo(new SimpleResolveResult(element), ResolveErrorType.OK) // todo: add substitutions
        : ResolveResultWithInfo.Ignore);
        }