Exemplo n.º 1
0
        public IntellisenseData(IIntellisenseContext context, DType expectedType, TexlBinding binding, TexlFunction curFunc, TexlNode curNode, int argIndex, int argCount, IsValidSuggestion isValidSuggestionFunc, IList <DType> missingTypes, List <CommentToken> comments)
        {
            Contracts.AssertValue(context);
            Contracts.AssertValid(expectedType);
            Contracts.AssertValue(binding);
            Contracts.AssertValue(curNode);
            Contracts.Assert(0 <= context.CursorPosition && context.CursorPosition <= context.InputText.Length);
            Contracts.AssertValue(isValidSuggestionFunc);
            Contracts.AssertValueOrNull(missingTypes);
            Contracts.AssertValueOrNull(comments);

            _expectedType         = expectedType;
            _suggestions          = new IntellisenseSuggestionList();
            _substringSuggestions = new IntellisenseSuggestionList();
            _binding               = binding;
            _comments              = comments;
            _curFunc               = curFunc;
            _curNode               = curNode;
            _script                = context.InputText;
            _cursorPos             = context.CursorPosition;
            _argIndex              = argIndex;
            _argCount              = argCount;
            _isValidSuggestionFunc = isValidSuggestionFunc;
            _matchingStr           = string.Empty;
            _matchingLength        = 0;
            _replacementStartIndex = context.CursorPosition;
            _missingTypes          = missingTypes;
            BoundTo                = string.Empty;
            _cleanupHandlers       = new List <ISpecialCaseHandler>();
        }
Exemplo n.º 2
0
        public InOpDelegationStrategy(BinaryOpNode node, TexlFunction function) : base(BinaryOp.In, function)
        {
            Contracts.AssertValue(node);
            Contracts.Assert(node.Op == BinaryOp.In);

            _binaryOpNode = node;
        }
Exemplo n.º 3
0
        public UnaryOpDelegationStrategy(UnaryOp op, TexlFunction function)
            : base(function)
        {
            Contracts.AssertValue(function);

            _unaryOp  = op;
            _function = function;
        }
Exemplo n.º 4
0
 /// <summary>
 /// No-op, default Intellisense does not augment signatures at this stage.
 /// </summary>
 /// <param name="newHighlightStart">
 /// 0 when this method returns
 /// </param>
 /// <param name="newHighlightEnd">
 /// 0 when this method returns
 /// </param>
 /// <param name="newParamName">
 /// <see cref="string.Empty"/> when this method returns
 /// </param>
 /// <param name="newInvariantParamName">
 /// <see cref="string.Empty"/> when this method returns
 /// </param>
 /// <returns>
 /// False
 /// </returns>
 public static bool DefaultTryAugmentSignature(TexlFunction func, int argIndex, string paramName, int highlightStart, out int newHighlightStart, out int newHighlightEnd, out string newParamName, out string newInvariantParamName)
 {
     newHighlightStart     = 0;
     newHighlightEnd       = 0;
     newParamName          = string.Empty;
     newInvariantParamName = string.Empty;
     return(false);
 }
Exemplo n.º 5
0
        public CallInfo(TexlFunction function, CallNode node)
        {
            Contracts.AssertValue(function);
            Contracts.AssertValue(node);

            Function = function;
            Node     = node;
        }
Exemplo n.º 6
0
        public CallNode(IRContext irContext, TexlFunction func, IList <IntermediateNode> args) : base(irContext)
        {
            Contracts.AssertValue(func);
            Contracts.AssertAllValues(args);

            Function = func;
            Args     = args.ToList();
        }
Exemplo n.º 7
0
 public FunctionScopeInfo(TexlFunction function, bool usesAllFieldsInScope = true, bool supportsAsyncLambdas = true, bool acceptsLiteralPredicates = true, bool iteratesOverScope = true, DType scopeType = null, Func <int, bool> appliesToArgument = null)
 {
     this.UsesAllFieldsInScope     = usesAllFieldsInScope;
     this.SupportsAsyncLambdas     = supportsAsyncLambdas;
     this.AcceptsLiteralPredicates = acceptsLiteralPredicates;
     this.IteratesOverScope        = iteratesOverScope;
     this.ScopeType         = scopeType;
     this._function         = function;
     this.AppliesToArgument = appliesToArgument ?? (i => i > 0);
 }
