protected virtual void Initialize(Source source, DesignerNode node, SnapshotPoint point)
        {
            Source = source;

            // calculate the span to be replaced with user selection
            Span span = new Span(point.Position, 0);

            if (node.SnapshotSpan.IntersectsWith(span))
            {
                span = node.SnapshotSpan.Span;
            }

            var existing_text = new SnapshotSpan(point.Snapshot.TextBuffer.CurrentSnapshot, span);

            var completion_offset = InitializeFilters(existing_text.GetText().Substring(0, point.Position - existing_text.Start));

            //Adjust the span to be replaced for variables/members;
            var to_be_replaced = new Span(span.Start + completion_offset, span.Length - completion_offset);

            ApplicableTo = point.Snapshot.CreateTrackingSpan(to_be_replaced, SpanTrackingMode.EdgeInclusive);

            // claculate the filter span (for explanation see comment on the filterspan member definition)
            filterSpan = point.Snapshot.CreateTrackingSpan(to_be_replaced.Start, point.Position - to_be_replaced.Start, SpanTrackingMode.EdgeInclusive);

            this.node = node;
        }
 private static void BuildNodesByName(Hashtable nodesByName, DesignerNode node)
 {
     if (node.Node.Name != String.Empty)
     {
         nodesByName.Add(node.Node.Name, node);
     }
     foreach (DesignerNode localNode in node.Nodes)
     {
         BuildNodesByName(nodesByName, localNode);
     }
 }
        internal static CompletionSet Create <T>
            (Source source, SnapshotPoint point, DesignerNode node)
            where T : AbstractCompletionSet, new()
        {
            if (node == null)
            {
                return(null);
            }
            var result = new T();

            result.Initialize(source, node, point);
            return(result);
        }
Example #4
0
        private CompletionSet CreateCompletionSet(CompletionContext context, SnapshotPoint point)
        {
            switch (context)
            {
            case CompletionContext.Tag:
                return(AbstractCompletionSet.Create <TagCompletionSet>(
                           nodeProvider, point,
                           n => n.NodeType == NodeType.ParsingContext
                           ));

            case CompletionContext.Variable:
                return(AbstractCompletionSet.Create <VariableCompletionSet>(
                           nodeProvider, point,
                           n => n.NodeType == NodeType.ParsingContext
                           ));

            case CompletionContext.FilterName:
                return(AbstractCompletionSet.Create <FilterCompletionSet>(
                           nodeProvider, point,
                           n => n.NodeType == NodeType.ParsingContext
                           ));

            case CompletionContext.Word:
                // Get the list of all nodes with non-empty value lists
                List <DesignerNode> nodes = nodeProvider.GetNodes(point, n => n.Values.GetEnumerator().MoveNext());
                // out of the list get the last node which is not a parsing context
                DesignerNode node = nodes.FindLast(n => n.NodeType != NodeType.ParsingContext);
                if (node == null)
                {
                    break;
                }
                if (node.NodeType == NodeType.TagName)
                {
                    return(new TagNameCompletionSet(node, point));
                }
                return(new ValueCompletionSet(node, point));

            default:
                break;
            }

            return(null);
            // for now let us leave the template names alone
            //return AbstractCompletionSet.Create<TemplateNameCompletionSet>(
            //    nodeProvider, point,
            //    n =>
            //        n.NodeType == NodeType.TemplateName
            //        && string_delimiters.Contains(n.SnapshotSpan.GetText()[0])
            //        );
        }
Example #5
0
        private void Highlight(NodeProvider provider, CaretPosition position)
        {
            SnapshotPoint point = position.BufferPosition;

            List <DesignerNode> tags     = provider.GetNodes(point, node => node.NodeType == NDjango.Interfaces.NodeType.TagName);
            DesignerNode        selected = tags.Count == 0 ? null : tags[0];

            DesignerNode highlighted = null;

            point.Snapshot.TextBuffer.Properties.TryGetProperty <DesignerNode>(typeof(Highlighter), out highlighted);
            if (selected != highlighted)
            {
                point.Snapshot.TextBuffer.Properties[typeof(Highlighter)] = selected;
                provider.RaiseNodesChanged(point.Snapshot);
            }
        }
Example #6
0
        protected virtual void Initialize(DesignerNode node, SnapshotPoint point)
        {
            // calculate the span to be replaced with user selection
            Span span = new Span(point.Position, 0);

            if (node.SnapshotSpan.IntersectsWith(span))
            {
                span = node.SnapshotSpan.Span;
            }
            ApplicableTo = point.Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive);

            // claculate the filter span (see above)
            filterSpan = point.Snapshot.CreateTrackingSpan(span.Start, point.Position - span.Start, SpanTrackingMode.EdgeInclusive);

            this.node = node;
        }
Example #7
0
        protected override void Initialize(Source source, DesignerNode node, SnapshotPoint point)
        {
            base.Initialize(source, node, point);
            switch (source.Context)
            {
            case CompletionContext.QuotedString:
                quote_char = '"';
                break;

            case CompletionContext.AposString:
                quote_char = '\'';
                break;

            default:
                System.Diagnostics.Debug.Assert(true, "Contexts other than QuotedString and AposString are not allowed, context=" + source.Context.ToString());
                break;
            }
            source.Session.Committed += new EventHandler(Session_Committed);
        }
