Example #1
0
 public TemplateRegion(string text, TemplateTokenKind kind, DjangoBlock block, int start)
 {
     Text  = text;
     Kind  = kind;
     Start = start;
     Block = block;
 }
Example #2
0
 public TemplateToken(TemplateTokenKind kind, int start, int end, bool isClosed = true)
 {
     Kind     = kind;
     Start    = start;
     End      = end;
     IsClosed = isClosed;
 }
Example #3
0
        /// <summary>
        /// Given a point in the template buffer gets the text for that template tag.
        /// </summary>
        internal string GetTemplateText(SnapshotPoint point, out TemplateTokenKind kind, out int start)
        {
            Debug.Assert(point.Snapshot.TextBuffer == _templateBuffer);

            var realPoint = _bufferGraph.MapDownToBuffer(
                point,
                PointTrackingMode.Positive,
                _diskBuffer,
                PositionAffinity.Successor);

            if (realPoint != null)
            {
                // TODO: Binary search would be better
                var pointVal = realPoint.Value;
                for (int i = 0; i < _spans.Count; i++)
                {
                    var startPoint = _spans[i].DiskBufferSpan.GetSpan(_diskBuffer.CurrentSnapshot);
                    if (startPoint.Start <= pointVal.Position && startPoint.End >= pointVal.Position)
                    {
                        kind  = _spans[i].Kind;
                        start = startPoint.Start;
                        return(_spans[i].DiskBufferSpan.GetText(_diskBuffer.CurrentSnapshot));
                    }
                }
            }
            kind  = TemplateTokenKind.None;
            start = 0;
            return(null);
        }
        /// <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, DjangoAnalyzer 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._tags, 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._tags, 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",
                "Django Tags",
                applicableSpan,
                completions,
                options,
                CompletionComparer.UnderscoresLast);
        }
Example #5
0
        public static TemplateArtifact Create(TemplateTokenKind kind, ITextRange range, bool isClosed)
        {
            switch (kind)
            {
            case TemplateTokenKind.Block:
                return(new TemplateBlockArtifact(range, isClosed));

            case TemplateTokenKind.Variable:
                return(new TemplateVariableArtifact(range, isClosed));

            case TemplateTokenKind.Comment:
                return(new TemplateCommentArtifact(range, isClosed));

            default:
                throw new ArgumentException("Unsupported TemplateTokenKind", "kind");
            }
        }
Example #6
0
        public TemplateToken?ReadToClose(int start, TemplateTokenKind kind, char closeType)
        {
            var prevChar = ReadChar();

            for (; ;)
            {
                if (prevChar == -1)
                {
                    return(new TemplateToken(kind, start, _position - 1, isClosed: false));
                }
                else if (prevChar == closeType)
                {
                    if ((prevChar = ReadChar()) == '}')
                    {
                        // we're done
                        return(new TemplateToken(kind, start, _position - 1));
                    }
                }
                else
                {
                    prevChar = ReadChar();
                }
            }
        }
Example #7
0
 public static TemplateArtifact Create(TemplateTokenKind kind, ITextRange range, bool isClosed) {
     switch (kind) {
         case TemplateTokenKind.Block:
             return new TemplateBlockArtifact(range, isClosed);
         case TemplateTokenKind.Variable:
             return new TemplateVariableArtifact(range, isClosed);
         case TemplateTokenKind.Comment:
             return new TemplateCommentArtifact(range, isClosed);
         default:
             throw new ArgumentException("Unsupported TemplateTokenKind", "kind");
     }
 }
Example #8
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 #9
0
 public TemplateToken? ReadToClose(int start, TemplateTokenKind kind, char closeType) {
     var prevChar = ReadChar();            
     for (; ; ) {               
         if (prevChar == -1) {
             return new TemplateToken(kind, start, _position - 1, isClosed: false);
         } else if (prevChar == closeType) {
             if ((prevChar = ReadChar()) == '}') {
                 // we're done
                 return new TemplateToken(kind, start, _position - 1);
             }
         } else {
             prevChar = ReadChar();
         }
     }            
 }
Example #10
0
 public TemplateRegion(string text, TemplateTokenKind kind, DjangoBlock block, int start) {
     Text = text;
     Kind = kind;
     Start = start;
     Block = block;
 }
Example #11
0
 public SpanInfo(ITrackingSpan diskBufferSpan, TemplateTokenKind kind, DjangoBlock djangoBlock)
 {
     DiskBufferSpan = diskBufferSpan;
     Kind           = kind;
     Block          = djangoBlock;
 }
Example #12
0
 public SpanInfo(ITrackingSpan diskBufferSpan, TemplateTokenKind kind)
 {
     DiskBufferSpan = diskBufferSpan;
     Kind           = kind;
     Block          = null;
 }