Ejemplo n.º 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);
        }
        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);
        }