Example #1
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
                    return(CompletionInfo.ToCompletionInfo(context.GetMembers(varName)));
                }
                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>());
        }
Example #2
0
        private IEnumerable <CompletionInfo> GetUnusedNamedParameters(DjangoUrl url)
        {
            if (url == null)
            {
                return(Enumerable.Empty <CompletionInfo>());
            }

            IList <string> undefinedNamedParameters = new List <string>();

            foreach (DjangoUrlParameter urlParam in url.NamedParameters)
            {
                if (!_definedNamedParameters.Contains(urlParam.Name))
                {
                    undefinedNamedParameters.Add(urlParam.Name);
                }
            }

            return(CompletionInfo.ToCompletionInfo(undefinedNamedParameters.Select(p => p += '='), StandardGlyphGroup.GlyphGroupField));
        }
Example #3
0
        /// <param name="kind">The type of template tag we are processing</param>
        /// <param name="templateText">The text of the template tag which we are offering a completion in</param>
        /// <param name="templateStart">The offset in the buffer where the template starts</param>
        /// <param name="triggerPoint">The point in the buffer where the completion was triggered</param>
        internal CompletionSet GetCompletionSet(CompletionOptions options, VsProjectAnalyzer analyzer, TemplateTokenKind kind, string templateText, int templateStart, SnapshotPoint triggerPoint, out ITrackingSpan applicableSpan)
        {
            int position = triggerPoint.Position - templateStart;
            IEnumerable <CompletionInfo> tags;
            IDjangoCompletionContext     context;

            applicableSpan = GetWordSpan(templateText, templateStart, triggerPoint);

            switch (kind)
            {
            case TemplateTokenKind.Block:
                var block = DjangoBlock.Parse(templateText);
                if (block != null)
                {
                    if (position <= block.ParseInfo.Start + block.ParseInfo.Command.Length)
                    {
                        // we are completing before the command
                        // TODO: Return a new set of tags?  Do nothing?  Do this based upon ctrl-space?
                        tags = FilterBlocks(CompletionInfo.ToCompletionInfo(analyzer.GetTags(), StandardGlyphGroup.GlyphKeyword), triggerPoint);
                    }
                    else
                    {
                        // we are in the arguments, let the block handle the completions
                        context = new ProjectBlockCompletionContext(analyzer, _buffer);
                        tags    = block.GetCompletions(context, position);
                    }
                }
                else
                {
                    // no tag entered yet, provide the known list of tags.
                    tags = FilterBlocks(CompletionInfo.ToCompletionInfo(analyzer.GetTags(), StandardGlyphGroup.GlyphKeyword), triggerPoint);
                }
                break;

            case TemplateTokenKind.Variable:
                var variable = DjangoVariable.Parse(templateText);
                context = new ProjectBlockCompletionContext(analyzer, _buffer);
                if (variable != null)
                {
                    tags = variable.GetCompletions(context, position);
                }
                else
                {
                    // show variable names
                    tags = CompletionInfo.ToCompletionInfo(context.Variables, StandardGlyphGroup.GlyphGroupVariable);
                }

                break;

            default:
                throw new InvalidOperationException();
            }

            var completions = tags
                              .OrderBy(tag => tag.DisplayText, StringComparer.OrdinalIgnoreCase)
                              .Select(tag => new DynamicallyVisibleCompletion(
                                          tag.DisplayText,
                                          tag.InsertionText,
                                          StripDocumentation(tag.Documentation),
                                          _glyphService.GetGlyph(tag.Glyph, StandardGlyphItem.GlyphItemPublic),
                                          "tag"));

            return(new FuzzyCompletionSet(
                       "PythonDjangoTags",
                       Resources.DjangoTagsCompletionSetDisplayName,
                       applicableSpan,
                       completions,
                       options,
                       CompletionComparer.UnderscoresLast));
        }
Example #4
0
 private IEnumerable <CompletionInfo> GetUrlCompletion(IDjangoCompletionContext context)
 {
     return(CompletionInfo.ToCompletionInfo(context.Urls.Select(url => string.Format("'{0}'", url.FullName)), StandardGlyphGroup.GlyphGroupField));
 }