/// <summary>
 /// Retrieves or creates a node provider for a buffer
 /// </summary>
 /// <param name="buffer"></param>
 /// <returns></returns>
 internal NodeProvider GetNodeProvider(ITextBuffer buffer, IVsHierarchy hier, string filename)
 {
     var provider = new NodeProvider(this, filename, type_resolver);
     buffer.Properties.AddProperty(typeof(NodeProvider), provider);
     template_loader.Register(filename, buffer, provider);
     return provider;
 }
Exemple #2
0
        /// <summary>
        /// Retrieves or creates a node provider for a buffer
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        internal NodeProvider GetNodeProvider(ITextBuffer buffer, IVsHierarchy hier, string filename)
        {
            var provider = new NodeProvider(this, filename, type_resolver);

            buffer.Properties.AddProperty(typeof(NodeProvider), provider);
            template_loader.Register(filename, buffer, provider);
            return(provider);
        }
 /// <summary>
 /// Retrieves or creates a node provider for a buffer
 /// </summary>
 /// <param name="buffer"></param>
 /// <returns></returns>
 internal NodeProvider GetNodeProvider(string project_directory, ITextBuffer buffer, IVsHierarchy hier, string filename)
 {
     var provider =
         new NodeProvider(
             this,
             filename,
             new TypeResolver(GlobalServices.TypeService.GetContextTypeResolver(hier), GlobalServices.TypeService.GetTypeResolutionService(hier)));
     buffer.Properties.AddProperty(typeof(NodeProvider), provider);
     template_loader.Register(filename, buffer, provider);
     return provider;
 }
