Exemplo n.º 1
0
 protected void ClassifyTemplateBody(ITextSnapshot snapshot, List<ClassificationSpan> spans, TemplateRegion region, int prefixLength, int suffixLength) {
     switch (region.Kind) {
         case TemplateTokenKind.Comment:
             spans.Add(
                 new ClassificationSpan(
                     new SnapshotSpan(
                         snapshot,
                         new Span(region.Start + prefixLength, region.Text.Length - (prefixLength + suffixLength))
                     ),
                     _classifierProvider._commentClassType
                 )
             );
             break;
         case TemplateTokenKind.Variable:
             var filterInfo = DjangoVariable.Parse(region.Text);
             
             if (filterInfo != null) {
                 foreach(var curSpan in filterInfo.GetSpans()) {
                     spans.Add(ToClassificationSpan(curSpan, snapshot, region.Start));
                 }
             }
             break;
         case TemplateTokenKind.Block:
             var blockInfo = region.Block ?? DjangoBlock.Parse(region.Text);
             if (blockInfo != null) {
                 foreach (var curSpan in blockInfo.GetSpans()) {
                     spans.Add(ToClassificationSpan(curSpan, snapshot, region.Start));
                 }
             } else if (region.Text.Length > (prefixLength + suffixLength)) {    // unterminated block at end of file
                 spans.Add(
                     new ClassificationSpan(
                         new SnapshotSpan(
                             snapshot,
                             new Span(region.Start + prefixLength, region.Text.Length - (prefixLength + suffixLength))
                         ),
                         _classifierProvider._classType
                     )
                 );
             }
             break;
     }
 }
Exemplo n.º 2
0
        protected void ClassifyTemplateBody(ITextSnapshot snapshot, List <ClassificationSpan> spans, TemplateRegion region, int prefixLength, int suffixLength)
        {
            switch (region.Kind)
            {
            case TemplateTokenKind.Comment:
                spans.Add(
                    new ClassificationSpan(
                        new SnapshotSpan(
                            snapshot,
                            new Span(region.Start + prefixLength, region.Text.Length - (prefixLength + suffixLength))
                            ),
                        _classifierProvider._commentClassType
                        )
                    );
                break;

            case TemplateTokenKind.Variable:
                var filterInfo = DjangoVariable.Parse(region.Text);

                if (filterInfo != null)
                {
                    foreach (var curSpan in filterInfo.GetSpans())
                    {
                        spans.Add(ToClassificationSpan(curSpan, snapshot, region.Start));
                    }
                }
                break;

            case TemplateTokenKind.Block:
                var blockInfo = region.Block ?? DjangoBlock.Parse(region.Text);
                if (blockInfo != null)
                {
                    foreach (var curSpan in blockInfo.GetSpans())
                    {
                        spans.Add(ToClassificationSpan(curSpan, snapshot, region.Start));
                    }
                }
                else if (region.Text.Length > (prefixLength + suffixLength))            // unterminated block at end of file
                {
                    spans.Add(
                        new ClassificationSpan(
                            new SnapshotSpan(
                                snapshot,
                                new Span(region.Start + prefixLength, region.Text.Length - (prefixLength + suffixLength))
                                ),
                            _classifierProvider._classType
                            )
                        );
                }
                break;
            }
        }