From 39aa253496b4053b559e6d72440e78e89d527122 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Mon, 25 Jan 2021 18:02:24 -0800 Subject: [PATCH 01/14] update version of the roslyn packages (and their dependencies) --- eng/Versions.props | 75 ++++++++----------- .../Roslyn.SDK.Template.Wizard.csproj | 21 +----- .../Roslyn.SyntaxVisualizer.Control.csproj | 17 ++--- .../Roslyn.SyntaxVisualizer.DgmlHelper.vbproj | 8 +- .../Roslyn.SyntaxVisualizer.Extension.csproj | 24 ++---- .../Roslyn.SDK.IntegrationTests.csproj | 8 ++ 6 files changed, 57 insertions(+), 96 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 216fe81409..0a3d49706d 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -13,58 +13,49 @@ 3.8.0-4.20464.1 16.1.1 - - - - 3.0.0 - 3.3.1 - 3.3.1 - 3.3.1 - 3.3.1 - 3.3.1 + + + + + + 3.3.2 + 3.8.0 + 3.8.0 + 3.8.0 + 3.8.0 + 3.8.0 + - - 7.0.3300 - 12.0.4 - 8.0.1 - 8.0.0 - 16.4.280 - 16.4.280 - 16.4.280 - 16.4.280 - 7.10.6071 - 16.5.29911.84 - 16.5.29911.84 - 7.10.6072 - 8.0.50728 - 9.0.30730 - 10.0.30320 - 11.0.61031 - 12.1.30329 - 14.3.26929 - 15.7.1 - 16.4.280 - 16.4.280 - 7.10.6071 - 16.4.280 - 16.4.280 - 16.5.29903.186 - 16.5.132 + 16.8.239 + 16.7.30328.74 + 16.7.9 + 16.0.206 + 16.7.30329.88 + 16.7.30329.88 + 16.7.30328.74 + 16.7.30328.74 + 16.7.30328.74 + 16.7.30328.74 + 16.7.30328.74 + 16.8.239 + 16.8.239 + 16.7.30328.74 + 16.8.55 + 16.3.23 5.6.0 - 2.3.99 + 2.5.44 + 12.0.4 + - 1.3.1 - 1.1.0 - 1.4.2 1.4.4 + 2.6.1 3.8.0 1.0.1-beta1.20374.2 1.2.7 0.1.49-beta + 2.9.8 1.2.0-beta.164 diff --git a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/Roslyn.SDK.Template.Wizard.csproj b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/Roslyn.SDK.Template.Wizard.csproj index 71eac5d5a2..a2f1b14c3b 100644 --- a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/Roslyn.SDK.Template.Wizard.csproj +++ b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/Roslyn.SDK.Template.Wizard.csproj @@ -7,26 +7,7 @@ - - - - - - - - - - - - - - - - - - - - + diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj index b49c1a4c9b..f6261fa079 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj @@ -11,17 +11,12 @@ - - - - - - - - - - - + + + + + + diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.DgmlHelper/Roslyn.SyntaxVisualizer.DgmlHelper.vbproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.DgmlHelper/Roslyn.SyntaxVisualizer.DgmlHelper.vbproj index d54d6e6079..262a8975c6 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.DgmlHelper/Roslyn.SyntaxVisualizer.DgmlHelper.vbproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.DgmlHelper/Roslyn.SyntaxVisualizer.DgmlHelper.vbproj @@ -11,10 +11,10 @@ - - - - + + + + diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj index 1619cb0160..03f01cead1 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj @@ -24,28 +24,14 @@ - - - - - - - + + + + - - - - - - - + - - - - - diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj index d8d0265eb4..62ac0ada43 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj @@ -19,11 +19,19 @@ + + + + + + + + From 60afadd6872f2ccc2fb6ab244a9c061bee28f3c7 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Mon, 25 Jan 2021 18:02:49 -0800 Subject: [PATCH 02/14] add non-nullable references support --- .../Roslyn.SyntaxVisualizer.Control.csproj | 2 ++ .../Roslyn.SyntaxVisualizer.Extension.csproj | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj index f6261fa079..354a8a12bb 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj @@ -7,6 +7,8 @@ false true true + enable + 9 diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj index 03f01cead1..29453ba95c 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj @@ -7,6 +7,8 @@ false false true + enable + 9 false From 52acf72a148d3b3c497e8d30511a7b0e1601df48 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Mon, 25 Jan 2021 18:03:15 -0800 Subject: [PATCH 03/14] annotate syntax visualizer --- .../ColorPickerViewModel.cs | 2 +- .../ControlExtensions.cs | 7 +- .../SymbolDisplay/BasePropertyGridAdapter.cs | 4 +- .../SyntaxKindHelper.cs | 4 +- .../SyntaxVisualizerControl.xaml.cs | 160 +++++++++++------- .../TabStopPanel.cs | 4 +- .../HelperExtensionMethods.cs | 4 +- .../SyntaxVisualizerContainer.xaml.cs | 100 ++++++----- .../InProcess/InProcComponent.cs | 4 + 9 files changed, 172 insertions(+), 117 deletions(-) diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/ColorPickerViewModel.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/ColorPickerViewModel.cs index 96c9f4687e..269184d4e5 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/ColorPickerViewModel.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/ColorPickerViewModel.cs @@ -184,7 +184,7 @@ private void UpdateColorComponents() } #region NotifyPropertyChanged - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; private bool SetProperty(ref T backingField, T value, [CallerMemberName] string propertyName = "") { if (EqualityComparer.Default.Equals(backingField, value)) diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/ControlExtensions.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/ControlExtensions.cs index 81cefbb70b..e09144d915 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/ControlExtensions.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/ControlExtensions.cs @@ -29,7 +29,7 @@ internal static Color GetColorAtOffset(this GradientStopCollection collection, d } GradientStop left = stops[0]; - GradientStop right = null; + GradientStop? right = null; foreach (GradientStop stop in stops) { @@ -42,6 +42,11 @@ internal static Color GetColorAtOffset(this GradientStopCollection collection, d left = stop; } + if (right is null) + { + return left.Color; + } + double percent = Math.Round((offset - left.Offset) / (right.Offset - left.Offset), 3); byte a = (byte)((right.Color.A - left.Color.A) * percent + left.Color.A); byte r = (byte)((right.Color.R - left.Color.R) * percent + left.Color.R); diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SymbolDisplay/BasePropertyGridAdapter.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SymbolDisplay/BasePropertyGridAdapter.cs index f2299d455c..d9470090ab 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SymbolDisplay/BasePropertyGridAdapter.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SymbolDisplay/BasePropertyGridAdapter.cs @@ -12,12 +12,12 @@ internal abstract class BasePropertyGridAdapter : ICustomTypeDescriptor public virtual string GetComponentName() => TypeDescriptor.GetClassName(this, true); public virtual TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); public virtual EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); - public virtual PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public virtual PropertyDescriptor? GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); public virtual object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); public virtual EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); public virtual EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); public virtual PropertyDescriptorCollection GetProperties() => TypeDescriptor.GetProperties(this, true); public virtual PropertyDescriptorCollection GetProperties(Attribute[] attributes) => TypeDescriptor.GetProperties(this, attributes, true); - public virtual object GetPropertyOwner(PropertyDescriptor pd) => null; + public virtual object? GetPropertyOwner(PropertyDescriptor pd) => null; } } diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxKindHelper.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxKindHelper.cs index 15ce4a2611..af62333089 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxKindHelper.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxKindHelper.cs @@ -15,9 +15,9 @@ public static string GetKind(this SyntaxNodeOrToken nodeOrToken) { var kind = string.Empty; - if (nodeOrToken.IsNode) + if (nodeOrToken.IsNode && nodeOrToken.AsNode() is SyntaxNode node) { - kind = nodeOrToken.AsNode().GetKind(); + kind = node.GetKind(); } else { diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs index 507834971e..55397cb8c2 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs @@ -14,6 +14,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; + using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.Text; @@ -23,7 +24,9 @@ using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Text.Adornments; using Microsoft.VisualStudio.Text.Classification; + using Roslyn.SyntaxVisualizer.Control.SymbolDisplay; + using SystemInformation = System.Windows.Forms.SystemInformation; namespace Roslyn.SyntaxVisualizer.Control @@ -52,16 +55,16 @@ private class SyntaxTag { internal TextSpan Span { get; set; } internal TextSpan FullSpan { get; set; } - internal TreeViewItem ParentItem { get; set; } - internal string Kind { get; set; } - internal SyntaxNode SyntaxNode { get; set; } + internal TreeViewItem? ParentItem { get; set; } + internal string? Kind { get; set; } + internal SyntaxNode? SyntaxNode { get; set; } internal SyntaxToken SyntaxToken { get; set; } internal SyntaxTrivia SyntaxTrivia { get; set; } internal SyntaxCategory Category { get; set; } } #region Private State - private TreeViewItem _currentSelection; + private TreeViewItem? _currentSelection; private bool _isNavigatingFromSourceToTree; private bool _isNavigatingFromTreeToSource; private readonly System.Windows.Forms.PropertyGrid _propertyGrid; @@ -94,26 +97,26 @@ private class SyntaxTag /// we temporarily clear the specified foreground color and restore it when the item is /// unselected. This field is used to save and restore that foreground color. /// - private Brush _currentSelectionUnselectedForeground; + private Brush? _currentSelectionUnselectedForeground; private ImmutableArray classifiedSpans; #endregion #region Public Properties, Events - public SyntaxTree SyntaxTree { get; private set; } - public SemanticModel SemanticModel { get; private set; } + public SyntaxTree? SyntaxTree { get; private set; } + public SemanticModel? SemanticModel { get; private set; } public bool IsLazy { get; private set; } - public delegate void SyntaxNodeDelegate(SyntaxNode node); - public event SyntaxNodeDelegate SyntaxNodeDirectedGraphRequested; - public event SyntaxNodeDelegate SyntaxNodeNavigationToSourceRequested; + public delegate void SyntaxNodeDelegate(SyntaxNode? node); + public event SyntaxNodeDelegate? SyntaxNodeDirectedGraphRequested; + public event SyntaxNodeDelegate? SyntaxNodeNavigationToSourceRequested; public delegate void SyntaxTokenDelegate(SyntaxToken token); - public event SyntaxTokenDelegate SyntaxTokenDirectedGraphRequested; - public event SyntaxTokenDelegate SyntaxTokenNavigationToSourceRequested; + public event SyntaxTokenDelegate? SyntaxTokenDirectedGraphRequested; + public event SyntaxTokenDelegate? SyntaxTokenNavigationToSourceRequested; public delegate void SyntaxTriviaDelegate(SyntaxTrivia trivia); - public event SyntaxTriviaDelegate SyntaxTriviaDirectedGraphRequested; - public event SyntaxTriviaDelegate SyntaxTriviaNavigationToSourceRequested; + public event SyntaxTriviaDelegate? SyntaxTriviaDirectedGraphRequested; + public event SyntaxTriviaDelegate? SyntaxTriviaNavigationToSourceRequested; private ClassifiedSpan? _classifiedSpan; public ClassifiedSpan? ClassifiedSpan @@ -142,7 +145,10 @@ public ClassifiedSpan? ClassifiedSpan { colorLabel.Visibility = Visibility.Visible; colorPickerGrid.Visibility = Visibility.Visible; - colorPickerButton.Background = new SolidColorBrush(color.Value); + if (color is not null) + { + colorPickerButton.Background = new SolidColorBrush(color.Value); + } var textValue = _classifiedSpan?.ClassificationType; if (string.IsNullOrEmpty(textValue)) @@ -214,12 +220,16 @@ private void ColorPickerButton_Click(object sender, RoutedEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); - var color = ((SolidColorBrush)colorPickerButton.Background).Color; + var color = ( (SolidColorBrush)colorPickerButton.Background ).Color; var popup = new ColorPickerWindow(color); if (popup.ShowDialog() == true) { - FontsAndColorsHelper.UpdateClassificationColor(_classifiedSpan.Value, popup.Color); + if (_classifiedSpan is not null) + { + FontsAndColorsHelper.UpdateClassificationColor(_classifiedSpan.Value, popup.Color); + } + colorPickerButton.Background = new SolidColorBrush(popup.Color); } @@ -323,7 +333,7 @@ public void Clear() // the children for any given item are only populated when the item is selected. If lazy is // false then the entire tree is populated at once (and this can result in bad performance when // displaying large trees). - public void DisplaySyntaxTree(SyntaxTree tree, SemanticModel model = null, bool lazy = true, Workspace workspace = null) + public void DisplaySyntaxTree(SyntaxTree tree, SemanticModel? model = null, bool lazy = true, Workspace? workspace = null) { if (tree != null) { @@ -347,7 +357,7 @@ public void DisplaySyntaxTree(SyntaxTree tree, SemanticModel model = null, bool // the children for any given item are only populated when the item is selected. If lazy is // false then the entire tree is populated at once (and this can result in bad performance when // displaying large trees). - public void DisplaySyntaxNode(SyntaxNode node, SemanticModel model = null, bool lazy = true) + public void DisplaySyntaxNode(SyntaxNode node, SemanticModel? model = null, bool lazy = true) { if (node != null) { @@ -359,11 +369,11 @@ public void DisplaySyntaxNode(SyntaxNode node, SemanticModel model = null, bool } // Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose position best matches the supplied position. - public bool NavigateToBestMatch(int position, string kind = null, + public bool NavigateToBestMatch(int position, string? kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false) { - TreeViewItem match = null; + TreeViewItem? match = null; if (treeView.HasItems && !_isNavigatingFromTreeToSource) { @@ -372,20 +382,18 @@ public bool NavigateToBestMatch(int position, string kind = null, _isNavigatingFromSourceToTree = false; } - var matchFound = match != null; - - if (highlightMatch && matchFound) + if (highlightMatch && match is not null) { match.Background = Brushes.Yellow; match.BorderBrush = Brushes.Black; match.BorderThickness = s_defaultBorderThickness; } - return matchFound; + return match is not null; } // Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. - public bool NavigateToBestMatch(int start, int length, string kind = null, + public bool NavigateToBestMatch(int start, int length, string? kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false) { @@ -393,11 +401,11 @@ public bool NavigateToBestMatch(int start, int length, string kind = null, } // Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. - public bool NavigateToBestMatch(TextSpan span, string kind = null, + public bool NavigateToBestMatch(TextSpan span, string? kind = null, SyntaxCategory category = SyntaxCategory.None, bool highlightMatch = false) { - TreeViewItem match = null; + TreeViewItem? match = null; if (treeView.HasItems && !_isNavigatingFromTreeToSource) { @@ -406,16 +414,14 @@ public bool NavigateToBestMatch(TextSpan span, string kind = null, _isNavigatingFromSourceToTree = false; } - var matchFound = match != null; - - if (highlightMatch && matchFound) + if (highlightMatch && match is not null) { match.Background = Brushes.Yellow; match.BorderBrush = Brushes.Black; match.BorderThickness = s_defaultBorderThickness; } - return matchFound; + return match is not null; } #endregion @@ -447,7 +453,7 @@ private void DeepCollapse(TreeViewItem item) } // Ensure that the supplied treeview item and all its ancestors are expanded. - private void ExpandPathTo(TreeViewItem item) + private void ExpandPathTo(TreeViewItem? item) { if (item != null) { @@ -457,10 +463,10 @@ private void ExpandPathTo(TreeViewItem item) } // Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose position best matches the supplied position. - private TreeViewItem NavigateToBestMatch(TreeViewItem current, int position, string kind = null, + private TreeViewItem? NavigateToBestMatch(TreeViewItem current, int position, string? kind = null, SyntaxCategory category = SyntaxCategory.None) { - TreeViewItem match = null; + TreeViewItem? match = null; if (current != null) { @@ -478,8 +484,8 @@ private TreeViewItem NavigateToBestMatch(TreeViewItem current, int position, str } } - if (match == null && (kind == null || currentTag.Kind == kind) && - (category == SyntaxCategory.None || category == currentTag.Category)) + if (match == null && ( kind == null || currentTag.Kind == kind ) && + ( category == SyntaxCategory.None || category == currentTag.Category )) { match = current; } @@ -490,17 +496,17 @@ private TreeViewItem NavigateToBestMatch(TreeViewItem current, int position, str } // Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. - private TreeViewItem NavigateToBestMatch(TreeViewItem current, TextSpan span, string kind = null, + private TreeViewItem? NavigateToBestMatch(TreeViewItem current, TextSpan span, string? kind = null, SyntaxCategory category = SyntaxCategory.None) { - TreeViewItem match = null; + 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)) + if (( currentTag.Span == span || currentTag.FullSpan == span ) && ( kind == null || currentTag.Kind == kind )) { CollapseEverythingBut(current); match = current; @@ -511,7 +517,7 @@ private TreeViewItem NavigateToBestMatch(TreeViewItem current, TextSpan span, st foreach (TreeViewItem item in current.Items) { - if (category != SyntaxCategory.Operation && ((SyntaxTag)item.Tag).Category == SyntaxCategory.Operation) + if (category != SyntaxCategory.Operation && ( (SyntaxTag)item.Tag ).Category == SyntaxCategory.Operation) { // Do not prefer navigating to IOperation nodes when clicking in source code continue; @@ -524,8 +530,8 @@ private TreeViewItem NavigateToBestMatch(TreeViewItem current, TextSpan span, st } } - if (match == null && (kind == null || currentTag.Kind == kind) && - (category == SyntaxCategory.None || category == currentTag.Category)) + if (match == null && ( kind == null || currentTag.Kind == kind ) && + ( category == SyntaxCategory.None || category == currentTag.Category )) { match = current; } @@ -669,8 +675,13 @@ static IEnumerable GetOperationInterfaces(IOperation operation) } } - private void AddNode(TreeViewItem parentItem, SyntaxNode node) + private void AddNode(TreeViewItem? parentItem, SyntaxNode? node) { + if (node is null) + { + return; + } + var kind = node.GetKind(); var tag = new SyntaxTag() { @@ -724,10 +735,13 @@ private void AddNode(TreeViewItem parentItem, SyntaxNode node) // Remove placeholder child and populate real children. item.Items.RemoveAt(0); - var operation = SemanticModel.GetOperation(node); - if (operation is { Parent: null }) + if (SemanticModel is not null) { - AddOperation(item, operation); + var operation = SemanticModel.GetOperation(node); + if (operation is { Parent: null }) + { + AddOperation(item, operation); + } } foreach (var child in node.ChildNodesAndTokens()) @@ -877,7 +891,7 @@ private void AddTrivia(TreeViewItem parentItem, SyntaxTrivia trivia, bool isLead ParentItem = parentItem }; - var item = CreateTreeViewItem(tag, (isLeadingTrivia ? "Lead: " : "Trail: ") + tag.Kind + " " + trivia.Span.ToString(), trivia.ContainsDiagnostics); + var item = CreateTreeViewItem(tag, ( isLeadingTrivia ? "Lead: " : "Trail: " ) + tag.Kind + " " + trivia.Span.ToString(), trivia.ContainsDiagnostics); item.SetResourceReference(ForegroundProperty, SyntaxTriviaTextBrushKey); if (SyntaxTree != null && trivia.ContainsDiagnostics) @@ -988,7 +1002,7 @@ private TreeViewItem CreateTreeViewItem(SyntaxTag tag, string text, bool contain #endregion #region Private Helpers - Other - private void DisplaySymbolInPropertyGrid(ISymbol symbol) + private void DisplaySymbolInPropertyGrid(ISymbol? symbol) { if (symbol == null) { @@ -1010,9 +1024,9 @@ private void DisplaySymbolInPropertyGrid(ISymbol symbol) } } - private static TreeViewItem FindTreeViewItem(DependencyObject source) + private static TreeViewItem? FindTreeViewItem(DependencyObject source) { - while (source != null && !(source is TreeViewItem)) + while (source != null && !( source is TreeViewItem )) { if (source is ContentElement contentElement) { @@ -1024,7 +1038,7 @@ private static TreeViewItem FindTreeViewItem(DependencyObject source) } } - return (TreeViewItem)source; + return (TreeViewItem?)source; } #endregion @@ -1067,15 +1081,15 @@ private void TreeView_ContextMenuOpening(object sender, ContextMenuEventArgs e) } var directedSyntaxGraphEnabled = - (SyntaxNodeDirectedGraphRequested != null) && - (SyntaxTokenDirectedGraphRequested != null) && - (SyntaxTriviaDirectedGraphRequested != null); + ( SyntaxNodeDirectedGraphRequested != null ) && + ( SyntaxTokenDirectedGraphRequested != null ) && + ( SyntaxTriviaDirectedGraphRequested != null ); var symbolDetailsEnabled = - (SemanticModel != null) && - (((SyntaxTag)_currentSelection.Tag).Category == SyntaxCategory.SyntaxNode); + ( SemanticModel != null ) && + ( ( (SyntaxTag)_currentSelection.Tag ).Category == SyntaxCategory.SyntaxNode ); - if ((!directedSyntaxGraphEnabled) && (!symbolDetailsEnabled)) + if (( !directedSyntaxGraphEnabled ) && ( !symbolDetailsEnabled )) { e.Handled = true; } @@ -1133,7 +1147,7 @@ private void SymbolDetailsMenuItem_Click(object sender, RoutedEventArgs e) } var currentTag = (SyntaxTag)_currentSelection.Tag; - if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode)) + if (( SemanticModel != null ) && ( currentTag.Category == SyntaxCategory.SyntaxNode ) && currentTag.SyntaxNode is not null) { var symbol = SemanticModel.GetSymbolInfo(currentTag.SyntaxNode).Symbol; if (symbol == null) @@ -1159,7 +1173,13 @@ private void TypeSymbolDetailsMenuItem_Click(object sender, RoutedEventArgs e) } var currentTag = (SyntaxTag)_currentSelection.Tag; - if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode)) + if (currentTag.SyntaxNode is null) + { + e.Handled = true; + return; + } + + if (( SemanticModel != null ) && ( currentTag.Category == SyntaxCategory.SyntaxNode )) { var symbol = SemanticModel.GetTypeInfo(currentTag.SyntaxNode).Type; DisplaySymbolInPropertyGrid(symbol); @@ -1175,7 +1195,13 @@ private void ConvertedTypeSymbolDetailsMenuItem_Click(object sender, RoutedEvent } var currentTag = (SyntaxTag)_currentSelection.Tag; - if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode)) + if (currentTag.SyntaxNode is null) + { + e.Handled = true; + return; + } + + if (( SemanticModel != null ) && ( currentTag.Category == SyntaxCategory.SyntaxNode )) { var symbol = SemanticModel.GetTypeInfo(currentTag.SyntaxNode).ConvertedType; DisplaySymbolInPropertyGrid(symbol); @@ -1191,7 +1217,13 @@ private void AliasSymbolDetailsMenuItem_Click(object sender, RoutedEventArgs e) } var currentTag = (SyntaxTag)_currentSelection.Tag; - if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode)) + if (currentTag.SyntaxNode is null) + { + e.Handled = true; + return; + } + + if (( SemanticModel != null ) && ( currentTag.Category == SyntaxCategory.SyntaxNode )) { var symbol = SemanticModel.GetAliasInfo(currentTag.SyntaxNode); DisplaySymbolInPropertyGrid(symbol); @@ -1207,7 +1239,9 @@ private void ConstantValueDetailsMenuItem_Click(object sender, RoutedEventArgs e } var currentTag = (SyntaxTag)_currentSelection.Tag; - if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode)) + if (SemanticModel != null && + currentTag.Category == SyntaxCategory.SyntaxNode && + currentTag.SyntaxNode is not null) { var value = SemanticModel.GetConstantValue(currentTag.SyntaxNode); kindTextLabel.Visibility = Visibility.Hidden; diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/TabStopPanel.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/TabStopPanel.cs index b23843966a..7add4f10da 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/TabStopPanel.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/TabStopPanel.cs @@ -14,13 +14,13 @@ namespace Roslyn.SyntaxVisualizer.Control internal class TabStopPanel : Panel { private readonly HwndHost _wpfHost; - private PropertyGrid _propertyGrid; + private PropertyGrid? _propertyGrid; public TabStopPanel(HwndHost wpfHost) { _wpfHost = wpfHost; } - public PropertyGrid PropertyGrid + public PropertyGrid? PropertyGrid { get => _propertyGrid; set diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/HelperExtensionMethods.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/HelperExtensionMethods.cs index e580b801ea..91be1f6cbb 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/HelperExtensionMethods.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/HelperExtensionMethods.cs @@ -12,9 +12,9 @@ namespace Roslyn.SyntaxVisualizer.Extension { internal static class HelperExtensionMethods { - internal static IWpfTextView ToWpfTextView(this IVsWindowFrame vsWindowFrame) + internal static IWpfTextView? ToWpfTextView(this IVsWindowFrame vsWindowFrame) { - IWpfTextView wpfTextView = null; + IWpfTextView? wpfTextView = null; var vsTextView = VsShellUtilities.GetTextView(vsWindowFrame); if (vsTextView != null) diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs index 72c5c3a930..2427b98147 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs @@ -8,6 +8,7 @@ using System.Windows.Controls; using System.Windows.Threading; using System.Xml.Linq; + using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.Text; @@ -17,6 +18,7 @@ using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Text.Classification; using Microsoft.VisualStudio.Text.Editor; + using Roslyn.SyntaxVisualizer.DgmlHelper; namespace Roslyn.SyntaxVisualizer.Extension @@ -26,11 +28,11 @@ namespace Roslyn.SyntaxVisualizer.Extension internal partial class SyntaxVisualizerContainer : UserControl, IVsRunningDocTableEvents, IVsSolutionEvents, IDisposable { private readonly SyntaxVisualizerToolWindow parent; - private IWpfTextView activeWpfTextView; - private IClassificationFormatMap activeClassificationFormatMap; - private IEditorFormatMap activeEditorFormatMap; - private SyntaxTree activeSyntaxTree; - private DispatcherTimer typingTimer; + private IWpfTextView? activeWpfTextView; + private IClassificationFormatMap? activeClassificationFormatMap; + private IEditorFormatMap? activeEditorFormatMap; + private SyntaxTree? activeSyntaxTree; + private DispatcherTimer? typingTimer; private const string CSharpContentType = "CSharp"; private const string VisualBasicContentType = "Basic"; @@ -62,7 +64,7 @@ internal SyntaxVisualizerContainer(SyntaxVisualizerToolWindow parent) UpdateThemedColors(); - syntaxVisualizer.SyntaxNodeNavigationToSourceRequested += node => NavigateToSource(node.Span); + syntaxVisualizer.SyntaxNodeNavigationToSourceRequested += node => NavigateToSource(node?.Span); syntaxVisualizer.SyntaxTokenNavigationToSourceRequested += token => NavigateToSource(token.Span); syntaxVisualizer.SyntaxTriviaNavigationToSourceRequested += trivia => NavigateToSource(trivia.Span); } @@ -78,7 +80,10 @@ internal void UpdateThemedColors() if (activeClassificationFormatMap != null && activeEditorFormatMap != null) { var classificationTypeRegistryService = GetMefService(); - syntaxVisualizer.SetTreeViewColors(classificationTypeRegistryService, activeClassificationFormatMap, activeEditorFormatMap); + if (classificationTypeRegistryService is not null) + { + syntaxVisualizer.SetTreeViewColors(classificationTypeRegistryService, activeClassificationFormatMap, activeEditorFormatMap); + } } } @@ -121,7 +126,7 @@ internal void Clear() } #region Helpers - GetService - private static Microsoft.VisualStudio.OLE.Interop.IServiceProvider globalServiceProvider; + private static Microsoft.VisualStudio.OLE.Interop.IServiceProvider? globalServiceProvider; private static Microsoft.VisualStudio.OLE.Interop.IServiceProvider GlobalServiceProvider { get @@ -138,11 +143,11 @@ private static Microsoft.VisualStudio.OLE.Interop.IServiceProvider GlobalService } } - private TServiceInterface GetService() + private TServiceInterface? GetService() where TServiceInterface : class where TService : class { - TServiceInterface service = null; + TServiceInterface? service = null; if (parent != null) { @@ -152,12 +157,12 @@ private TServiceInterface GetService() return service; } - private static object GetService( + private static object? GetService( Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider, Guid guidService, bool unique) { var guidInterface = VSConstants.IID_IUnknown; var ptr = IntPtr.Zero; - object service = null; + object? service = null; #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread if (serviceProvider.QueryService(ref guidService, ref guidInterface, out ptr) == 0 && @@ -184,17 +189,17 @@ private static object GetService( return service; } - private static TServiceInterface GetService( + private static TServiceInterface? GetService( Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider) where TServiceInterface : class where TService : class { - return (TServiceInterface)GetService(serviceProvider, typeof(TService).GUID, false); + return (TServiceInterface?)GetService(serviceProvider, typeof(TService).GUID, false); } - private static TServiceInterface GetMefService() where TServiceInterface : class + private static TServiceInterface? GetMefService() where TServiceInterface : class { - TServiceInterface service = null; + TServiceInterface? service = null; var componentModel = GetService(GlobalServiceProvider); if (componentModel != null) @@ -209,8 +214,8 @@ private static TServiceInterface GetMefService() where TServi #region Helpers - Initialize and Dispose IVsRunningDocumentTable private uint runningDocumentTableCookie; - private IVsRunningDocumentTable runningDocumentTable; - private IVsRunningDocumentTable RunningDocumentTable + private IVsRunningDocumentTable? runningDocumentTable; + private IVsRunningDocumentTable? RunningDocumentTable { get { @@ -238,7 +243,7 @@ void IDisposable.Dispose() if (runningDocumentTableCookie != 0) { #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread - runningDocumentTable.UnadviseRunningDocTableEvents(runningDocumentTableCookie); + runningDocumentTable?.UnadviseRunningDocTableEvents(runningDocumentTableCookie); #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread runningDocumentTableCookie = 0; } @@ -268,7 +273,7 @@ private void RefreshSyntaxVisualizer() var activeSemanticModel = ThreadHelper.JoinableTaskFactory.Run(() => document.GetSemanticModelAsync()); // Display the SyntaxTree. - if (contentType.IsOfType(VisualBasicContentType) || contentType.IsOfType(CSharpContentType)) + if (( contentType.IsOfType(VisualBasicContentType) || contentType.IsOfType(CSharpContentType) ) && activeSyntaxTree is not null) { syntaxVisualizer.DisplaySyntaxTree(activeSyntaxTree, activeSemanticModel, workspace: document.Project.Solution.Workspace); } @@ -290,11 +295,11 @@ private void NavigateFromSource() } // When user clicks on a particular item in the treeview select the corresponding text in the editor. - private void NavigateToSource(TextSpan span) + private void NavigateToSource(TextSpan? span) { - if (IsVisible && activeWpfTextView != null) + if (IsVisible && activeWpfTextView != null && span is TextSpan nonNullableSpan) { - var snapShotSpan = span.ToSnapshotSpan(activeWpfTextView.TextBuffer.CurrentSnapshot); + var snapShotSpan = nonNullableSpan.ToSnapshotSpan(activeWpfTextView.TextBuffer.CurrentSnapshot); // See SyntaxVisualizerToolWindow_GotFocus and SyntaxVisualizerToolWindow_LostFocus // for some notes about selection opacity and why it needs to be manipulated. @@ -337,7 +342,7 @@ private void HandleTextViewLostFocus(object sender, EventArgs e) private void HandleTypingTimerTimeout(object sender, EventArgs e) { - typingTimer.Stop(); + typingTimer?.Stop(); RefreshSyntaxVisualizer(); } @@ -361,10 +366,16 @@ int IVsRunningDocTableEvents.OnBeforeDocumentWindowShow(uint docCookie, int isFi var classificationFormatMapService = GetMefService(); var editorFormatMapService = GetMefService(); - activeClassificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(activeWpfTextView); - activeClassificationFormatMap.ClassificationFormatMappingChanged += HandleFormatMappingChanged; - activeEditorFormatMap = editorFormatMapService.GetEditorFormatMap(activeWpfTextView); - activeEditorFormatMap.FormatMappingChanged += HandleFormatMappingChanged; + activeClassificationFormatMap = classificationFormatMapService?.GetClassificationFormatMap(activeWpfTextView); + if (activeClassificationFormatMap is not null) + { + activeClassificationFormatMap.ClassificationFormatMappingChanged += HandleFormatMappingChanged; + } + activeEditorFormatMap = editorFormatMapService?.GetEditorFormatMap(activeWpfTextView); + if (activeEditorFormatMap is not null) + { + activeEditorFormatMap.FormatMappingChanged += HandleFormatMappingChanged; + } UpdateThemedColors(); RefreshSyntaxVisualizer(); @@ -414,9 +425,9 @@ int IVsRunningDocTableEvents.OnAfterSave(uint docCookie) #endregion #region Event Handlers - Directed Syntax Graph / IVsSolutionEvents Events - private string dgmlFilePath; - private IVsFileChangeEx fileChangeService; - private IVsFileChangeEx FileChangeService + private string? dgmlFilePath; + private IVsFileChangeEx? fileChangeService; + private IVsFileChangeEx? FileChangeService { get { @@ -429,8 +440,8 @@ private IVsFileChangeEx FileChangeService } } - private IVsSolution solutionService; - private IVsSolution SolutionService + private IVsSolution? solutionService; + private IVsSolution? SolutionService { get { @@ -443,7 +454,7 @@ private IVsSolution SolutionService } } - private void DisplayDgml(XElement dgml) + private void DisplayDgml(XElement? dgml) { uint cookie; const int TRUE = -1; @@ -466,8 +477,9 @@ private void DisplayDgml(XElement dgml) #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread out var docUIHierarchy, out var docItemId, out var docWindowFrame) && docWindowFrame != null) { + if (RunningDocumentTable is not null && #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread - if (RunningDocumentTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, dgmlFilePath, + RunningDocumentTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, dgmlFilePath, #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread out var docHierarchy, out docItemId, out var docDataIUnknownPointer, @@ -490,16 +502,16 @@ private void DisplayDgml(XElement dgml) // The below call ensures that there are no pop-ups from Visual Studio // prompting the user to reload the file each time it is changed. #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread - FileChangeService.IgnoreFile(0, dgmlFilePath, TRUE); + FileChangeService?.IgnoreFile(0, dgmlFilePath, TRUE); #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread // Update the file on disk with the new directed syntax graph. - dgml.Save(dgmlFilePath); + dgml?.Save(dgmlFilePath); // The below calls ensure that the file is refreshed inside Visual Studio // so that the latest contents are displayed to the user. #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread - FileChangeService.SyncFile(dgmlFilePath); + FileChangeService?.SyncFile(dgmlFilePath); persistDocDataService.ReloadDocData((uint)_VSRELOADDOCDATA.RDD_IgnoreNextFileChange); #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread @@ -519,7 +531,7 @@ private void DisplayDgml(XElement dgml) else { // Update the file on disk with the new directed syntax graph. - dgml.Save(dgmlFilePath); + dgml?.Save(dgmlFilePath); // Open the new directed syntax graph in the 'design' view. VsShellUtilities.OpenDocument( @@ -532,18 +544,18 @@ private void DisplayDgml(XElement dgml) // This ensures that the file won't be persisted in the .suo file and that it therefore won't get re-opened // when the solution is re-opened. #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread - SolutionService.AdviseSolutionEvents(this, out cookie); + SolutionService?.AdviseSolutionEvents(this, out cookie); #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread } } - private void DisplaySyntaxNodeDgml(SyntaxNode node) + private void DisplaySyntaxNodeDgml(SyntaxNode? node) { if (activeWpfTextView != null) { var snapshot = activeWpfTextView.TextBuffer.CurrentSnapshot; var contentType = snapshot.ContentType; - XElement dgml = null; + XElement? dgml = null; if (contentType.IsOfType(CSharpContentType) || contentType.IsOfType(VisualBasicContentType)) { @@ -560,7 +572,7 @@ private void DisplaySyntaxTokenDgml(SyntaxToken token) { var snapshot = activeWpfTextView.TextBuffer.CurrentSnapshot; var contentType = snapshot.ContentType; - XElement dgml = null; + XElement? dgml = null; if (contentType.IsOfType(CSharpContentType) || contentType.IsOfType(VisualBasicContentType)) { @@ -577,7 +589,7 @@ private void DisplaySyntaxTriviaDgml(SyntaxTrivia trivia) { var snapshot = activeWpfTextView.TextBuffer.CurrentSnapshot; var contentType = snapshot.ContentType; - XElement dgml = null; + XElement? dgml = null; if (contentType.IsOfType(CSharpContentType) || contentType.IsOfType(VisualBasicContentType)) { diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs index f489684626..307a699ca1 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs @@ -40,9 +40,13 @@ protected async Task GetGlobalServiceAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); +#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. +#pragma warning disable CS8603 // Possible null reference return. var serviceProvider = (IAsyncServiceProvider2)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SAsyncServiceProvider)); Assumes.Present(serviceProvider); return (TInterface)await serviceProvider.GetServiceAsync(typeof(TService)); +#pragma warning restore CS8603 // Possible null reference return. +#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. } protected async Task GetComponentModelServiceAsync() From a9d6001676115fca2aefae2846fe35ab605af387 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Tue, 26 Jan 2021 18:15:13 -0800 Subject: [PATCH 04/14] move common properties to build.props --- src/Directory.Build.props | 6 ++++-- .../RoslynSDKAnalyzerTemplateWizard.cs | 2 +- .../RoslynSDKChildTemplateWizard.InterfaceMembers.cs | 6 ++++-- .../RoslynSDKCodeFixTemplateWizard.cs | 2 +- .../RoslynSDKRootTemplateWizard.InterfaceMembers.cs | 5 ++++- .../Roslyn.SyntaxVisualizer.Control.csproj | 2 -- .../Roslyn.SyntaxVisualizer.Extension.csproj | 2 -- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 682ceac121..c159990977 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -13,14 +13,16 @@ - 15.5 + 16 - 8.0 + preview + 9999 + enable diff --git a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKAnalyzerTemplateWizard.cs b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKAnalyzerTemplateWizard.cs index eb1a6acd6c..b0a5791a52 100644 --- a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKAnalyzerTemplateWizard.cs +++ b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKAnalyzerTemplateWizard.cs @@ -4,7 +4,7 @@ public class RoslynSDKAnalyzerTemplateWizard : RoslynSDKChildTemplateWizard { - public static Project Project { get; private set; } + public static Project? Project { get; private set; } public override void OnProjectFinishedGenerating(Project project) { diff --git a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKChildTemplateWizard.InterfaceMembers.cs b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKChildTemplateWizard.InterfaceMembers.cs index 0d4a299e71..8d6ba5d8f0 100644 --- a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKChildTemplateWizard.InterfaceMembers.cs +++ b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKChildTemplateWizard.InterfaceMembers.cs @@ -18,7 +18,9 @@ public void ProjectItemFinishedGenerating(ProjectItem projectItem) { } public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { ThreadHelper.ThrowIfNotOnUIThread(); - - OnRunStarted(automationObject as DTE, replacementsDictionary, runKind, customParams); + if (automationObject is DTE dte) + { + OnRunStarted(dte, replacementsDictionary, runKind, customParams); + } } } diff --git a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKCodeFixTemplateWizard.cs b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKCodeFixTemplateWizard.cs index e46896a572..f19a27dea0 100644 --- a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKCodeFixTemplateWizard.cs +++ b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKCodeFixTemplateWizard.cs @@ -6,7 +6,7 @@ public class RoslynSDKCodeFixTemplateWizard : RoslynSDKChildTemplateWizard { - public static Project Project { get; private set; } + public static Project? Project { get; private set; } public override void OnProjectFinishedGenerating(Project project) { diff --git a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKRootTemplateWizard.InterfaceMembers.cs b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKRootTemplateWizard.InterfaceMembers.cs index 51e48abb4a..d6559c2fda 100644 --- a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKRootTemplateWizard.InterfaceMembers.cs +++ b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/RoslynSDKRootTemplateWizard.InterfaceMembers.cs @@ -16,6 +16,9 @@ public void RunStarted(object automationObject, Dictionary repla { ThreadHelper.ThrowIfNotOnUIThread(); - OnRunStarted(automationObject as DTE, replacementsDictionary, runKind, customParams); + if (automationObject is DTE dte) + { + OnRunStarted(dte, replacementsDictionary, runKind, customParams); + } } } diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj index 354a8a12bb..f6261fa079 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj @@ -7,8 +7,6 @@ false true true - enable - 9 diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj index 29453ba95c..03f01cead1 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj @@ -7,8 +7,6 @@ false false true - enable - 9 false From 737e87463228929f41a5ffa9fac58a88c858e889 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Tue, 26 Jan 2021 18:34:09 -0800 Subject: [PATCH 05/14] update LangVersion --- tests/VisualStudio.Roslyn.SDK/Directory.Build.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/VisualStudio.Roslyn.SDK/Directory.Build.props b/tests/VisualStudio.Roslyn.SDK/Directory.Build.props index 2c3ad8c9b9..a5c0a7c0ac 100644 --- a/tests/VisualStudio.Roslyn.SDK/Directory.Build.props +++ b/tests/VisualStudio.Roslyn.SDK/Directory.Build.props @@ -17,13 +17,13 @@ - 15.5 + 16 - 8 + 9 From 270e853b7bd1332b8c1b87a40dcca392b1b6a53f Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Tue, 26 Jan 2021 18:36:06 -0800 Subject: [PATCH 06/14] small fixes --- .../SyntaxKindHelper.cs | 68 ++++--------------- .../SyntaxVisualizerControl.xaml.cs | 16 ++--- .../SyntaxVisualizerContainer.xaml.cs | 17 ++--- .../InProcess/EditorInProcess.cs | 2 +- .../InProcess/ErrorListInProcess.cs | 4 +- .../InProcess/InProcComponent.cs | 23 ++++--- .../InProcess/SolutionExplorerInProcess.cs | 28 ++++---- 7 files changed, 58 insertions(+), 100 deletions(-) diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxKindHelper.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxKindHelper.cs index af62333089..6d7ac4f455 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxKindHelper.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxKindHelper.cs @@ -12,67 +12,23 @@ public static class SyntaxKindHelper // SyntaxNode / SyntaxToken / SyntaxTrivia. public static string GetKind(this SyntaxNodeOrToken nodeOrToken) - { - var kind = string.Empty; - - if (nodeOrToken.IsNode && nodeOrToken.AsNode() is SyntaxNode node) - { - kind = node.GetKind(); - } - else - { - kind = nodeOrToken.AsToken().GetKind(); - } - - return kind; - } + => nodeOrToken.AsNode() is SyntaxNode node + ? node.GetKind() + : nodeOrToken.AsToken().GetKind(); public static string GetKind(this SyntaxNode node) - { - var kind = string.Empty; - - if (node.Language == LanguageNames.CSharp) - { - kind = CSharpExtensions.Kind(node).ToString(); - } - else - { - kind = VisualBasicExtensions.Kind(node).ToString(); - } - - return kind; - } + => node.Language == LanguageNames.CSharp + ? CSharpExtensions.Kind(node).ToString() + : VisualBasicExtensions.Kind(node).ToString(); public static string GetKind(this SyntaxToken token) - { - var kind = string.Empty; - - if (token.Language == LanguageNames.CSharp) - { - kind = CSharpExtensions.Kind(token).ToString(); - } - else - { - kind = VisualBasicExtensions.Kind(token).ToString(); - } - - return kind; - } + => token.Language == LanguageNames.CSharp + ? CSharpExtensions.Kind(token).ToString() + : VisualBasicExtensions.Kind(token).ToString(); public static string GetKind(this SyntaxTrivia trivia) - { - var kind = string.Empty; - - if (trivia.Language == LanguageNames.CSharp) - { - kind = CSharpExtensions.Kind(trivia).ToString(); - } - else - { - kind = VisualBasicExtensions.Kind(trivia).ToString(); - } - - return kind; - } + => trivia.Language == LanguageNames.CSharp + ? CSharpExtensions.Kind(trivia).ToString() + : VisualBasicExtensions.Kind(trivia).ToString(); } } diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs index 55397cb8c2..2f9d27e4ab 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs @@ -3,12 +3,10 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.ComponentModel.Composition; using System.Globalization; using System.Linq; using System.Windows; using System.Windows.Controls; -using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; @@ -220,7 +218,7 @@ private void ColorPickerButton_Click(object sender, RoutedEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); - var color = ( (SolidColorBrush)colorPickerButton.Background ).Color; + var color = ((SolidColorBrush)colorPickerButton.Background).Color; var popup = new ColorPickerWindow(color); if (popup.ShowDialog() == true) @@ -382,12 +380,12 @@ public bool NavigateToBestMatch(int position, string? kind = null, _isNavigatingFromSourceToTree = false; } - if (highlightMatch && match is not null) - { - match.Background = Brushes.Yellow; - match.BorderBrush = Brushes.Black; - match.BorderThickness = s_defaultBorderThickness; - } + if (!highlightMatch || match is null) + return false; + + match.Background = Brushes.Yellow; + match.BorderBrush = Brushes.Black; + match.BorderThickness = s_defaultBorderThickness; return match is not null; } diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs index 2427b98147..fb0e160b15 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Immutable; using System.IO; using System.Runtime.InteropServices; using System.Windows; @@ -10,7 +9,6 @@ using System.Xml.Linq; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio; using Microsoft.VisualStudio.ComponentModelHost; @@ -46,7 +44,7 @@ internal SyntaxVisualizerContainer(SyntaxVisualizerToolWindow parent) InitializeRunningDocumentTable(); - var shellService = GetService(GlobalServiceProvider); + var shellService = GetRequiredMefService(GlobalServiceProvider); if (shellService != null) { @@ -71,7 +69,7 @@ internal SyntaxVisualizerContainer(SyntaxVisualizerToolWindow parent) internal void UpdateThemedColors() { - var uiShellService = GetService(GlobalServiceProvider); + var uiShellService = GetRequiredMefService(GlobalServiceProvider); if (uiShellService != null) { syntaxVisualizer.SetPropertyGridColors(uiShellService); @@ -189,18 +187,21 @@ private static Microsoft.VisualStudio.OLE.Interop.IServiceProvider GlobalService return service; } - private static TServiceInterface? GetService( + private static TServiceInterface GetRequiredMefService( Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider) where TServiceInterface : class where TService : class { - return (TServiceInterface?)GetService(serviceProvider, typeof(TService).GUID, false); + var service = (TServiceInterface?)GetService(serviceProvider, typeof(TService).GUID, false); + return service is null + ? throw new InvalidOperationException($"Unable to get service '{typeof(TServiceInterface).FullName}'") + : service; } private static TServiceInterface? GetMefService() where TServiceInterface : class { TServiceInterface? service = null; - var componentModel = GetService(GlobalServiceProvider); + var componentModel = GetRequiredMefService(GlobalServiceProvider); if (componentModel != null) { @@ -221,7 +222,7 @@ private IVsRunningDocumentTable? RunningDocumentTable { if (runningDocumentTable == null) { - runningDocumentTable = GetService(GlobalServiceProvider); + runningDocumentTable = GetRequiredMefService(GlobalServiceProvider); } return runningDocumentTable; diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/EditorInProcess.cs b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/EditorInProcess.cs index da5a38bde2..03936d8d76 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/EditorInProcess.cs +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/EditorInProcess.cs @@ -28,7 +28,7 @@ private async Task GetActiveVsTextViewAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var vsTextManager = await GetGlobalServiceAsync(); + var vsTextManager = await GetRequiredGlobalServiceAsync(); ErrorHandler.ThrowOnFailure(vsTextManager.GetActiveView(fMustHaveFocus: 1, pBuffer: null, ppView: out var vsTextView)); diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/ErrorListInProcess.cs b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/ErrorListInProcess.cs index 21fea7306b..63e8cbfb89 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/ErrorListInProcess.cs +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/ErrorListInProcess.cs @@ -27,7 +27,7 @@ public async Task ShowBuildErrorsAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var errorList = await GetGlobalServiceAsync(); + var errorList = await GetRequiredGlobalServiceAsync(); errorList.AreBuildErrorSourceEntriesShown = true; errorList.AreOtherErrorSourceEntriesShown = false; errorList.AreErrorsShown = true; @@ -91,7 +91,7 @@ private async Task> GetErrorItemsAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var errorList = await GetGlobalServiceAsync(); + var errorList = await GetRequiredGlobalServiceAsync(); var args = await errorList.TableControl.ForceUpdateAsync(); return args.AllEntries.ToImmutableArray(); } diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs index 307a699ca1..a0ea448ea7 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs @@ -7,10 +7,12 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Threading; + using Microsoft.VisualStudio.ComponentModelHost; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Threading; + using Task = System.Threading.Tasks.Task; namespace Microsoft.CodeAnalysis.Testing.InProcess @@ -30,29 +32,30 @@ protected async Task ExecuteCommandAsync(string commandName, string args = "") { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var dte = await GetGlobalServiceAsync(); + var dte = await GetRequiredGlobalServiceAsync(); dte.ExecuteCommand(commandName, args); } - protected async Task GetGlobalServiceAsync() + protected async Task GetRequiredGlobalServiceAsync() where TService : class where TInterface : class { await JoinableTaskFactory.SwitchToMainThreadAsync(); -#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. -#pragma warning disable CS8603 // Possible null reference return. - var serviceProvider = (IAsyncServiceProvider2)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SAsyncServiceProvider)); - Assumes.Present(serviceProvider); - return (TInterface)await serviceProvider.GetServiceAsync(typeof(TService)); -#pragma warning restore CS8603 // Possible null reference return. -#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. + var serviceProvider = (IAsyncServiceProvider2?)await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SAsyncServiceProvider)); + if (serviceProvider is null) + { + throw new InvalidOperationException($"Unable to get service {typeof(IAsyncServiceProvider2).FullName}"); + } + + var @interface = (TInterface?)await serviceProvider.GetServiceAsync(typeof(TService)); + return @interface ?? throw new InvalidOperationException($"Unable to get service {typeof(TInterface).FullName}"); } protected async Task GetComponentModelServiceAsync() where TService : class { - var componentModel = await GetGlobalServiceAsync(); + var componentModel = await GetRequiredGlobalServiceAsync(); return componentModel.GetService(); } diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/SolutionExplorerInProcess.cs b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/SolutionExplorerInProcess.cs index 4bbcf6c0ab..8e311a9d24 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/SolutionExplorerInProcess.cs +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/SolutionExplorerInProcess.cs @@ -31,7 +31,7 @@ private async Task IsSolutionOpenAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var solution = await GetGlobalServiceAsync(); + var solution = await GetRequiredGlobalServiceAsync(); ErrorHandler.ThrowOnFailure(solution.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out var isOpen)); return (bool)isOpen; } @@ -56,7 +56,7 @@ private async Task CloseSolutionAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var solution = await GetGlobalServiceAsync(); + var solution = await GetRequiredGlobalServiceAsync(); if (!await IsSolutionOpenAsync()) { return; @@ -98,7 +98,7 @@ private async Task CreateSolutionAsync(string solutionPath, string solutionName) var solutionFileName = Path.ChangeExtension(solutionName, ".sln"); Directory.CreateDirectory(solutionPath); - var solution = await GetGlobalServiceAsync(); + var solution = await GetRequiredGlobalServiceAsync(); ErrorHandler.ThrowOnFailure(solution.CreateSolution(solutionPath, solutionFileName, (uint)__VSCREATESOLUTIONFLAGS.CSF_SILENT)); ErrorHandler.ThrowOnFailure(solution.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, null, 0)); } @@ -112,7 +112,7 @@ public async Task SaveSolutionAsync() throw new InvalidOperationException("Cannot save solution when no solution is open."); } - var solution = await GetGlobalServiceAsync(); + var solution = await GetRequiredGlobalServiceAsync(); // Make sure the directory exists so the Save dialog doesn't appear ErrorHandler.ThrowOnFailure(solution.GetSolutionInfo(out var solutionDirectory, out _, out _)); @@ -135,7 +135,7 @@ private async Task GetDirectoryNameAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var dte = await GetGlobalServiceAsync(); + var dte = await GetRequiredGlobalServiceAsync(); var solution = (EnvDTE80.Solution2)dte.Solution; var solutionFullName = solution.FullName; var solutionFileFullPath = string.IsNullOrEmpty(solutionFullName) @@ -149,7 +149,7 @@ private async Task> GetCSharpProjectTemplate { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var dte = await GetGlobalServiceAsync(); + var dte = await GetRequiredGlobalServiceAsync(); var localeID = dte.LocaleID; var builder = ImmutableDictionary.CreateBuilder(); @@ -166,7 +166,7 @@ private async Task> GetVisualBasicProjectTem { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var dte = await GetGlobalServiceAsync(); + var dte = await GetRequiredGlobalServiceAsync(); var localeID = dte.LocaleID; var builder = ImmutableDictionary.CreateBuilder(); @@ -185,7 +185,7 @@ public async Task AddProjectAsync(string projectName, string projectTemplate, st var projectPath = Path.Combine(await GetDirectoryNameAsync(), projectName); var projectTemplatePath = await GetProjectTemplatePathAsync(projectTemplate, ConvertLanguageName(languageName)); - var solution = await GetGlobalServiceAsync(); + var solution = await GetRequiredGlobalServiceAsync(); ErrorHandler.ThrowOnFailure(solution.AddNewProjectFromTemplate(projectTemplatePath, null, null, projectPath, projectName, null, out _)); } @@ -193,7 +193,7 @@ private async Task GetProjectTemplatePathAsync(string projectTemplate, s { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var dte = await GetGlobalServiceAsync(); + var dte = await GetRequiredGlobalServiceAsync(); var solution = (EnvDTE80.Solution2)dte.Solution; if (string.Equals(languageName, "csharp", StringComparison.OrdinalIgnoreCase) @@ -215,7 +215,7 @@ public async Task RestoreNuGetPackagesAsync(CancellationToken cancellationToken) { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var dte = await GetGlobalServiceAsync(); + var dte = await GetRequiredGlobalServiceAsync(); var solution = (EnvDTE80.Solution2)dte.Solution; foreach (var project in solution.Projects.OfType()) { @@ -227,7 +227,7 @@ public async Task RestoreNuGetPackagesAsync(string projectName, CancellationToke { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var operationProgressStatus = await GetGlobalServiceAsync(); + var operationProgressStatus = await GetRequiredGlobalServiceAsync(); var stageStatus = operationProgressStatus.GetStageStatus(CommonOperationProgressStageIds.Intellisense); await stageStatus.WaitForCompletionAsync(); @@ -281,7 +281,7 @@ public async Task GetBuildOutputWindowPaneAsync() { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var outputWindow = await GetGlobalServiceAsync(); + var outputWindow = await GetRequiredGlobalServiceAsync(); ErrorHandler.ThrowOnFailure(outputWindow.GetPane(VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid, out var pane)); return pane; } @@ -290,7 +290,7 @@ private async Task WaitForBuildToFinishAsync(IVsOutputWindowPane buildOu { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var buildManager = await GetGlobalServiceAsync(); + var buildManager = await GetRequiredGlobalServiceAsync(); using var semaphore = new SemaphoreSlim(1); using var solutionEvents = new UpdateSolutionEvents(buildManager); @@ -330,7 +330,7 @@ private string CreateTemporaryPath() { await JoinableTaskFactory.SwitchToMainThreadAsync(); - var dte = await GetGlobalServiceAsync(); + var dte = await GetRequiredGlobalServiceAsync(); var solution = (EnvDTE80.Solution2)dte.Solution; return solution.Projects.OfType().First( project => From 8b2477e67b4152b6d7d167995673c7f03e5c8451 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Tue, 26 Jan 2021 18:58:37 -0800 Subject: [PATCH 07/14] fix integration project --- eng/Versions.props | 2 ++ .../Roslyn.SDK.IntegrationTests.csproj | 2 ++ 2 files changed, 4 insertions(+) diff --git a/eng/Versions.props b/eng/Versions.props index 0a3d49706d..ad2e3e4ad4 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -34,9 +34,11 @@ 16.7.30329.88 16.7.30328.74 16.7.30328.74 + 16.7.30328.74 16.7.30328.74 16.7.30328.74 16.7.30328.74 + 16.7.30328.74 16.8.239 16.8.239 16.7.30328.74 diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj index 62ac0ada43..5ba1f1701e 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj @@ -25,8 +25,10 @@ + + From a6d07e86113eb02e8d72351bd5efc0a40116fa5b Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Wed, 27 Jan 2021 11:10:34 -0800 Subject: [PATCH 08/14] Update src/Directory.Build.props Co-authored-by: Sam Harwell --- src/Directory.Build.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c159990977..a6bde5ece2 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -20,7 +20,7 @@ - preview + 9 9999 enable @@ -41,4 +41,4 @@ $(CopyrightMicrosoft) MIT - \ No newline at end of file + From f13f68cc7b11bf8d9a12ca352754d092f14c3453 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Wed, 27 Jan 2021 11:10:51 -0800 Subject: [PATCH 09/14] Update src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs Co-authored-by: Sam Harwell --- .../SyntaxVisualizerControl.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs index 2f9d27e4ab..097f32393d 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs @@ -387,7 +387,7 @@ public bool NavigateToBestMatch(int position, string? kind = null, match.BorderBrush = Brushes.Black; match.BorderThickness = s_defaultBorderThickness; - return match is not null; + return true; } // Select the SyntaxNode / SyntaxToken / SyntaxTrivia whose span best matches the supplied span. From efd6ba521a91d88fb390095cc5eba22e3cd9fa1c Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Wed, 27 Jan 2021 11:11:16 -0800 Subject: [PATCH 10/14] Update src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs Co-authored-by: Sam Harwell --- .../SyntaxVisualizerControl.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs index 097f32393d..679bc6ea3c 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs @@ -482,8 +482,8 @@ private void ExpandPathTo(TreeViewItem? item) } } - if (match == null && ( kind == null || currentTag.Kind == kind ) && - ( category == SyntaxCategory.None || category == currentTag.Category )) + if (match == null && (kind == null || currentTag.Kind == kind) && + (category == SyntaxCategory.None || category == currentTag.Category)) { match = current; } From 36faeda316a7b95c42bad38730f57a2872f78396 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Wed, 27 Jan 2021 15:38:03 -0800 Subject: [PATCH 11/14] don't use Microsoft.VisualStudio.SDK --- eng/Versions.props | 15 +++++++++++++-- .../Roslyn.SDK.Template.Wizard.csproj | 12 +++++++++++- .../Roslyn.SyntaxVisualizer.Control.csproj | 15 ++++++++++++++- .../Roslyn.SyntaxVisualizer.Extension.csproj | 17 ++++++++++++++++- .../Roslyn.SDK.IntegrationTests.csproj | 1 + 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index ad2e3e4ad4..b83b9dfd63 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -26,12 +26,21 @@ 3.8.0 + 8.0.0 + 8.0.1 + 2.7.100 + 16.8.239 16.8.239 + 16.8.239 + 16.7.30328.74 16.7.30328.74 + 16.7.30329.63 + 16.8.239 16.7.9 - 16.0.206 16.7.30329.88 16.7.30329.88 + 16.7.30328.74 + 16.7.30328.74 16.7.30328.74 16.7.30328.74 16.7.30328.74 @@ -42,10 +51,12 @@ 16.8.239 16.8.239 16.7.30328.74 + 16.8.239 16.8.55 16.3.23 5.6.0 - 2.5.44 + 2.6.121 + 16.7.30508.193 12.0.4 diff --git a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/Roslyn.SDK.Template.Wizard.csproj b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/Roslyn.SDK.Template.Wizard.csproj index a2f1b14c3b..b06da45aff 100644 --- a/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/Roslyn.SDK.Template.Wizard.csproj +++ b/src/VisualStudio.Roslyn.SDK/Roslyn.SDK.Template.Wizard/Roslyn.SDK.Template.Wizard.csproj @@ -7,7 +7,17 @@ - + + + + + + + + + + + diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj index f6261fa079..9392c305b4 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj @@ -16,7 +16,20 @@ - + + + + + + + + + + + + + + diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj index 03f01cead1..9baf559725 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/Roslyn.SyntaxVisualizer.Extension.csproj @@ -24,14 +24,29 @@ + + - + + + + + + + + + + + + + + diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj index 5ba1f1701e..0c66af099b 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/Roslyn.SDK.IntegrationTests.csproj @@ -19,6 +19,7 @@ + From c1a428a8bdc2bac94c96453339e24eb153fe726c Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Wed, 27 Jan 2021 16:05:49 -0800 Subject: [PATCH 12/14] update Microsoft.VisualStudio.Validation version --- eng/Versions.props | 1 + .../Roslyn.SyntaxVisualizer.Control.csproj | 1 + .../SyntaxVisualizerContainer.xaml.cs | 24 +++++++------------ .../InProcess/InProcComponent.cs | 8 +++---- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index b83b9dfd63..8d3bd6b042 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -54,6 +54,7 @@ 16.8.239 16.8.55 16.3.23 + 16.8.33 5.6.0 2.6.121 16.7.30508.193 diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj index 9392c305b4..6882f34004 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/Roslyn.SyntaxVisualizer.Control.csproj @@ -29,6 +29,7 @@ + diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs index fb0e160b15..ca8f3cfd94 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Extension/SyntaxVisualizerContainer.xaml.cs @@ -8,6 +8,7 @@ using System.Windows.Threading; using System.Xml.Linq; +using Microsoft; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio; @@ -77,7 +78,7 @@ internal void UpdateThemedColors() if (activeClassificationFormatMap != null && activeEditorFormatMap != null) { - var classificationTypeRegistryService = GetMefService(); + var classificationTypeRegistryService = GetRequiredMefService(); if (classificationTypeRegistryService is not null) { syntaxVisualizer.SetTreeViewColors(classificationTypeRegistryService, activeClassificationFormatMap, activeEditorFormatMap); @@ -193,22 +194,15 @@ private static TServiceInterface GetRequiredMefService() where TServiceInterface : class + private static TServiceInterface GetRequiredMefService() where TServiceInterface : class { - TServiceInterface? service = null; var componentModel = GetRequiredMefService(GlobalServiceProvider); - - if (componentModel != null) - { - service = componentModel.GetService(); - } - - return service; + Assumes.Present(componentModel); + return componentModel.GetService(); ; } #endregion @@ -365,8 +359,8 @@ int IVsRunningDocTableEvents.OnBeforeDocumentWindowShow(uint docCookie, int isFi activeWpfTextView.TextBuffer.Changed += HandleTextBufferChanged; activeWpfTextView.LostAggregateFocus += HandleTextViewLostFocus; - var classificationFormatMapService = GetMefService(); - var editorFormatMapService = GetMefService(); + var classificationFormatMapService = GetRequiredMefService(); + var editorFormatMapService = GetRequiredMefService(); activeClassificationFormatMap = classificationFormatMapService?.GetClassificationFormatMap(activeWpfTextView); if (activeClassificationFormatMap is not null) { diff --git a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs index a0ea448ea7..24f1d74330 100644 --- a/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs +++ b/tests/VisualStudio.Roslyn.SDK/Roslyn.SDK.IntegrationTests/InProcess/InProcComponent.cs @@ -43,13 +43,11 @@ protected async Task GetRequiredGlobalServiceAsync GetComponentModelServiceAsync() From 9a8c9afb7b51c29e0554dd06a3fc00d4375585b4 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Wed, 27 Jan 2021 16:13:21 -0800 Subject: [PATCH 13/14] update editorconfig to include settings for spaces --- .editorconfig | 24 ++++++++++++++ .../SyntaxVisualizerControl.xaml.cs | 32 +++++++++---------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.editorconfig b/.editorconfig index 87f3c996a0..4b4a345200 100644 --- a/.editorconfig +++ b/.editorconfig @@ -82,6 +82,30 @@ csharp_new_line_before_finally = true csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_anonymous_types = true +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = do_not_ignore +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + [*.cs] # Disable enforcement of items covered by StyleCop Analyzers dotnet_style_qualification_for_field = false:none diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs index 679bc6ea3c..451fde3b87 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs @@ -504,7 +504,7 @@ private void ExpandPathTo(TreeViewItem? item) var currentTag = (SyntaxTag)current.Tag; if (currentTag.FullSpan.Contains(span)) { - if (( currentTag.Span == span || currentTag.FullSpan == span ) && ( kind == null || currentTag.Kind == kind )) + if ((currentTag.Span == span || currentTag.FullSpan == span) && (kind == null || currentTag.Kind == kind)) { CollapseEverythingBut(current); match = current; @@ -515,7 +515,7 @@ private void ExpandPathTo(TreeViewItem? item) foreach (TreeViewItem item in current.Items) { - if (category != SyntaxCategory.Operation && ( (SyntaxTag)item.Tag ).Category == SyntaxCategory.Operation) + if (category != SyntaxCategory.Operation && ((SyntaxTag)item.Tag).Category == SyntaxCategory.Operation) { // Do not prefer navigating to IOperation nodes when clicking in source code continue; @@ -528,8 +528,8 @@ private void ExpandPathTo(TreeViewItem? item) } } - if (match == null && ( kind == null || currentTag.Kind == kind ) && - ( category == SyntaxCategory.None || category == currentTag.Category )) + if (match == null && (kind == null || currentTag.Kind == kind) && + (category == SyntaxCategory.None || category == currentTag.Category)) { match = current; } @@ -889,7 +889,7 @@ private void AddTrivia(TreeViewItem parentItem, SyntaxTrivia trivia, bool isLead ParentItem = parentItem }; - var item = CreateTreeViewItem(tag, ( isLeadingTrivia ? "Lead: " : "Trail: " ) + tag.Kind + " " + trivia.Span.ToString(), trivia.ContainsDiagnostics); + var item = CreateTreeViewItem(tag, (isLeadingTrivia ? "Lead: " : "Trail: ") + tag.Kind + " " + trivia.Span.ToString(), trivia.ContainsDiagnostics); item.SetResourceReference(ForegroundProperty, SyntaxTriviaTextBrushKey); if (SyntaxTree != null && trivia.ContainsDiagnostics) @@ -1024,7 +1024,7 @@ private void DisplaySymbolInPropertyGrid(ISymbol? symbol) private static TreeViewItem? FindTreeViewItem(DependencyObject source) { - while (source != null && !( source is TreeViewItem )) + while (source != null && !(source is TreeViewItem)) { if (source is ContentElement contentElement) { @@ -1079,15 +1079,15 @@ private void TreeView_ContextMenuOpening(object sender, ContextMenuEventArgs e) } var directedSyntaxGraphEnabled = - ( SyntaxNodeDirectedGraphRequested != null ) && - ( SyntaxTokenDirectedGraphRequested != null ) && - ( SyntaxTriviaDirectedGraphRequested != null ); + (SyntaxNodeDirectedGraphRequested != null) && + (SyntaxTokenDirectedGraphRequested != null) && + (SyntaxTriviaDirectedGraphRequested != null); var symbolDetailsEnabled = - ( SemanticModel != null ) && - ( ( (SyntaxTag)_currentSelection.Tag ).Category == SyntaxCategory.SyntaxNode ); + (SemanticModel != null) && + (((SyntaxTag)_currentSelection.Tag).Category == SyntaxCategory.SyntaxNode); - if (( !directedSyntaxGraphEnabled ) && ( !symbolDetailsEnabled )) + if ((!directedSyntaxGraphEnabled) && (!symbolDetailsEnabled)) { e.Handled = true; } @@ -1145,7 +1145,7 @@ private void SymbolDetailsMenuItem_Click(object sender, RoutedEventArgs e) } var currentTag = (SyntaxTag)_currentSelection.Tag; - if (( SemanticModel != null ) && ( currentTag.Category == SyntaxCategory.SyntaxNode ) && currentTag.SyntaxNode is not null) + if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode) && currentTag.SyntaxNode is not null) { var symbol = SemanticModel.GetSymbolInfo(currentTag.SyntaxNode).Symbol; if (symbol == null) @@ -1177,7 +1177,7 @@ private void TypeSymbolDetailsMenuItem_Click(object sender, RoutedEventArgs e) return; } - if (( SemanticModel != null ) && ( currentTag.Category == SyntaxCategory.SyntaxNode )) + if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode)) { var symbol = SemanticModel.GetTypeInfo(currentTag.SyntaxNode).Type; DisplaySymbolInPropertyGrid(symbol); @@ -1199,7 +1199,7 @@ private void ConvertedTypeSymbolDetailsMenuItem_Click(object sender, RoutedEvent return; } - if (( SemanticModel != null ) && ( currentTag.Category == SyntaxCategory.SyntaxNode )) + if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode)) { var symbol = SemanticModel.GetTypeInfo(currentTag.SyntaxNode).ConvertedType; DisplaySymbolInPropertyGrid(symbol); @@ -1221,7 +1221,7 @@ private void AliasSymbolDetailsMenuItem_Click(object sender, RoutedEventArgs e) return; } - if (( SemanticModel != null ) && ( currentTag.Category == SyntaxCategory.SyntaxNode )) + if ((SemanticModel != null) && (currentTag.Category == SyntaxCategory.SyntaxNode)) { var symbol = SemanticModel.GetAliasInfo(currentTag.SyntaxNode); DisplaySymbolInPropertyGrid(symbol); From c977ccbb1634cc90dbda29e8a82c394ad100386d Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Wed, 27 Jan 2021 16:17:45 -0800 Subject: [PATCH 14/14] use pattern matching --- .../SyntaxVisualizerControl.xaml.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs index 451fde3b87..fd5f6ea10c 100644 --- a/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs +++ b/src/VisualStudio.Roslyn.SDK/SyntaxVisualizer/Roslyn.SyntaxVisualizer.Control/SyntaxVisualizerControl.xaml.cs @@ -412,14 +412,14 @@ public bool NavigateToBestMatch(TextSpan span, string? kind = null, _isNavigatingFromSourceToTree = false; } - if (highlightMatch && match is not null) - { - match.Background = Brushes.Yellow; - match.BorderBrush = Brushes.Black; - match.BorderThickness = s_defaultBorderThickness; - } + if (!highlightMatch || match is null) + return false; - return match is not null; + match.Background = Brushes.Yellow; + match.BorderBrush = Brushes.Black; + match.BorderThickness = s_defaultBorderThickness; + + return true; } #endregion