Exemple #4
0
        /// <summary>
        /// Retrieves or creates a node provider for a buffer
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        internal NodeProvider GetNodeProvider(string project_directory, ITextBuffer buffer, IVsHierarchy hier, string filename)
        {
            var provider =
                new NodeProvider(
                    this,
                    filename,
                    new TypeResolver(GlobalServices.TypeService.GetContextTypeResolver(hier), GlobalServices.TypeService.GetTypeResolutionService(hier)));

            buffer.Properties.AddProperty(typeof(NodeProvider), provider);
            template_loader.Register(filename, buffer, provider);
            return(provider);
        }
        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);
            }
        }
        /// <summary>
        /// Creates the designer (proxy) node over the real syntax node passed in as a parameter
        /// Also recursively creates child nodes for all 'real' node children
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="snapshot"></param>
        /// <param name="node"></param>
        public DesignerNode(NodeProvider provider, DesignerNode parent, ITextSnapshot snapshot, INode node)
        {
            this.Provider = provider;
            Parent        = parent;
            this.node     = node;
            if (node.NodeType == NodeType.ParsingContext)
            {
                snapshotSpan  = new SnapshotSpan(snapshot, node.Position + node.Length, 0);
                extensionSpan = new SnapshotSpan(snapshot, node.Position, node.Length);
            }
            else
            {
                snapshotSpan = new SnapshotSpan(snapshot, node.Position, node.Length);
                int offset = 0;
                if (IsCompletionProvider)
                {
                    ITextSnapshotLine line = snapshot.GetLineFromPosition(node.Position);

                    // if the Value list is not empty, expand the snapshotSpan
                    // to include leading whitespaces, so that when a user
                    // types smth in this space he will get the dropdown
                    for (; node.Position - offset > line.Extent.Start.Position; offset++)
                    {
                        switch (snapshot[node.Position - offset - 1])
                        {
                        case ' ':
                        case '\t':
                            continue;

                        default:
                            break;
                        }
                        break;
                    }
                }
                extensionSpan = new SnapshotSpan(snapshot, node.Position - offset, offset);
            }
            foreach (IEnumerable <INode> list in node.Nodes.Values)
            {
                foreach (INode child in list)
                {
                    children.Add(new DesignerNode(provider, this, snapshot, child));
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Retrieves or creates a node provider for a buffer
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public NodeProvider GetNodeProvider(ITextBuffer buffer)
        {
            lock (this)
                if (!initialized)
                {
                    djangoDiagnostics = GetOutputPane(buffer);
                    initialized       = true;
                }

            NodeProvider provider;

            if (!buffer.Properties.TryGetProperty(typeof(NodeProvider), out provider))
            {
                provider = new NodeProvider(djangoDiagnostics, parser, buffer);
                buffer.Properties.AddProperty(typeof(NodeProvider), provider);
            }
            return(provider);
        }
        /// <summary>
        /// Creates the designer (proxy) node over the real syntax node passed in as a parameter
        /// Also recursively creates child nodes for all 'real' node children
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="snapshot"></param>
        /// <param name="node"></param>
        public DesignerNode(NodeProvider provider, DesignerNode parent, ITextSnapshot snapshot, INode node)
        {
            this.provider = provider;
            Parent = parent;
            this.node = node;
            if (node.NodeType == NodeType.ParsingContext)
            {
                snapshotSpan = new SnapshotSpan(snapshot, node.Position + node.Length, 0);
                extensionSpan = new SnapshotSpan(snapshot, node.Position, node.Length);
            }
            else
            {
                snapshotSpan = new SnapshotSpan(snapshot, node.Position, node.Length);
                int offset = 0;
                if (node.Values.GetEnumerator().MoveNext())
                {
                    ITextSnapshotLine line = snapshot.GetLineFromPosition(node.Position);

                    // if the Value list is not empty, expand the snapshotSpan
                    // to include leading whitespaces, so that when a user
                    // types smth in this space he will get the dropdown
                    for (; node.Position - offset > line.Extent.Start.Position; offset++)
                    {
                        switch (snapshot[node.Position - offset - 1])
                        {
                            case ' ':
                            case '\t':
                                continue;
                            default:
                                break;
                        }
                        break;
                    }
                }
                extensionSpan = new SnapshotSpan(snapshot, node.Position - offset, offset);
            }
            foreach (IEnumerable<INode> list in node.Nodes.Values)
                foreach (INode child in list)
                    children.Add(new DesignerNode(provider, this, snapshot, child));
        }
Exemple #9
0
 /// <summary>
 /// Creates a new instance of the <see cref="Classifier"/>
 /// </summary>
 /// <param name="nodeProviderBroker"></param>
 /// <param name="classificationTypeRegistry"></param>
 /// <param name="buffer"></param>
 public Classifier(INodeProviderBroker nodeProviderBroker, IClassificationTypeRegistryService classificationTypeRegistry, ITextBuffer buffer)
 {
     this.classificationTypeRegistry = classificationTypeRegistry;
     nodeProvider = nodeProviderBroker.GetNodeProvider(buffer);
     nodeProvider.NodesChanged += new NodeProvider.SnapshotEvent(nodeProvider_TagsChanged);
 }
 internal void Register(string path, ITextBuffer buffer, NodeProvider provider)
 {
     templates[path] = new BufferRecord(buffer.CurrentSnapshot, true);
 }
Exemple #11
0
 public Source(INodeProviderBroker nodeProviderBroker, ITextBuffer textBuffer)
 {
     this.textBuffer = textBuffer;
     nodeProvider = nodeProviderBroker.GetNodeProvider(textBuffer);
 }
        /// <summary>
        /// Retrieves or creates a node provider for a buffer
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public NodeProvider GetNodeProvider(ITextBuffer buffer)
        {
            if (djangoDiagnostics == null)
                djangoDiagnostics = GetOutputPane(buffer);

            NodeProvider provider;
            if (!buffer.Properties.TryGetProperty(typeof(NodeProvider), out provider))
                buffer.Properties.AddProperty(typeof(NodeProvider), provider
                    = new NodeProvider(djangoDiagnostics, parser, buffer));
            return provider;
        }
        private void CompletionSet_TestBase(string content, CompletionContext context, int position, Type completion_set, string[] display_values, string[] insert_values,string[] builder_values)
        {
            var textBuffer = new Mock<ITextBuffer>();

            // mock current snapshot - always return the content
            var current_snapshot = new Mock<ITextSnapshot>();
            current_snapshot.Setup<int>(s => s.Length).Returns(content.Length);
            current_snapshot.Setup<char[]>(s => s.ToCharArray(It.IsAny<int>(), It.IsAny<int>())).Returns((int pos, int len) => content.ToCharArray(pos, len));
            current_snapshot.Setup(s => s.GetText()).Returns(content);
            current_snapshot.Setup(s => s.CreateTrackingSpan(It.IsAny<int>(), It.IsAny<int>(), SpanTrackingMode.EdgeInclusive))
                .Returns((int start, int length, SpanTrackingMode tracking_mode) => new TrackingSpan(textBuffer.Object, start, length, tracking_mode));
            current_snapshot.Setup<ITextBuffer>(s => s.TextBuffer).Returns(textBuffer.Object);
            textBuffer.Setup<ITextSnapshot>(t => t.CurrentSnapshot).Returns(current_snapshot.Object);

            // mock snapshot lines - test templates are all single line
            var line = new Mock<ITextSnapshotLine>();
            var extent = new SnapshotSpan(current_snapshot.Object, 0, current_snapshot.Object.Length);
            line.Setup(l => l.LineNumber).Returns(0);
            line.Setup(l => l.Snapshot).Returns(current_snapshot.Object);
            line.Setup(l => l.Start).Returns(new SnapshotPoint(current_snapshot.Object, 0));
            line.Setup(l => l.End).Returns(new SnapshotPoint(current_snapshot.Object, current_snapshot.Object.Length));
            line.Setup(l => l.Extent).Returns(extent);

            // build a list of lines into snapshot
            var lines = new List<ITextSnapshotLine>();
            lines.Add(line.Object);
            current_snapshot.Setup(s => s.Lines).Returns(lines);
            current_snapshot.Setup(s => s.LineCount).Returns(lines.Count);
            current_snapshot.Setup(s => s.GetLineFromPosition(It.IsAny<int>())).Returns(line.Object);

            Assert.IsInstanceOf<ITemplateManager>(parser);

            // mock handler
            var handler = new Mock<IProjectHandler>();
            handler.Setup<ITextSnapshot>(h => h.GetSnapshot(It.IsAny<string>())).Returns((string t) => current_snapshot.Object);
            handler.Setup<Microsoft.FSharp.Collections.FSharpList<INodeImpl>>(h => h.ParseTemplate(It.IsAny<string>(), (NDjango.TypeResolver.ITypeResolver)It.IsAny<TestTypeResolver>()))
                .Returns((string t, NDjango.TypeResolver.ITypeResolver resolver)
                    => parser.GetTemplate(t, resolver, new NDjango.TypeResolver.ModelDescriptor(new List<NDjango.TypeResolver.IDjangoType>())).Nodes);

            var provider = new NodeProvider(handler.Object, "temp://" + content, new TestTypeResolver());

            var parsing_completed = false;

            provider.NodesChanged += delegate(SnapshotSpan span)
            {
                parsing_completed = true;
            };

            while (!parsing_completed)
                System.Threading.Thread.Sleep(1);

            var source = new Source(provider, textBuffer.Object);

            // mock session properties
            var session_properties = new Mock<PropertyCollection>().Object;
            session_properties.AddProperty(typeof(CompletionContext), context);

            // mock tracking point
            var tracking_point = new Mock<ITrackingPoint>();
            tracking_point.Setup<SnapshotPoint>(t => t.GetPoint(It.IsAny<ITextSnapshot>())).Returns((ITextSnapshot snapshot) => new SnapshotPoint(snapshot, position));

            var session = new Mock<ICompletionSession>();
            session.Setup<PropertyCollection>(s => s.Properties).Returns(session_properties);
            session.Setup<ITrackingPoint>(s => s.GetTriggerPoint(It.IsAny<ITextBuffer>())).Returns(tracking_point.Object);

            var completionSets = new List<CompletionSet>();
            source.AugmentCompletionSession(session.Object, completionSets);

            Assert.AreEqual(1, completionSets.Count);
            var c = completionSets[0];
            Assert.IsInstanceOf(completion_set, c);
            Assert.AreEqual(display_values.Length, c.Completions.Count);
            Assert.AreEqual(builder_values.Length,c.CompletionBuilders.Count);
            for (int i = 0; i<display_values.Length; i++)
                Assert.AreEqual(display_values[i], c.Completions[i].DisplayText);
            for (int i = 0; i < insert_values.Length; i++)
                Assert.AreEqual(insert_values[i], c.Completions[i].InsertionText);
            for (int i = 0; i < builder_values.Length; i++)
                Assert.AreEqual(builder_values[i], c.CompletionBuilders[i].DisplayText);
        }
Exemple #14
0
 public Source(NodeProvider provider, ITextBuffer textBuffer)
 {
     this.textBuffer = textBuffer;
     nodeProvider = provider;
 }