public static IDeclaredElement GetOwner([NotNull] this FSharpParameter fsParameter,
                                                [NotNull] FSharpSymbolReference reference)
        {
            var referenceOwner = reference.GetElement();

            if (referenceOwner is IReferenceExpr referenceExpr)
            {
                var infixAppExpr = BinaryAppExprNavigator.GetByLeftArgument(referenceExpr);
                if (!(infixAppExpr?.Operator is { ShortName : "=" }))
Esempio n. 2
0
        public static IDeclaredElement GetOwner([NotNull] this FSharpParameter fsParameter,
                                                [NotNull] FSharpSymbolReference reference)
        {
            var referenceOwner = reference.GetElement();

            if (referenceOwner is IReferenceExpr referenceExpr)
            {
                var infixAppExpr = BinaryAppExprNavigator.GetByLeftArgument(referenceExpr);

                if (!(infixAppExpr?.Operator is var funExpr) || funExpr?.GetText() != "=")
                {
                    return(null);
                }

                var innerExpr = (IFSharpExpression)TupleExprNavigator.GetByExpression(infixAppExpr) ?? infixAppExpr;
                var parenExpr = ParenExprNavigator.GetByInnerExpression(innerExpr);

                if (!(PrefixAppExprNavigator.GetByArgumentExpression(parenExpr)?.FunctionExpression is IReferenceExpr expr))
                {
                    return(null);
                }

                var fsSymbol = expr.Reference.GetFSharpSymbol();
                switch (fsSymbol)
                {
                case FSharpUnionCase unionCase:
                    return(GetFieldDeclaredElement(reference, unionCase, referenceOwner));

                case FSharpMemberOrFunctionOrValue mfv:
                    // todo: fix member param declarations
                    return(mfv.GetDeclaredElement(referenceOwner.GetPsiModule(), referenceOwner) is IFunction functionElement
              ? functionElement.Parameters.FirstOrDefault(p => p.ShortName == reference.GetName())
              : null);
                }
            }

            if (referenceOwner is IExpressionReferenceName referenceName)
            {
                var fieldPat           = FieldPatNavigator.GetByReferenceName(referenceName);
                var parametersOwnerPat = ParametersOwnerPatNavigator.GetByParameter(fieldPat);
                if (parametersOwnerPat == null)
                {
                    return(null);
                }

                return(parametersOwnerPat.ReferenceName.Reference.GetFSharpSymbol() is FSharpUnionCase unionCase
          ? GetFieldDeclaredElement(reference, unionCase, referenceOwner)
          : null);
            }

            return(null);
        }