Exemplo n.º 8
0
        public CallInfo(TexlFunction function, CallNode node, Object data)
        {
            Contracts.AssertValue(function);
            Contracts.AssertValue(node);
            Contracts.AssertValueOrNull(data);

            Function = function;
            Node     = node;
            Data     = data;
        }
Exemplo n.º 9
0
        // 1. For a function with limited MaxArity, The first time the count becomes equal to the argIndex, that's the arg we want to highlight
        // 2. For variadic function with repeating params in the signature, we highlight the param which indicates the corresponding position.
        internal bool ArgNeedsHighlight(TexlFunction func, int argCount, int argIndex, int signatureCount, int signatureIndex)
        {
            Contracts.AssertValue(func);

            if (func.SignatureConstraint == null || argCount <= func.SignatureConstraint.RepeatTopLength || signatureIndex <= func.SignatureConstraint.OmitStartIndex)
            {
                return(signatureIndex == argIndex);
            }

            return(func.SignatureConstraint.ArgNeedsHighlight(argCount, argIndex, signatureCount, signatureIndex));
        }
Exemplo n.º 10
0
        // GroupBy(source, column_name, column_name, ..., column_name, ..., group_name, ...)
        // AddColumns(source, column, expression, column, expression, ..., column, expression, ...)
        internal bool canParamOmit(TexlFunction func, int argCount, int argIndex, int signatureCount, int signatureIndex)
        {
            Contracts.AssertValue(func);
            Contracts.Assert(func.MaxArity == int.MaxValue);
            Contracts.Assert(func.SignatureConstraint != null && argCount > func.SignatureConstraint.RepeatTopLength && signatureCount >= func.SignatureConstraint.RepeatTopLength);

            if (func.SignatureConstraint == null)
            {
                return(false);
            }

            return(func.SignatureConstraint.canParamOmit(argCount, argIndex, signatureCount, signatureIndex));
        }
Exemplo n.º 11
0
        public CallInfo(TexlFunction function, CallNode node, DType cursorType, DName scopeIdentifier, bool requiresScopeIdentifier, int scopeNest)
        {
            Contracts.AssertValue(function);
            Contracts.AssertValue(node);
            Contracts.Assert(scopeNest >= 0);

            Function                = function;
            Node                    = node;
            CursorType              = cursorType;
            ScopeNest               = scopeNest;
            ScopeIdentifier         = scopeIdentifier;
            RequiresScopeIdentifier = requiresScopeIdentifier;
        }
Exemplo n.º 12
0
            private DType GetAggregateType(TexlFunction func, CallNode callNode, IntellisenseData.IntellisenseData intellisenseData)
            {
                Contracts.AssertValue(func);
                Contracts.AssertValue(callNode);
                Contracts.AssertValue(intellisenseData);

                if (intellisenseData.TryGetSpecialFunctionType(func, callNode, out var type))
                {
                    return(type);
                }

                return(intellisenseData.Binding.GetType(callNode.Args.Children[0]));
            }
Exemplo n.º 13
0
        public static void LogTelemetryForFunction(TexlFunction function, CallNode node, TexlBinding texlBinding,
                                                   bool isServerDelegatable)
        {
            Contracts.AssertValue(function);
            Contracts.AssertValue(node);
            Contracts.AssertValue(texlBinding);

            // We only want to log about successful delegation status here. Any failures should have been logged by this time.
            if (isServerDelegatable)
            {
                DelegationTrackerCore.SetDelegationTrackerStatus(DelegationStatus.DelegationSuccessful, node, texlBinding, function);
                return;
            }
        }
