public ALanguageSignature(ITextView view, int start, int length, ALanguageSignatureInfo info)
        {
            m_view           = view;
            ApplicableToSpan = view.TextSnapshot.CreateTrackingSpan(start, length, SpanTrackingMode.EdgeInclusive);

            string content    = "";
            var    parameters = new List <IParameter>();

            for (int i = 0; i < info.param_list.Count; ++i)
            {
                var param = info.param_list[i];

                int pos = content.Length;
                content += param.name;
                parameters.Add(new ALanguageParameter(param.documentation, new Span(pos, param.name.Length), param.name, this));
                if (i + 1 < info.param_list.Count)
                {
                    content += ", ";
                }
            }
            Content = content;
            PrettyPrintedContent = content;
            Parameters           = new ReadOnlyCollection <IParameter>(parameters);

            view.TextBuffer.Changed    += OnTextBufferChanged;
            view.Caret.PositionChanged += OnCaretChanged;
            view.Closed += OnClosed;
            if (view.Properties.ContainsProperty(nameof(ALanguageSignature)))
            {
                view.Properties.RemoveProperty(nameof(ALanguageSignature));
            }
            view.Properties.AddProperty(nameof(ALanguageSignature), this);
            ReCalcSignature();
        }
 public void RefreshSignatureHelp(ITextView view, int start, int length, ALanguageSignatureInfo info)
 {
     m_signature = null;
     if (info == null)
     {
         return;
     }
     m_signature = new ALanguageSignature(view, start, length, info);
 }
        public override ALanguageSignatureInfo QuerySignatureHelp(out int start, out int length)
        {
            start  = 0;
            length = 0;
            ABnfElement parent = m_element;

            while (parent != null)
            {
                if (parent is ALittleScriptPropertyValueMethodCallElement)
                {
                    var refe = parent.GetReference() as ALittleScriptPropertyValueMethodCallReference;
                    if (refe == null)
                    {
                        return(null);
                    }

                    var error = refe.GuessPreType(out ABnfGuess guess);
                    if (error != null)
                    {
                        return(null);
                    }

                    var guess_functor = guess as ALittleScriptGuessFunctor;
                    if (guess_functor == null)
                    {
                        return(null);
                    }

                    var info = new ALanguageSignatureInfo();
                    for (int i = 0; i < guess_functor.param_name_list.Count; ++i)
                    {
                        string type = "";
                        if (i < guess_functor.param_nullable_list.Count && guess_functor.param_nullable_list[i])
                        {
                            type = "[Nullable] ";
                        }
                        if (i < guess_functor.param_list.Count)
                        {
                            type += guess_functor.param_list[i].GetValue();
                        }

                        var param = new ALanguageParameterInfo();
                        param.name = type + " " + guess_functor.param_name_list[i];

                        info.param_list.Add(param);
                    }
                    if (guess_functor.param_tail != null)
                    {
                        var param = new ALanguageParameterInfo();
                        param.name = guess_functor.param_tail.GetValue();

                        info.param_list.Add(param);
                    }

                    start  = parent.GetStart();
                    length = parent.GetLengthWithoutError();
                    var method_call = parent as ALittleScriptPropertyValueMethodCallElement;
                    var string_list = method_call.GetStringList();
                    if (string_list.Count > 1)
                    {
                        start  = string_list[0].GetStart();
                        length = parent.GetLength() - (string_list[0].GetStart() - parent.GetStart()) - 1;
                    }
                    return(info);
                }
                else if (parent is ALittleScriptOpNewStatElement)
                {
                    var custom_type = (parent as ALittleScriptOpNewStatElement).GetCustomType();
                    if (custom_type == null)
                    {
                        return(null);
                    }

                    var error = custom_type.GuessType(out ABnfGuess guess);
                    if (error != null)
                    {
                        return(null);
                    }

                    if (guess is ALittleScriptGuessTemplate)
                    {
                        var guess_template = guess as ALittleScriptGuessTemplate;
                        if (guess_template.template_extends != null)
                        {
                            guess = guess_template.template_extends;
                        }
                    }

                    if (guess is ALittleScriptGuessClass)
                    {
                        var class_dec = ((ALittleScriptGuessClass)guess).class_dec;
                        var ctor      = ALittleScriptUtility.FindFirstCtorDecFromExtends(class_dec, 100);
                        if (ctor == null)
                        {
                            return(null);
                        }

                        var param_dec = ctor.GetMethodParamDec();
                        if (param_dec == null)
                        {
                            return(null);
                        }

                        var param_one_dec_list = param_dec.GetMethodParamOneDecList();
                        if (param_one_dec_list.Count == 0)
                        {
                            return(null);
                        }

                        var info = new ALanguageSignatureInfo();
                        for (int i = 0; i < param_one_dec_list.Count; ++i)
                        {
                            var param_one_dec = param_one_dec_list[i];
                            var tail_dec      = param_one_dec.GetMethodParamTailDec();
                            if (tail_dec != null)
                            {
                                var param_info = new ALanguageParameterInfo();
                                param_info.name = tail_dec.GetElementText();
                                info.param_list.Add(param_info);
                                continue;
                            }

                            var nullable = ALittleScriptUtility.IsNullable(param_one_dec.GetModifierList());

                            var all_type = param_one_dec.GetAllType();
                            if (all_type == null)
                            {
                                return(null);
                            }

                            error = all_type.GuessType(out ABnfGuess all_type_guess);
                            if (error != null)
                            {
                                return(null);
                            }

                            var param = new ALanguageParameterInfo();
                            param.name = all_type_guess.GetValue();
                            if (param_one_dec.GetMethodParamNameDec() != null)
                            {
                                if (nullable)
                                {
                                    param.name += " [Nullable]";
                                }
                                param.name += " " + param_one_dec.GetMethodParamNameDec().GetElementText();
                            }

                            info.param_list.Add(param);
                        }

                        start  = parent.GetStart();
                        length = parent.GetLengthWithoutError();
                        var new_stat    = parent as ALittleScriptOpNewStatElement;
                        var string_list = new_stat.GetStringList();
                        if (string_list.Count > 1)
                        {
                            start  = string_list[0].GetStart();
                            length = parent.GetLength() - (string_list[0].GetStart() - parent.GetStart()) - 1;
                        }
                        return(info);
                    }
                    return(null);
                }

                if (parent is ALittleScriptMethodBodyDecElement)
                {
                    return(null);
                }
                if (parent is ALittleScriptAllExprElement)
                {
                    return(null);
                }

                parent = parent.GetParent();
            }

            return(null);
        }