Exemplo n.º 1
0
        public void ReferenceFollowedByText()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "$Ajax.InstallScripts() text\n        text");
            //                          ^      ^
            TemplateNode templateNode = parser.ParseTemplate();

            // XmlTextNode, it is only one text node
            XmlTextNode point1 = (XmlTextNode)templateNode.GetNodeAt(1, 24);
            XmlTextNode point2 = (XmlTextNode)templateNode.GetNodeAt(2, 2);

            AssertPosition(new Position(1, 23, 2, 13), point1.Position);
            AssertPosition(new Position(1, 23, 2, 13), point2.Position);
        }
Exemplo n.º 2
0
        public void InsideWhitespacePrecededByXmlElement()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "  <p>inside</p>  ");
            //    ^              ^
            TemplateNode templateNode = parser.ParseTemplate();

            AstNode astNode;

            // Get the first XmlTextNode
            astNode = templateNode.GetNodeAt(1, 2);
            Assert.AreEqual("  ", ((XmlTextNode)astNode).Text);

            // Get the second XmlTextNode
            astNode = templateNode.GetNodeAt(1, 17);
            Assert.AreEqual("  ", ((XmlTextNode)astNode).Text);
        }
Exemplo n.º 3
0
        public void ParseReferenceInBetweenXmlTextNodes()
        {
            Parser parser = GetNewParser(
                "text$first.second(100) text");
            //      ^ ^                 ^
            TemplateNode templateNode = parser.ParseTemplate();

            // XmlTextNode
            XmlTextNode text1 = (XmlTextNode)templateNode.GetNodeAt(1, 4);

            AssertPosition(new Position(1, 1, 1, 5), text1.Position);

            // NVReference
            NVDesignator designator = (NVDesignator)templateNode.GetNodeAt(1, 6);

            AssertPosition(new Position(1, 5, 1, 23), designator.Position);

            // XmlTextNode
            XmlTextNode text2 = (XmlTextNode)templateNode.GetNodeAt(1, 24);

            AssertPosition(new Position(1, 23, 1, 28), text2.Position);
        }
Exemplo n.º 4
0
        public void AtEndOfUnclosedXmlElementWithAtLeastOneAttribute()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "<a name=\"\"     ");
            //               ^
            TemplateNode templateNode = parser.ParseTemplate();

            AstNode astNode = templateNode.GetNodeAt(1, 11);

            Assert.IsAssignableFrom(typeof(XmlElement), astNode);
            AssertPosition(new Position(1, 1, 1, 16), astNode.Position);
        }
Exemplo n.º 5
0
        public void ReferenceFollowedByReference()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "$Ajax.InstallScripts()\n$Form.");
            //                                 ^
            TemplateNode templateNode = parser.ParseTemplate();

            // Designator
            NVSelector designator = (NVSelector)templateNode.GetNodeAt(2, 7);

            AssertPosition(new Position(2, 6, 2, 7), designator.Position);
        }
Exemplo n.º 6
0
        public void ParseDirectiveStartWithNoNameFollowedByWhitespace()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;

            Parser parser = GetNewParser(scannerOptions,
                                         "# ");
            TemplateNode templateNode = parser.ParseTemplate();

            // Ensure the whole directive is included
            AssertPosition(new Position(1, 1, 1, 3), templateNode.GetNodeAt(1, 1).Position);

            Assert.AreEqual(1, parser.Errors.Count);
            AssertError("Expected directive name", new Position(1, 3, 1, 3), parser.Errors[0]);
        }
Exemplo n.º 7
0
        public void SecondDesignatorSelector()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "$Ajax.InstallScripts.");
            //                        ^
            TemplateNode templateNode = parser.ParseTemplate();

            // Get node at position
            AstNode astNode = templateNode.GetNodeAt(1, 22);

            Assert.AreEqual(typeof(NVSelector), astNode.GetType());
            AssertPosition(new Position(1, 21, 1, 22), astNode.Position); // selectors include '.'
        }