Exemplo n.º 14
0
        public DelegationTrackerEventArgs(DelegationStatus status, TexlNode node,
                                          TexlBinding binding, TexlFunction func, DelegationTelemetryInfo logInfo = null)
        {
            Contracts.AssertValue(node);
            Contracts.AssertValue(binding);
            Contracts.AssertValueOrNull(func);
            Contracts.AssertValueOrNull(logInfo);

            Status  = status;
            Node    = node;
            Binding = binding;
            Func    = func;
            LogInfo = logInfo;
        }
Exemplo n.º 15
0
        public IntellisenseSuggestion(TexlFunction function, string exactMatch, UIString displayText)
            : this(displayText, SuggestionKind.Function, SuggestionIconKind.Function, function.VerifyValue().ReturnType, exactMatch, -1, function.Description, function.VerifyValue().Name, 0)
        {
            Contracts.AssertValue(function);

            foreach (var signature in function.GetSignatures())
            {
                int           count             = 0;
                string        argumentSeparator = "";
                string        listSep           = TexlLexer.LocalizedInstance.LocalizedPunctuatorListSeparator + " ";
                StringBuilder funcDisplayString = new StringBuilder(Text);
                funcDisplayString.Append('(');
                foreach (var arg in signature)
                {
                    funcDisplayString.Append(argumentSeparator);
                    funcDisplayString.Append(arg(null));
                    argumentSeparator = listSep;
                    count++;
                }
                funcDisplayString.Append(')');
                _overloads.Add(new IntellisenseSuggestion(new UIString(funcDisplayString.ToString()), SuggestionKind.Function, SuggestionIconKind.Function, function.VerifyValue().ReturnType, exactMatch, count, function.Description, function.Name, 0));
            }
        }
Exemplo n.º 16
0
 public virtual bool TryAugmentSignature(TexlFunction func, int argIndex, string paramName, int highlightStart, out int newHighlightStart, out int newHighlightEnd, out string newParamName, out string newInvariantParamName) =>
 DefaultIntellisenseData.DefaultTryAugmentSignature(func, argIndex, paramName, highlightStart, out newHighlightStart, out newHighlightEnd, out newParamName, out newInvariantParamName);
Exemplo n.º 17
0
        /// <summary>
        /// Returns a list of argument suggestions for a given function, scope type, and argument index
        /// </summary>
        /// <param name="function">
        /// The function for which we are producing argument suggestions
        /// </param>
        /// <param name="scopeType">
        /// The type of the scope from where intellisense is run
        /// </param>
        /// <param name="argumentIndex">
        /// The index of the current argument of <see cref="function"/>
        /// </param>
        /// <param name="argsSoFar">
        /// The arguments that are present in the formula at the time of invocation
        /// </param>
        /// <param name="requiresSuggestionEscaping">
        /// Is set to whether the characters within the returned suggestion need have its characters escaped
        /// </param>
        /// <returns>
        /// Argument suggestions for the provided context
        /// </returns>
        internal virtual IEnumerable <KeyValuePair <string, DType> > GetArgumentSuggestions(TexlFunction function, DType scopeType, int argumentIndex, TexlNode[] argsSoFar, out bool requiresSuggestionEscaping)
        {
            Contracts.AssertValue(function);
            Contracts.AssertValue(scopeType);

            return(ArgumentSuggestions.GetArgumentSuggestions(TryGetEnumSymbol, SuggestUnqualifiedEnums, function, scopeType, argumentIndex, out requiresSuggestionEscaping));
        }
Exemplo n.º 18
0
 /// <summary>
 /// Should return the kind of suggestion that may be recomended for the
 /// <see cref="argumentIndex"/> parameter of <see cref="function"/>
 /// </summary>
 /// <param name="function">
 /// Function that the kind of suggestion for which this function determines
 /// </param>
 /// <param name="argumentIndex">
 /// The index of the argument to which the suggestion pertains
 /// </param>
 /// <returns>
 /// The suggestion kind for the hypothetical suggestion
 /// </returns>
 internal virtual SuggestionKind GetFunctionSuggestionKind(TexlFunction function, int argumentIndex) => SuggestionKind.Global;