Example #8
0
        private CompletionSet CreateCompletionSet(SnapshotPoint point)
        {
            switch (Context)
            {
            case CompletionContext.Tag:
                return(AbstractCompletionSet.Create <TagCompletionSet>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.ParsingContext).FindLast(n => true)
                           ));

            case CompletionContext.Variable:
                return(AbstractCompletionSet.Create <VariableCompletionSet>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.ParsingContext).FindLast(n => true)
                           ));

            case CompletionContext.FilterName:
                return(AbstractCompletionSet.Create <FilterName>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.ParsingContext).FindLast(n => true)
                           ));

            case CompletionContext.FilterArgument:
                return(AbstractCompletionSet.Create <FilterArgument>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.Filter).FindLast(n => true)));

            case CompletionContext.Word:
                // Get the list of all nodes with non-empty value lists
                List <DesignerNode> nodes = nodeProvider.GetNodes(point, n => n.IsCompletionProvider);
                // out of the list get the last node which is not a parsing context
                DesignerNode node = nodes.FindLast(n => n.NodeType != NodeType.ParsingContext);
                if (node == null)
                {
                    return(null);
                }
                switch (node.NodeType)
                {
                case NodeType.Reference:
                    return(AbstractCompletionSet.Create <Member>(this, point, node));

                case NodeType.TagName:
                    return(new TagName(this, node, point));

                case NodeType.TypeName:
                    return(new TypeName(this, node, point));

                default:
                    break;
                }
                return(new ValueCompletionSet(this, node, point));

            case CompletionContext.NewMemberReference:
                return(AbstractCompletionSet.Create <NewMember>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.Reference).FindLast(n => true)));

            case CompletionContext.AposString:
            case CompletionContext.QuotedString:
                return(AbstractCompletionSet.Create <TemplateName>(
                           this, point,
                           nodeProvider.GetNodes(point, n => n.NodeType == NodeType.TemplateName).FindLast(n => true)));

            default:
                return(null);
            }
        }
Example #9
0
 /// <summary>
 /// Completion set constructor - only called from the Create method
 /// </summary>
 /// <param name="node"></param>
 /// <param name="point"></param>
 internal AbstractCompletionSet(DesignerNode node, SnapshotPoint point)
     : base("Django Completions", "Django Completions", null, null, null)
 {
     Initialize(node, point);
 }
Example #10
0
 internal TagName(Source source, DesignerNode node, SnapshotPoint point)
     : base(source, node, point)
 {
 }
 internal TagNameCompletionSet(DesignerNode node, SnapshotPoint point)
     : base(node, point)
 {
 }
 protected override void Initialize(DesignerNode node, SnapshotPoint point)
 {
     base.Initialize(node, point);
     this.quote_char = node.SnapshotSpan.GetText()[0];
 }
Example #13
0
 public ValueCompletionSet(Source source, DesignerNode node, SnapshotPoint point)
     : base(source, node, point)
 {
 }
Example #14
0
        /// <summary>
        /// Provides a list of <see cref="ClassificationSpan"/> objects for the specified span
        /// </summary>
        /// <param name="span">span for which the list is requested</param>
        /// <returns></returns>
        /// <remarks>The list is generated based on the list of <see cref="TokenSnapshots"/> recieved
        /// from the tokenizer</remarks>
        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            List <ClassificationSpan> classifications = new List <ClassificationSpan>();

            // create classifiers for currently selected tag (if any)
            DesignerNode selection;

            if (span.Snapshot.TextBuffer.Properties
                .TryGetProperty <DesignerNode>(typeof(Highlighter), out selection) && selection != null)
            {
                // colorize the selected tag name
                classifications.Add(
                    new ClassificationSpan(
                        selection.SnapshotSpan,
                        classificationTypeRegistry.GetClassificationType(Constants.DJANGO_SELECTED_TAGNAME)
                        )
                    );

                // colorize the selected tag itself
                DesignerNode tag = selection.Parent;
                classifications.Add(
                    new ClassificationSpan(
                        tag.SnapshotSpan,
                        classificationTypeRegistry.GetClassificationType(Constants.DJANGO_SELECTED_TAG)
                        )
                    );

                // for every context defined in the tag
                foreach (DesignerNode child in tag.Children)
                {
                    // colorize the context
                    if (child.NodeType == NodeType.ParsingContext)
                    {
                        classifications.Add(
                            new ClassificationSpan(
                                child.ExtensionSpan,
                                classificationTypeRegistry.GetClassificationType(Constants.DJANGO_SELECTED_TAG)
                                )
                            );
                    }
                    // locate the closing tag for context
                    if (child.NodeType == NodeType.CloseTag)
                    {
                        foreach (DesignerNode t in child.Children)
                        {
                            if (t.NodeType == NodeType.TagName)
                            {
                                // colorize the closing tag name
                                classifications.Add(
                                    new ClassificationSpan(
                                        t.SnapshotSpan,
                                        classificationTypeRegistry.GetClassificationType(Constants.DJANGO_SELECTED_TAGNAME)
                                        )
                                    );
                                break;
                            }
                        }
                    }
                }
            }

            // create standard classifiers for tags
            nodeProvider.GetNodes(span, node => node.NodeType != NodeType.ParsingContext)
            .ForEach(
                node =>
            {
                switch (node.NodeType)
                {
                case NodeType.Marker:
                    classifications.Add(
                        new ClassificationSpan(
                            node.SnapshotSpan,
                            classificationTypeRegistry.GetClassificationType(Constants.MARKER_CLASSIFIER)
                            ));
                    break;

                default:
                    break;
                }
                ;
            }
                );

            return(classifications);
        }
Example #15
0
 public TypeName(Source source, DesignerNode node, SnapshotPoint point)
     : base(source, node, point)
 {
 }
 public ValueCompletionSet(DesignerNode node, SnapshotPoint point)
     : base(node, point)
 {
 }