Пример #1
0
        internal IIntellisenseResult Suggest(string expression, FormulaType parameterType, int cursorPosition)
        {
            var formula = new Formula(expression);

            formula.EnsureParsed(TexlParser.Flags.None);

            var binding = TexlBinding.Run(
                new Glue2DocumentBinderGlue(),
                formula.ParseTree,
                new SimpleResolver(EnumStore.EnumSymbols),
                ruleScope: parameterType._type,
                useThisRecordForRuleScope: false
                );

            var context      = new IntellisenseContext(expression, cursorPosition);
            var intellisense = IntellisenseProvider.GetIntellisense();
            var suggestions  = intellisense.Suggest(context, binding, formula);

            if (suggestions.Exception != null)
            {
                throw suggestions.Exception;
            }

            return(suggestions);
        }
Пример #2
0
        private CheckResult CheckInternal(string expressionText, FormulaType parameterType = null, bool intellisense = false)
        {
            if (parameterType == null)
            {
                parameterType = new RecordType();
            }

            var formula = new Formula(expressionText);

            formula.EnsureParsed(TexlParser.Flags.None);

            // Ok to continue with binding even if there are parse errors.
            // We can still use that for intellisense.

            var extraFunctions = _extraFunctions.Values.ToArray();

            var resolver = new RecalcEngineResolver(this, (RecordType)parameterType, EnumStore.EnumSymbols, extraFunctions);

            // $$$ - intellisense only works with ruleScope.
            // So if running for intellisense, pass the parameters in ruleScope.
            // But if running for eval, let the resolver handle the parameters.
            // Resolver is only invoked if not in RuleScope.

            var binding = TexlBinding.Run(
                new Glue2DocumentBinderGlue(),
                formula.ParseTree,
                resolver,
                ruleScope: intellisense ? parameterType._type : null,
                useThisRecordForRuleScope: false
                );

            var errors = (formula.HasParseErrors) ? formula.GetParseErrors() : binding.ErrorContainer.GetErrors();

            var result = new CheckResult
            {
                _binding = binding,
                _formula = formula,
            };

            if (errors != null && errors.Any())
            {
                result.SetErrors(errors.ToArray());
            }
            else
            {
                result.TopLevelIdentifiers = DependencyFinder.FindDependencies(binding.Top, binding);
                // TODO: Fix FormulaType.Build to not throw exceptions for Enum types then remove this check
                if (binding.ResultType.Kind != DKind.Enum)
                {
                    result.ReturnType = FormulaType.Build(binding.ResultType);
                }
            }

            return(result);
        }