Exemplo n.º 19
0
        private void GetFunctionAndTypeInformation(IIntellisenseContext context, TexlNode curNode, TexlBinding binding, out TexlFunction curFunc, out int argIndex, out int argCount, out DType expectedType, out IsValidSuggestion isValidSuggestionFunc)
        {
            Contracts.AssertValue(context);
            Contracts.AssertValue(curNode);
            Contracts.AssertValue(binding);

            if (!FindCurFuncAndArgs(curNode, context.CursorPosition, binding, out curFunc, out argIndex, out argCount, out expectedType))
            {
                curFunc      = null;
                argIndex     = 0;
                argCount     = 0;
                expectedType = DType.Unknown;
            }

            DType binaryOpExpectedType;

            if (TryGetExpectedTypeForBinaryOp(binding, curNode, context.CursorPosition, out binaryOpExpectedType))
            {
                expectedType = binaryOpExpectedType;
            }

            if (curFunc != null)
            {
                isValidSuggestionFunc = (intellisenseData, suggestion) => intellisenseData.CurFunc.IsSuggestionTypeValid(intellisenseData.ArgIndex, suggestion.Type);
            }
            else
            {
                isValidSuggestionFunc = Helper.DefaultIsValidSuggestionFunc;
            }
        }
Exemplo n.º 20
0
 protected internal virtual IntellisenseData.IntellisenseData CreateData(IIntellisenseContext context, DType expectedType, TexlBinding binding, TexlFunction curFunc, TexlNode curNode, int argIndex, int argCount, IsValidSuggestion isValidSuggestionFunc, IList <DType> missingTypes, List <CommentToken> comments)
 {
     return(new IntellisenseData.IntellisenseData(context, expectedType, binding, curFunc, curNode, argIndex, argCount, isValidSuggestionFunc, missingTypes, comments));
 }
Exemplo n.º 21
0
        public static bool FindCurFuncAndArgs(TexlNode curNode, int cursorPos, TexlBinding binding, out TexlFunction curFunc, out int argIndex, out int argCount, out DType expectedType)
        {
            Contracts.AssertValue(curNode);
            Contracts.AssertValue(binding);

            if (curNode.Kind == NodeKind.Call)
            {
                CallNode callNode = curNode.CastCall();
                if (callNode.Token.Span.Lim <= cursorPos && callNode.ParenClose != null && cursorPos <= callNode.ParenClose.Span.Min)
                {
                    CallInfo info = binding.GetInfo(callNode);

                    if (info.Function != null)
                    {
                        curFunc      = info.Function;
                        argIndex     = 0;
                        argCount     = callNode.Args.Count;
                        expectedType = curFunc.ParamTypes.Length > 0 ? curFunc.ParamTypes[0] : DType.Error;

                        return(true);
                    }
                }
            }

            if (IntellisenseHelper.TryGetInnerMostFunction(curNode, binding, out curFunc, out argIndex, out argCount))
            {
                expectedType = curFunc.ParamTypes.Length > argIndex ? curFunc.ParamTypes[argIndex] : DType.Error;
                return(true);
            }

            expectedType = DType.Error;
            return(false);
        }
Exemplo n.º 22
0
        public static DelegationTelemetryInfo CreateUndelegatableFunctionTelemetryInfo(TexlFunction func)
        {
            Contracts.AssertValueOrNull(func);

            if (func == null)
            {
                return(CreateEmptyDelegationTelemetryInfo());
            }

            return(new DelegationTelemetryInfo(func.Name));
        }
Exemplo n.º 23
0
 public bool IsComponentScopedPropertyFunction(TexlFunction infoFunction)
 {
     return(false); // $$$
 }
