internal SyntaxTransporter(CommonSyntaxNode node) { if (node is CSharp.SyntaxNode) { SourceLanguage = LanguageNames.CSharp; } else { SourceLanguage = LanguageNames.VisualBasic; } SyntaxStream = new MemoryStream(); var rootNode = GetRootNode(node); if (rootNode != null) { if (SourceLanguage == LanguageNames.CSharp) { var csharpRootNode = (CSharp.SyntaxNode)rootNode; csharpRootNode.SerializeTo(SyntaxStream); } else { var vbRootNode = (VisualBasic.SyntaxNode)rootNode; vbRootNode.SerializeTo(SyntaxStream); } } ItemSpan = node.Span; ItemKind = node.GetKind(SourceLanguage); ItemCategory = SyntaxCategory.SyntaxNode; }
private void AddNode(TreeViewItem parentItem, CommonSyntaxNode node) { var kind = node.GetKind(SourceLanguage); var tag = new SyntaxTag() { SyntaxNode = node, Category = SyntaxCategory.SyntaxNode, Span = node.Span, FullSpan = node.FullSpan, Kind = kind, ParentItem = parentItem }; var item = new TreeViewItem() { Tag = tag, IsExpanded = false, Foreground = Brushes.LightBlue, FontSize = 13, //Background = node.ContainsDiagnostics ? Brushes.Pink : Brushes.AliceBlue, Header = tag.Kind + " " + node.Span.ToString() }; if (SyntaxTree != null && node.ContainsDiagnostics) { item.ToolTip = string.Empty; foreach (var diagnostic in SyntaxTree.GetDiagnostics(node)) { item.ToolTip += diagnostic.ToString(null) + "\n"; } item.ToolTip = item.ToolTip.ToString().Trim(); } item.Selected += new RoutedEventHandler(async(sender, e) => { isNavigatingFromTreeToSource = true; //typeTextLabel.Visibility = Visibility.Visible; //kindTextLabel.Visibility = Visibility.Visible; //kindValueLabel.Content = kind; item.IsExpanded = true; if (!isNavigatingFromSourceToTree && SyntaxNodeNavigationToSourceRequested != null) { SyntaxNodeNavigationToSourceRequested(node); } try { propertyGrid.Instance = node; } catch { } isNavigatingFromTreeToSource = false; e.Handled = true; }); item.Expanded += new RoutedEventHandler((sender, e) => { if (item.Items.Count == 1 && item.Items[0] == null) { // Remove placeholder child and populate real children. item.Items.RemoveAt(0); foreach (var child in node.ChildNodesAndTokens()) { AddNodeOrToken(item, child); } } }); if (parentItem == root) { parentItem.Items.Clear(); parentItem.Items.Add(item); parentItem.IsExpanded = true; } else { parentItem.Items.Add(item); } if (node.ChildNodesAndTokens().Count > 0) { if (IsLazy) { // Add placeholder child to indicate that real children need to be populated on expansion. item.Items.Add(null); } else { // Recursively populate all descendants. foreach (var child in node.ChildNodesAndTokens()) { AddNodeOrToken(item, child); } } } }
internal SyntaxTransporter(CommonSyntaxNode node) { if (node is CSharp.SyntaxNode) { SourceLanguage = LanguageNames.CSharp; } else { SourceLanguage = LanguageNames.VisualBasic; } SyntaxStream = new MemoryStream(); var rootNode = GetRootNode(node); if (rootNode != null) { if (SourceLanguage == LanguageNames.CSharp) { var csharpRootNode = (CSharp.SyntaxNode)rootNode; csharpRootNode.SerializeTo(SyntaxStream); } else { var vbRootNode = (VisualBasic.SyntaxNode)rootNode; vbRootNode.SerializeTo(SyntaxStream); } } ItemSpan = node.Span; ItemKind = node.GetKind(SourceLanguage); ItemCategory = SyntaxCategory.SyntaxNode; }
private void AddNode(TreeViewItem parentItem, CommonSyntaxNode node) { var kind = node.GetKind(SourceLanguage); var tag = new SyntaxTag() { SyntaxNode = node, IsSyntaxNode = true, IsSyntaxToken = false, IsSyntaxTrivia = false, Span = node.Span, FullSpan = node.FullSpan, Kind = kind, ParentItem = parentItem }; var item = new TreeViewItem() { Tag = tag, IsExpanded = true, Foreground = Brushes.Blue, Background = node.HasDiagnostics ? Brushes.Pink : Brushes.White, Header = tag.Kind + " " + node.Span.ToString() }; if (node.HasDiagnostics) { item.ToolTip = string.Empty; foreach (var diagnostic in SyntaxTree.GetDiagnostics(node)) { item.ToolTip += diagnostic.ToString(null) + "\n"; } item.ToolTip = item.ToolTip.ToString().Trim(); } item.Selected += new RoutedEventHandler((sender, e) => { if (!e.Handled) { isNavigatingFromTreeToSource = true; typeTextLabel.Visibility = Visibility.Visible; kindTextLabel.Visibility = Visibility.Visible; typeValueLabel.Content = node.GetType().Name; kindValueLabel.Content = kind; propertyGrid.SelectedObject = node; // If IsLazy is true then populate only child items. if (IsLazy && item.Items.Count == 0 && node.HasChildren) { foreach (var child in node.ChildNodesAndTokens()) { AddNodeOrToken(item, child); } } item.IsExpanded = true; if (!isNavigatingFromSourceToTree && SyntaxNodeNavigationToSourceRequested != null) { SyntaxNodeNavigationToSourceRequested(node); } isNavigatingFromTreeToSource = false; e.Handled = true; } }); if (parentItem == null) { treeView.Items.Clear(); treeView.Items.Add(item); } else { parentItem.Items.Add(item); } // If IsLazy is false then recursively populate all descendent items. if (!IsLazy && node.HasChildren) { foreach (var child in node.ChildNodesAndTokens()) { AddNodeOrToken(item, child); } } }
private void AddNode(TreeViewItem parentItem, CommonSyntaxNode node) { var kind = node.GetKind(SourceLanguage); var tag = new SyntaxTag() { SyntaxNode = node, IsSyntaxNode = true, IsSyntaxToken = false, IsSyntaxTrivia = false, Span = node.Span, FullSpan = node.FullSpan, Kind = kind, ParentItem = parentItem }; var item = new TreeViewItem() { Tag = tag, IsExpanded = true, Foreground = Brushes.Blue, Background = node.HasDiagnostics ? Brushes.Pink : Brushes.White, Header = tag.Kind + " " + node.Span.ToString() }; if (node.HasDiagnostics) { item.ToolTip = string.Empty; foreach (var diagnostic in SyntaxTree.GetDiagnostics(node)) { item.ToolTip += diagnostic.ToString(null) + "\n"; } item.ToolTip = item.ToolTip.ToString().Trim(); } item.Selected += new RoutedEventHandler((sender, e) => { if (!e.Handled) { isNavigatingFromTreeToSource = true; typeTextLabel.Visibility = Visibility.Visible; kindTextLabel.Visibility = Visibility.Visible; typeValueLabel.Content = node.GetType().Name; kindValueLabel.Content = kind; propertyGrid.SelectedObject = node; // If IsLazy is true then populate only child items. if (IsLazy && item.Items.Count == 0 && node.HasChildren) { foreach (var child in node.ChildNodesAndTokens()) { AddNodeOrToken(item, child); } } item.IsExpanded = true; if (!isNavigatingFromSourceToTree && SyntaxNodeNavigationToSourceRequested != null) { SyntaxNodeNavigationToSourceRequested(node); } isNavigatingFromTreeToSource = false; e.Handled = true; } }); if (parentItem == null) { treeView.Items.Clear(); treeView.Items.Add(item); } else { parentItem.Items.Add(item); } // If IsLazy is false then recursively populate all descendent items. if (!IsLazy && node.HasChildren) { foreach (var child in node.ChildNodesAndTokens()) { AddNodeOrToken(item, child); } } }