Exemplo n.º 8
0
        public void AtEndOfUnclosedXmlTagWithOneAttributeInsideXmlContent()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "<div>\n" +
                                         "    <a name=\"\" \n" +
                                         //                ^
                                         "</div>");
            TemplateNode templateNode = parser.ParseTemplate();

            AstNode astNode = templateNode.GetNodeAt(2, 16);

            Assert.IsAssignableFrom(typeof(XmlElement), astNode);
            AssertPosition(new Position(2, 5, 2, 16), astNode.Position);
        }
Exemplo n.º 9
0
        public void InsideStringLiteralInReference()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "$obj.Method(\"");
            //                 ^
            TemplateNode templateNode = parser.ParseTemplate();

            // Get node at position
            AstNode astNode = templateNode.GetNodeAt(1, 14);

            //TODO finish
            //NVStringExpression stringExpr = (NVStringExpression)astNode;
            //Assert.AreEqual("", stringExpr.Value);
            //AssertPosition(new Position(1, 14, 1, 14), stringExpr.Position);
        }
Exemplo n.º 10
0
        public void StartOfDesignator()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "$");
            //    ^
            TemplateNode templateNode = parser.ParseTemplate();

            // Check template
            Assert.AreEqual(1, templateNode.Content.Count);
            Assert.AreEqual(typeof(NVReference), templateNode.Content[0].GetType());

            // Get node at position
            AstNode astNode = templateNode.GetNodeAt(1, 2);

            Assert.AreEqual(typeof(NVDesignator), astNode.GetType());
            AssertPosition(new Position(1, 1, 1, 2), astNode.Position);
        }
Exemplo n.º 11
0
        public void InsideComponent()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "#component(");
            //              ^
            TemplateNode templateNode = parser.ParseTemplate();

            // Check template
            NVDirective nvDirective = (NVDirective)templateNode.Content[0];

            Assert.AreEqual("component", nvDirective.Name);

            // Get node at position
            AstNode astNode = templateNode.GetNodeAt(1, 12);

            Assert.AreEqual(typeof(NVDirective), astNode.GetType());
            AssertPosition(new Position(1, 1, 1, 12), astNode.Position);
        }
Exemplo n.º 12
0
        private void UpdateUIInUIThread(int cursorLine, int cursorCol, TemplateNode templateNode)
        {
            // Current Position
            currentPositionLabel.Text = string.Format("Line: {0}, Pos: {1}", cursorLine, cursorCol);

            // Current Node
            AstNode astNode = templateNode.GetNodeAt(cursorLine, cursorCol);

            currentNodeLabel.Text = string.Format("{0}, Pos: {1}",
                                                  astNode != null ? astNode.GetType().Name : "null astNode",
                                                  astNode != null ? astNode.Position.ToString() : "null astNode");

            // Abstract Syntax Tree
            BuildTreeViewFromAst(templateNode);
            ApplyFormattingToTreeNodes(astTreeView.Nodes, cursorLine, cursorCol);

            // Current Scope
            scopeListView.BeginUpdate();
            scopeListView.Items.Clear();
            AddItemsFromScope(templateNode, cursorLine, cursorCol);
            scopeListView.EndUpdate();
        }
Exemplo n.º 13
0
        public void InsideBodyOfComponentAtEndOfStartedDirective()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "#foreach($item in $items)\n" +
                                         "    #\n" +
                                         //    ^
                                         "#end");
            TemplateNode templateNode = parser.ParseTemplate();

            // Check the inner directive
            NVDirective nvDirective = (NVDirective)((NVForeachDirective)templateNode.Content[0]).Content[1];

            Assert.AreEqual("", nvDirective.Name);

            // Get the node at the location and check its position
            AstNode astNode = templateNode.GetNodeAt(2, 6);

            Assert.IsInstanceOfType(typeof(NVDirective), astNode);
            AssertPosition(new Position(2, 5, 3, 1), astNode.Position);
        }
