Ejemplo n.º 1
0
        protected static IEnumerable<CompletionInfo> GetCompletions(IDjangoCompletionContext context, int position, DjangoVariable[] variables, int max = Int32.MaxValue) {
            for (int i = 0; i < variables.Length; i++) {
                if (position >= variables[i].ExpressionStart &&
                    (i == variables.Length - 1 || position < variables[i + 1].ExpressionStart)) {
                    var res = variables[i].GetCompletions(context, position);
                    if (res.Count() != 0) {
                        return res;
                    }
                }
            }

            if (variables.Length < max) {
                var vars = context.Variables;
                if (vars != null) {
                    return CompletionInfo.ToCompletionInfo(vars.Keys, StandardGlyphGroup.GlyphGroupField);
                }
            }

            return new CompletionInfo[0];
        }
        public IEnumerable <CompletionInfo> GetCompletions(IDjangoCompletionContext context, int position)
        {
            if (Expression == null)
            {
                return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField));
            }
            else if (position <= Expression.Value.Length + ExpressionStart)
            {
                if (position - ExpressionStart - 1 >= 0 &&
                    Expression.Value[position - ExpressionStart - 1] == '.')
                {
                    // TODO: Handle multiple dots
                    string varName = Expression.Value.Substring(0, Expression.Value.IndexOf('.'));

                    // get the members of this variable
                    HashSet <AnalysisValue> values;
                    if (context.Variables != null && context.Variables.TryGetValue(varName, out values))
                    {
                        var newTags = new Dictionary <string, PythonMemberType>();
                        foreach (var member in values.SelectMany(item => item.GetAllMembers(context.ModuleContext)))
                        {
                            string           name = member.Key;
                            PythonMemberType type, newType = GetMemberType(member.Value);

                            if (!newTags.TryGetValue(name, out type))
                            {
                                newTags[name] = newType;
                            }
                            else if (type != newType && type != PythonMemberType.Unknown && newType != PythonMemberType.Unknown)
                            {
                                newTags[name] = PythonMemberType.Multiple;
                            }
                        }
                        return(CompletionInfo.ToCompletionInfo(newTags));
                    }
                }
                else
                {
                    return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField));
                }
            }
            else if (Filters.Length > 0)
            {
                // we are triggering in the filter or arg area
                foreach (var curFilter in Filters)
                {
                    if (position >= curFilter.FilterStart && position <= curFilter.FilterStart + curFilter.Filter.Length)
                    {
                        // it's in this filter area
                        return(CompletionInfo.ToCompletionInfo(context.Filters, StandardGlyphGroup.GlyphKeyword));
                    }
                    else if (curFilter.Arg != null && position >= curFilter.ArgStart && position < curFilter.ArgStart + curFilter.Arg.Value.Length)
                    {
                        // it's in this argument
                        return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField));
                    }
                }

                if (String.IsNullOrWhiteSpace(Filters.Last().Filter))
                {
                    // last filter was blank, so provide filters
                    return(CompletionInfo.ToCompletionInfo(context.Filters, StandardGlyphGroup.GlyphKeyword));
                }
                else
                {
                    // ... else, provide variables
                    return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField));
                }
            }

            return(Enumerable.Empty <CompletionInfo>());
        }
Ejemplo n.º 3
0
 public virtual IEnumerable <CompletionInfo> GetCompletions(IDjangoCompletionContext context, int position)
 {
     return(CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupField));
 }