static bool CheckIfAttributeContainsNonMarkupNodes(RazorSyntaxNode attributeNode)
            {
                // Only allow markup, generic & (non-razor comment) token nodes
                var containsNonMarkupNodes = attributeNode.DescendantNodes()
                                             .Any(n => !(n is MarkupBlockSyntax ||
                                                         n is MarkupSyntaxNode ||
                                                         n is GenericBlockSyntax ||
                                                         (n is SyntaxNode sn && sn.IsToken && sn.Kind != SyntaxKind.RazorCommentTransition)));

                return(containsNonMarkupNodes);
            }
Пример #2
0
        private static string GetAttributeValueContent(RazorSyntaxNode attributeBlock)
        {
            if (attributeBlock is MarkupTagHelperAttributeSyntax tagHelperAttribute)
            {
                return(tagHelperAttribute.Value?.GetContent());
            }
            else if (attributeBlock is MarkupAttributeBlockSyntax attribute)
            {
                return(attribute.Value?.GetContent());
            }

            return(null);
        }
        private void AddNode(RazorSyntaxNode node, TreeViewItem?parent)
        {
            var item = new TreeViewItem()
            {
                Tag        = node,
                IsExpanded = parent == null,
                ToolTip    = node.ToString(),
                Header     = $"{node.Kind} [{node.SpanStart}-{node.SpanEnd}]"
            };

            item.Selected += new RoutedEventHandler((sender, e) =>
            {
                item.IsExpanded = true;

                if (!_isNavigatingFromSourceToTree)
                {
                    _isNavigatingFromTreeToSource = true;

                    if (IsVisible && _activeWpfTextView != null)
                    {
                        var snapShotSpan = new SnapshotSpan(_activeWpfTextView.TextBuffer.CurrentSnapshot, node.SpanStart, node.SpanLength);

                        _activeWpfTextView.Selection.Select(snapShotSpan, false);
                        _activeWpfTextView.ViewScroller.EnsureSpanVisible(snapShotSpan);
                    }

                    _isNavigatingFromTreeToSource = false;
                }

                e.Handled = true;
            });

            if (parent == null)
            {
                treeView.Items.Clear();
                treeView.Items.Add(item);
            }
            else
            {
                parent.Items.Add(item);
            }

            foreach (var child in node.Children)
            {
                AddNode(child, item);
            }
        }
Пример #4
0
        private RangeModel GetRangeFromSyntaxNode(RazorSyntaxNode syntaxNode, RazorCodeDocument codeDocument)
        {
            try
            {
                int startPosition;
                int endPosition;
                if (syntaxNode is MarkupTagHelperAttributeSyntax thAttributeSyntax)
                {
                    startPosition = thAttributeSyntax.Name.Position;
                    endPosition   = thAttributeSyntax.Name.EndPosition;
                }
                else if (syntaxNode is MarkupMinimizedTagHelperAttributeSyntax thAttrSyntax)
                {
                    startPosition = thAttrSyntax.Name.Position;
                    endPosition   = thAttrSyntax.Name.EndPosition;
                }
                else
                {
                    startPosition = syntaxNode.Position;
                    endPosition   = syntaxNode.EndPosition;
                }
                var startLocation = codeDocument.Source.Lines.GetLocation(startPosition);
                var endLocation   = codeDocument.Source.Lines.GetLocation(endPosition);

                return(new RangeModel
                {
                    Start = new Position(startLocation.LineIndex, startLocation.CharacterIndex),
                    End = new Position(endLocation.LineIndex, endLocation.CharacterIndex)
                });
            }
            catch (IndexOutOfRangeException)
            {
                Debug.Assert(false, "Node position should stay within document length.");
                return(null);
            }
        }
        internal static SyntaxNode NextSiblingOrSelf(this SyntaxList <RazorSyntaxNode> syntaxList, RazorSyntaxNode syntaxNode)
        {
            var index = syntaxList.IndexOf(syntaxNode);

            if (index == syntaxList.Count - 1)
            {
                return(syntaxNode);
            }
            else if (index == -1)
            {
                throw new ArgumentException("The provided node was not in the SyntaxList");
            }
            else
            {
                return(syntaxList[index + 1]);
            }
        }