Exemplo n.º 24
0
        // Gets the inner most function and the current arg index from the current node, if any.
        // If there is no inner most function, current arg index will be -1
        // and argument count will be -1.
        internal static bool TryGetInnerMostFunction(TexlNode nodeCur, TexlBinding bind, out TexlFunction funcCur, out int iarg, out int carg)
        {
            Contracts.AssertValue(nodeCur);
            Contracts.AssertValue(bind);

            TexlNode nodeParent  = nodeCur.Parent;
            TexlNode nodeCallArg = nodeCur;
            CallNode callNode    = null;

            while (nodeParent != null)
            {
                if (nodeParent.Kind == NodeKind.Call)
                {
                    callNode = nodeParent.AsCall();
                    break;
                }
                // The last node before a call's list node is the call arg.
                if (nodeParent.Kind != NodeKind.List)
                {
                    nodeCallArg = nodeParent;
                }

                nodeParent = nodeParent.Parent;
            }

            if (callNode == null)
            {
                iarg    = -1;
                carg    = -1;
                funcCur = null;
                return(false);
            }

            Contracts.AssertValue(nodeCallArg);

            CallInfo info = bind.GetInfo(callNode);

            if (info.Function != null)
            {
                carg = callNode.Args.Count;
                for (iarg = 0; iarg < carg; iarg++)
                {
                    if (callNode.Args.Children[iarg] == nodeCallArg)
                    {
                        break;
                    }
                }
                Contracts.Assert(iarg < carg);
                funcCur = (TexlFunction)info.Function;
                return(true);
            }

            iarg    = -1;
            carg    = -1;
            funcCur = null;
            return(false);
        }
Exemplo n.º 25
0
 /// <param name="function">
 /// Function whose eligibility is called into question.
 /// </param>
 /// <returns>
 /// Returns true if <see cref="Intellisense.FunctionRecordNameSuggestionHandler"/> should make suggestions
 /// for the provided function and false otherwise.
 /// </returns>
 internal virtual bool IsFunctionElligibleForRecordSuggestions(TexlFunction function) => true;
Exemplo n.º 26
0
 /// <param name="function">
 /// Function in question
 /// </param>
 /// <param name="callNode">
 /// The node at the present cursor position
 /// </param>
 /// <param name="type">
 /// If overridden, may be set to a custom function type when returns.
 /// </param>
 /// <returns>
 /// True if a special type was found and type is set, false otherwise.
 /// </returns>
 internal virtual bool TryGetSpecialFunctionType(TexlFunction function, CallNode callNode, out DType type)
 {
     type = null;
     return(false);
 }
Exemplo n.º 27
0
 /// <summary>
 /// This method may be overridden to provide additional suggestions for function record names after
 /// the default have been added.  It should return true if intellisenseData is handled and no more
 /// suggestions are to be found and false otherwise.
 /// </summary>
 internal virtual bool TryAddFunctionRecordSuggestions(TexlFunction function, CallNode callNode, Identifier columnName) => false;
Exemplo n.º 28
0
 /// <summary>
 /// This method is called by <see cref="Intellisense.ErrorNodeSuggestionHandlerBase"/> if function was
 /// discovered as a parent node to the current error node.  It may be overridden to add additional
 /// suggestions pertaining to <see cref="function"/> and <see cref="argIndex"/>.  If it returns true,
 /// <see cref="Intellisense.ErrorNodeSuggestionHandlerBase"/> will return immediately and no more suggestions
 /// will be added.
 /// </summary>
 /// <param name="function">
 /// Function for which additional suggestions may be added
 /// </param>
 /// <param name="argIndex">
 /// Index of the argument on which the cursor is positioned
 /// </param>
 /// <returns>
 /// True if all suggestions have been added and no more should be.  False otherwise.
 /// </returns>
 internal virtual bool TryAddCustomFunctionSuggestionsForErrorNode(TexlFunction function, int argIndex) => false;
Exemplo n.º 29
0
        public CallNode(IRContext irContext, TexlFunction func, ScopeSymbol scope, IList <IntermediateNode> args) : this(irContext, func, args)
        {
            Contracts.AssertValue(scope);

            Scope = scope;
        }
Exemplo n.º 30
0
 public virtual string GenerateParameterDescriptionSuffix(TexlFunction function, string paramName) =>
 DefaultIntellisenseData.GenerateDefaultParameterDescriptionSuffix(function, paramName);