// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose position best matches the supplied position. private TreeViewItem NavigateToBestMatch(TreeViewItem current, int position, string kind = null, SyntaxCategory category = SyntaxCategory.None) { TreeViewItem match = null; if (current != null && current != root) { SyntaxTag currentTag = (SyntaxTag)current.Tag; if (currentTag.FullSpan.Contains(position)) { CollapseEverythingBut(current); foreach (TreeViewItem item in current.Items) { match = NavigateToBestMatch(item, position, kind, category); if (match != null) { break; } } if (match == null && (kind == null || currentTag.Kind == kind) && (category == SyntaxCategory.None || category == currentTag.Category)) { match = current; } } } return(match); }
private static void CheckCategory(SyntaxKind kind, SyntaxCategory category) { if (kind.GetCategory() != category) { throw new ArgumentException($"The kind {kind} is not a {category.ToString().ToLower()}"); } }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. public bool NavigateToBestMatch(TextSpan span, string kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false, string highlightLegendDescription = null) { TreeViewItem match = null; if (treeView.HasItems && !_isNavigatingFromTreeToSource) { _isNavigatingFromSourceToTree = true; match = NavigateToBestMatch((TreeViewItem)treeView.Items[0], span, kind, category); _isNavigatingFromSourceToTree = false; } var matchFound = match != null; if (highlightMatch && matchFound) { match.Background = Brushes.Yellow; match.BorderBrush = Brushes.Black; match.BorderThickness = s_defaultBorderThickness; highlightLegendTextLabel.Visibility = Visibility.Visible; highlightLegendDescriptionLabel.Visibility = Visibility.Visible; if (!string.IsNullOrWhiteSpace(highlightLegendDescription)) { highlightLegendDescriptionLabel.Content = highlightLegendDescription; } } return(matchFound); }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. public bool NavigateToBestMatch(TextSpan span, string kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false, string highlightLegendDescription = null) { TreeViewItem match = null; if (treeView.HasItems && !isNavigatingFromTreeToSource) { isNavigatingFromSourceToTree = true; match = NavigateToBestMatch((TreeViewItem)treeView.Items[0], span, kind, category); isNavigatingFromSourceToTree = false; } var matchFound = match != null; if (highlightMatch && matchFound) { match.Background = Brushes.Yellow; match.BorderBrush = Brushes.Black; match.BorderThickness = DefaultBorderThickness; match.IsSelected = true; } return(matchFound); }
internal SyntaxTransporter(CommonSyntaxTrivia trivia) { try { var t = (CSharp.SyntaxTrivia)trivia; SourceLanguage = LanguageNames.CSharp; } catch { var t = (VisualBasic.SyntaxTrivia)trivia; SourceLanguage = LanguageNames.VisualBasic; } SyntaxStream = new MemoryStream(); var rootNode = GetRootNode(trivia); 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 = trivia.Span; ItemKind = trivia.GetKind(SourceLanguage); ItemCategory = SyntaxCategory.SyntaxTrivia; }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. private TreeViewItem NavigateToBestMatch(TreeViewItem current, TextSpan span, string kind = null, SyntaxCategory category = SyntaxCategory.None) { TreeViewItem match = null; if (current != null) { var currentTag = (SyntaxTag)current.Tag; if (currentTag.FullSpan.Contains(span)) { if ((currentTag.Span == span || currentTag.FullSpan == span) && (kind == null || currentTag.Kind == kind)) { CollapseEverythingBut(current); match = current; } else { CollapseEverythingBut(current); foreach (TreeViewItem item in current.Items) { if (category != SyntaxCategory.Operation && ((SyntaxTag)item.Tag).Category == SyntaxCategory.Operation) { // Do not prefer navigating to IOperation nodes when clicking in source code continue; } match = NavigateToBestMatch(item, span, kind, category); if (match != null) { break; } } if (match == null && (kind == null || currentTag.Kind == kind) && (category == SyntaxCategory.None || category == currentTag.Category)) { match = current; } } } } return(match); }
internal SyntaxTransporter(CommonSyntaxTree tree) { SyntaxStream = new MemoryStream(); if (tree is CSharp.SyntaxTree) { SourceLanguage = LanguageNames.CSharp; var csharpTree = (CSharp.SyntaxTree)tree; csharpTree.GetRoot().SerializeTo(SyntaxStream); } else { SourceLanguage = LanguageNames.VisualBasic; var vbTree = (VisualBasic.SyntaxTree)tree; vbTree.GetRoot().SerializeTo(SyntaxStream); } ItemSpan = tree.GetRoot().Span; ItemKind = tree.GetRoot().GetKind(SourceLanguage); ItemCategory = SyntaxCategory.SyntaxNode; }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. private TreeViewItem NavigateToBestMatch(TreeViewItem current, TextSpan span, string kind = null, SyntaxCategory category = SyntaxCategory.None) { TreeViewItem match = null; if (current != null) { var currentTag = (SyntaxTag)current.Tag; if (currentTag.FullSpan.Contains(span)) { if ((currentTag.Span == span || currentTag.FullSpan == span) && (kind == null || currentTag.Kind == kind)) { CollapseEverythingBut(current); match = current; } else { CollapseEverythingBut(current); foreach (TreeViewItem item in current.Items) { match = NavigateToBestMatch(item, span, kind, category); if (match != null) { break; } } if (match == null && (kind == null || currentTag.Kind == kind) && (category == SyntaxCategory.None || category == currentTag.Category)) { match = current; } } } } return(match); }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose position best matches the supplied position. public bool NavigateToBestMatch(int position, string kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false) { TreeViewItem match = null; if (treeView.HasItems && !_isNavigatingFromTreeToSource) { _isNavigatingFromSourceToTree = true; match = NavigateToBestMatch((TreeViewItem)treeView.Items[0], position, kind, category); _isNavigatingFromSourceToTree = false; } var matchFound = match != null; if (highlightMatch && matchFound) { match.Background = Brushes.Yellow; match.BorderBrush = Brushes.Black; match.BorderThickness = s_defaultBorderThickness; } return(matchFound); }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. private TreeViewItem NavigateToBestMatch(TreeViewItem current, TextSpan span, string kind = null, SyntaxCategory category = SyntaxCategory.None) { TreeViewItem match = null; if (current != null) { SyntaxTag currentTag = (SyntaxTag)current.Tag; if (currentTag.FullSpan.Contains(span)) { if ((currentTag.Span == span || currentTag.FullSpan == span) && (kind == null || currentTag.Kind == kind)) { CollapseEverythingBut(current); match = current; } else { CollapseEverythingBut(current); foreach (TreeViewItem item in current.Items) { match = NavigateToBestMatch(item, span, kind, category); if (match != null) { break; } } if (match == null && (kind == null || currentTag.Kind == kind) && (category == SyntaxCategory.None || category == currentTag.Category)) { match = current; } } } } return match; }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. public bool NavigateToBestMatch(TextSpan span, string kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false, string highlightLegendDescription = null) { TreeViewItem match = null; if (treeView.HasItems && !_isNavigatingFromTreeToSource) { _isNavigatingFromSourceToTree = true; match = NavigateToBestMatch((TreeViewItem)treeView.Items[0], span, kind, category); _isNavigatingFromSourceToTree = false; } var matchFound = match != null; if (highlightMatch && matchFound) { match.Background = Brushes.Yellow; match.BorderBrush = Brushes.Black; match.BorderThickness = s_defaultBorderThickness; highlightLegendTextLabel.Visibility = Visibility.Visible; highlightLegendDescriptionLabel.Visibility = Visibility.Visible; if (!string.IsNullOrWhiteSpace(highlightLegendDescription)) { highlightLegendDescriptionLabel.Content = highlightLegendDescription; } } return matchFound; }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. public bool NavigateToBestMatch(int start, int length, string kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false, string highlightLegendDescription = null) { return NavigateToBestMatch(new TextSpan(start, length), kind, category, highlightMatch, highlightLegendDescription); }
// Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. public bool NavigateToBestMatch(int start, int length, string kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false, string highlightLegendDescription = null) { return(NavigateToBestMatch(new TextSpan(start, length), kind, category, highlightMatch, highlightLegendDescription)); }
public Syntax(SyntaxCategory category, string regex) { this.category = category; this.regex = new Regex(regex, RegexOptions.Compiled); }