Exemplo n.º 14
0
        public void FirstDesignatorSelector()
        {
            ScannerOptions scannerOptions = new ScannerOptions();

            scannerOptions.EnableIntelliSenseTriggerTokens = true;
            Parser parser = GetNewParser(scannerOptions,
                                         "$Ajax.");
            //         ^
            TemplateNode templateNode = parser.ParseTemplate();

            // Check template
            NVReference nvReference = (NVReference)templateNode.Content[0];

            Assert.AreEqual("Ajax", nvReference.Designator.Name);
            NVSelector nvSelector = nvReference.Designator.Selectors[0];

            Assert.AreEqual("", nvSelector.Name);

            // Get node at position
            AstNode astNode = templateNode.GetNodeAt(1, 7);

            Assert.AreEqual(typeof(NVSelector), astNode.GetType());
            AssertPosition(new Position(1, 6, 1, 7), astNode.Position);
        }
Exemplo n.º 15
0
        public override Declarations GetDeclarations(IVsTextView view, int line, int col,
                                                     TokenInfo info, ParseReason reason)
        {
            // If the intellisense parse reason was called before the template could be parsed
            if (_templateNode == null)
            {
                return(null);
            }

            AstNode astNode = _templateNode.GetNodeAt(line + 1, col + 1);

            if (astNode == null)
            {
                Debug.Fail("Null AstNode when attempting to provide IntelliSense in NVelocityAuthoringScope.");
                return(null);
            }

            NVelocityDeclarations declarations = new NVelocityDeclarations();

            if (astNode is NVDesignator)
            {
                List <NVLocalNode> localNodes = _templateNode.GetLocalNodesFromScope(line, col);
                localNodes.Sort(new Comparison <NVLocalNode>(
                                    delegate(NVLocalNode x, NVLocalNode y)
                {
                    return(x.Name.CompareTo(y.Name));
                }));
                foreach (NVLocalNode localNode in localNodes)
                {
                    declarations.Add(new NVelocityDeclaration(localNode.Name, localNode, IntelliSenseIcon.Variable));
                }
            }
            else if (astNode is NVSelector)
            {
                NVTypeNode typeNode = ((NVSelector)astNode).GetParentType();
                if (typeNode is NVClassNode)
                {
                    NVClassNode classNode = (NVClassNode)typeNode;

                    Dictionary <string, NVMethodNode> uniqueMethods = new Dictionary <string, NVMethodNode>();
                    foreach (NVMethodNode methodNode in classNode.Methods)
                    {
                        if (!uniqueMethods.ContainsKey(methodNode.Name))
                        {
                            uniqueMethods.Add(methodNode.Name, methodNode);
                        }
                    }

                    List <NVMethodNode> uniqueMethodsList = new List <NVMethodNode>();
                    foreach (KeyValuePair <string, NVMethodNode> pair in uniqueMethods)
                    {
                        uniqueMethodsList.Add(pair.Value);
                    }

                    uniqueMethodsList.Sort(new Comparison <NVMethodNode>(
                                               delegate(NVMethodNode x, NVMethodNode y)
                    {
                        return(x.Name.CompareTo(y.Name));
                    }));
                    foreach (NVMethodNode methodNode in uniqueMethodsList)
                    {
                        declarations.Add(new NVelocityDeclaration(methodNode.Name, methodNode, IntelliSenseIcon.Method));
                    }
                }
                else
                {
                    if (typeNode == null)
                    {
                        declarations.Add(new NVelocityDeclaration("Error: TypeNode is null", null, IntelliSenseIcon.Error));
                    }
                    else
                    {
                        declarations.Add(new NVelocityDeclaration("Error: Unsupported type for NVSelector " + typeNode.GetType().Name,
                                                                  null, IntelliSenseIcon.Error));
                    }
                }
            }
            else if (astNode is NVDirective)
            {
                NVDirective nvDirective = (NVDirective)astNode;
                if ((col + 1) - astNode.Position.StartPos == 1)
                {
                    // TODO: change the if expression so that it checks if the col is between the # and (
                    //       because you can bring up the intellisense list in the middle of the identifier
                    //       and it should display the list of the directives instead of the view components.
                    List <string> directivesList = new List <string>();
                    directivesList.AddRange(new string[]
                    {
                        "if", "elseif", "else", "end", "foreach", "set", "stop", "component",
                        "blockcomponent", "literal", "macro"
                    });
                    directivesList.Sort();

                    foreach (string directive in directivesList)
                    {
                        declarations.Add(new NVelocityDeclaration(directive, null, IntelliSenseIcon.Macro));
                    }
                }
                else if (nvDirective.Name == "component" || nvDirective.Name == "blockcomponent")
                {
                    List <NVClassNode> viewComponents = _templateNode.GetViewComponentsFromScope();
                    viewComponents.Sort(new Comparison <NVClassNode>(
                                            delegate(NVClassNode x, NVClassNode y)
                    {
                        return(x.Name.CompareTo(y.Name));
                    }));
                    foreach (NVClassNode classNode in viewComponents)
                    {
                        declarations.Add(new NVelocityDeclaration(classNode.Name, classNode, IntelliSenseIcon.Class));
                    }
                }
            }
            else if (astNode is XmlElement)
            {
                string xhtmlSchemaFileName = GetXhtmlSchemaFileName();
                if (string.IsNullOrEmpty(xhtmlSchemaFileName))
                {
                    Debug.Fail("Could not find XHTML schema.");
                    return(declarations);
                }
                XhtmlSchemaProvider xhtmlSchemaProvider = new XhtmlSchemaProvider(xhtmlSchemaFileName);

                XmlElement xmlElement = (XmlElement)astNode;
                if (string.IsNullOrEmpty(xmlElement.Name))
                {
                    if (xmlElement.Parent != null)
                    {
                        if (!xmlElement.Parent.IsSelfClosing && !xmlElement.IsComplete && !xmlElement.Parent.IsComplete)
                        {
                            declarations.Add(new NVelocityDeclaration(string.Format("/{0}>", xmlElement.Parent.Name),
                                                                      null, IntelliSenseIcon.XmlElement));
                        }
                    }

                    foreach (string xhtmlElement in xhtmlSchemaProvider.GetElements())
                    {
                        declarations.Add(new NVelocityDeclaration(xhtmlElement, null, IntelliSenseIcon.XmlElement));
                    }
                }
                else
                {
                    // Retrieve attributes
                    List <string> xhtmlAttributes = xhtmlSchemaProvider.GetAttributes(xmlElement.Name);

                    // Remove attributes that are already used
                    foreach (AstNode attribute in xmlElement.Attributes)
                    {
                        if (attribute is XmlAttribute)
                        {
                            XmlAttribute xmlAttribute = (XmlAttribute)attribute;
                            if (xhtmlAttributes.Contains(xmlAttribute.Name))
                            {
                                xhtmlAttributes.Remove(xmlAttribute.Name);
                            }
                        }
                    }

                    // Add the declarations for the attributes to show
                    foreach (string xhtmlAttribute in xhtmlAttributes)
                    {
                        declarations.Add(new NVelocityDeclaration(xhtmlAttribute, null, IntelliSenseIcon.XmlAttribute));
                    }
                }
            }
            else
            {
                declarations.Add(new NVelocityDeclaration("Error: Context unknown, type is " + astNode.GetType().Name,
                                                          null, IntelliSenseIcon.Error));
            }

            return(declarations);
        }
Exemplo n.º 16
0
        private void UpdateUIInUIThread(int cursorLine, int cursorCol, TemplateNode templateNode)
        {
            // Current Position
            currentPositionLabel.Text = string.Format("Line: {0}, Pos: {1}", cursorLine, cursorCol);

            // Current Node
            AstNode astNode = templateNode.GetNodeAt(cursorLine, cursorCol);
            currentNodeLabel.Text = string.Format("{0}, Pos: {1}",
                astNode != null ? astNode.GetType().Name : "null astNode",
                astNode != null ? astNode.Position.ToString() : "null astNode");

            // Abstract Syntax Tree
            BuildTreeViewFromAst(templateNode);
            ApplyFormattingToTreeNodes(astTreeView.Nodes, cursorLine, cursorCol);

            // Current Scope
            scopeListView.BeginUpdate();
            scopeListView.Items.Clear();
            AddItemsFromScope(templateNode, cursorLine, cursorCol);
            scopeListView.EndUpdate();
        }