public void InvalidElementRange(string testFileName, int nodeIndex, string elementName, int startLine, int startColumn, int endLine, int endColumn) { string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions xmlPositions = new TextPositions(testXml); XmlDocumentSyntax xmlDocument = Parser.ParseText(testXml); List <XSNode> nodes = xmlDocument.GetSemanticModel(xmlPositions); Assert.NotNull(nodes); XSNode targetNode = nodes[nodeIndex]; Assert.NotNull(targetNode); Assert.IsAssignableFrom <XSElement>(targetNode); XSElement targetElement = (XSElement)targetNode; Assert.Equal(elementName, targetElement.Name); Assert.False(targetElement.IsValid, "IsValid"); Range expectedRange = new Range( start: new Position(startLine, startColumn), end: new Position(endLine, endColumn) ); Assert.Equal(expectedRange, targetElement.Range); }
/// <summary> /// Get hover content for an XML element that does not directly correspond to an <see cref="MSBuildObject"/>. /// </summary> /// <param name="element"> /// The <see cref="XSElement"/>. /// </param> /// <returns> /// The content, or <c>null</c> if no content is provided. /// </returns> public MarkedStringContainer Element(XSElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } string elementDescription = MSBuildSchemaHelp.ForElement(element.Name); if (String.IsNullOrWhiteSpace(elementDescription)) { return(null); } List <MarkedString> content = new List <MarkedString> { elementDescription }; string helpLink = MSBuildSchemaHelp.HelpLinkForElement(element.Name); if (!String.IsNullOrWhiteSpace(helpLink)) { content.Add( $"[Help]({helpLink})" ); } return(new MarkedStringContainer(content)); }
public void InEmptyElementName(string testFileName, int line, int column, string expectedElementName) { Position testPosition = new Position(line, column); string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions positions = new TextPositions(testXml); XmlDocumentSyntax document = Parser.ParseText(testXml); XmlLocator locator = new XmlLocator(document, positions); XmlLocation result = locator.Inspect(testPosition); Assert.NotNull(result); Assert.Equal(XSNodeKind.Element, result.Node.Kind); Assert.True(result.IsElement(), "IsElement"); XSElement element = (XSElement)result.Node; Assert.Equal(expectedElementName, element.Name); Assert.True(result.IsEmptyElement(), "IsEmptyElement"); Assert.True(result.IsName(), "IsName"); Assert.False(result.IsElementContent(), "IsElementContent"); // TODO: Verify Parent, PreviousSibling, and NextSibling. }
/// <summary> /// Get the names of existing metadata on the target item. /// </summary> /// <param name="itemElement"> /// The item element. /// </param> /// <returns> /// A sequence of existing metadata names. /// </returns> IEnumerable <string> GetExistingMetadataNames(XSElement itemElement) { if (itemElement == null) { throw new ArgumentNullException(nameof(itemElement)); } foreach (XSAttribute metadataAttribute in itemElement.Attributes) { yield return(metadataAttribute.Name); } foreach (XSElement metadataElement in itemElement.ChildElements) { yield return(metadataElement.Name); } }
void ElementAttributesRange(string testFileName, string elementName, int startLine, int startColumn, int endLine, int endColumn) { string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions xmlPositions = new TextPositions(testXml); XmlDocumentSyntax xmlDocument = Parser.ParseText(testXml); List <XSNode> nodes = xmlDocument.GetSemanticModel(xmlPositions); Assert.NotNull(nodes); XSNode targetNode = nodes.Find(node => node.Name == elementName); Assert.NotNull(targetNode); Assert.IsAssignableFrom <XSElement>(targetNode); XSElement targetElement = (XSElement)targetNode; Range expectedRange = new Range( start: new Position(startLine, startColumn), end: new Position(endLine, endColumn) ); Assert.Equal(expectedRange, targetElement.AttributesRange); }