Skip to content

Commit

Permalink
Merge pull request #495 from sharwell/operation-tree
Browse files Browse the repository at this point in the history
IOperation tree
  • Loading branch information
sharwell authored Apr 3, 2020
2 parents d7820c1 + 1eacf08 commit b934e46
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 29 deletions.
30 changes: 15 additions & 15 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
<UsingToolSymbolUploader>true</UsingToolSymbolUploader>
<!-- Dependencies -->
<UpdateTemplateVersionVersion>1.0.4-beta1</UpdateTemplateVersionVersion>
<!-- Roslyn for VS 2015 -->
<!-- NOTE: Do not upgrade these to be newer than what shipped in VS 2015 since the Syntax Visualizer extension still
<!-- Roslyn for VS 2019 -->
<!-- NOTE: Do not upgrade these to be newer than what shipped in VS 2019 since the Syntax Visualizer extension still
supports it. -->
<MicrosoftCodeAnalysisAnalyzersVersionVS2015>1.1.0</MicrosoftCodeAnalysisAnalyzersVersionVS2015>
<MicrosoftCodeAnalysisCommonVersionVS2015>1.0.1</MicrosoftCodeAnalysisCommonVersionVS2015>
<MicrosoftCodeAnalysisCSharpVersionVS2015>1.0.1</MicrosoftCodeAnalysisCSharpVersionVS2015>
<MicrosoftCodeAnalysisEditorFeaturesTextVersionVS2015>1.0.1</MicrosoftCodeAnalysisEditorFeaturesTextVersionVS2015>
<MicrosoftCodeAnalysisVisualBasicVersionVS2015>1.0.1</MicrosoftCodeAnalysisVisualBasicVersionVS2015>
<MicrosoftCodeAnalysisWorkspacesCommonVersionVS2015>1.0.1</MicrosoftCodeAnalysisWorkspacesCommonVersionVS2015>
<MicrosoftCodeAnalysisAnalyzersVersionVS2019>3.0.0</MicrosoftCodeAnalysisAnalyzersVersionVS2019>
<MicrosoftCodeAnalysisCommonVersionVS2019>3.3.1</MicrosoftCodeAnalysisCommonVersionVS2019>
<MicrosoftCodeAnalysisCSharpVersionVS2019>3.3.1</MicrosoftCodeAnalysisCSharpVersionVS2019>
<MicrosoftCodeAnalysisEditorFeaturesTextVersionVS2019>3.3.1</MicrosoftCodeAnalysisEditorFeaturesTextVersionVS2019>
<MicrosoftCodeAnalysisVisualBasicVersionVS2019>3.3.1</MicrosoftCodeAnalysisVisualBasicVersionVS2019>
<MicrosoftCodeAnalysisWorkspacesCommonVersionVS2019>3.3.1</MicrosoftCodeAnalysisWorkspacesCommonVersionVS2019>
<!-- VS SDK -->
<!-- NOTE: Do not upgrade these to be newer than what shipped in VS 2015
<!-- NOTE: Do not upgrade these to be newer than what shipped in VS 2019
we need our extensions to work on both. -->
<VSLangProjVersion>7.0.3300</VSLangProjVersion>
<VSSDKTemplateWizardInterfaceVersion>12.0.4</VSSDKTemplateWizardInterfaceVersion>
<EnvDTEVersion>8.0.1</EnvDTEVersion>
<EnvDTE80Version>8.0.0</EnvDTE80Version>
<MicrosoftVisualStudioComponentModelHostVersion>14.0.25424</MicrosoftVisualStudioComponentModelHostVersion>
<MicrosoftVisualStudioCoreUtilityVersion>14.3.25407</MicrosoftVisualStudioCoreUtilityVersion>
<MicrosoftVisualStudioCoreUtilityVersion>16.2.45</MicrosoftVisualStudioCoreUtilityVersion>
<MicrosoftVisualStudioEditorVersion>14.3.25407</MicrosoftVisualStudioEditorVersion>
<MicrosoftVisualStudioLanguageStandardClassificationVersion>14.3.25407</MicrosoftVisualStudioLanguageStandardClassificationVersion>
<MicrosoftVisualStudioOLEInteropVersion>7.10.6070</MicrosoftVisualStudioOLEInteropVersion>
Expand All @@ -39,13 +39,13 @@
<MicrosoftVisualStudioShellInterop90Version>9.0.30729</MicrosoftVisualStudioShellInterop90Version>
<MicrosoftVisualStudioShellInterop100Version>10.0.30319</MicrosoftVisualStudioShellInterop100Version>
<MicrosoftVisualStudioShellInterop110Version>11.0.61030</MicrosoftVisualStudioShellInterop110Version>
<MicrosoftVisualStudioTextDataVersion>14.3.25407</MicrosoftVisualStudioTextDataVersion>
<MicrosoftVisualStudioTextLogicVersion>14.3.25407</MicrosoftVisualStudioTextLogicVersion>
<MicrosoftVisualStudioTextDataVersion>16.2.45</MicrosoftVisualStudioTextDataVersion>
<MicrosoftVisualStudioTextLogicVersion>16.2.45</MicrosoftVisualStudioTextLogicVersion>
<MicrosoftVisualStudioTextManagerInteropVersion>7.10.6070</MicrosoftVisualStudioTextManagerInteropVersion>
<MicrosoftVisualStudioTextUIVersion>14.3.25407</MicrosoftVisualStudioTextUIVersion>
<MicrosoftVisualStudioTextUIWpfVersion>14.3.25407</MicrosoftVisualStudioTextUIWpfVersion>
<MicrosoftVisualStudioTextUIVersion>16.2.45</MicrosoftVisualStudioTextUIVersion>
<MicrosoftVisualStudioTextUIWpfVersion>16.2.45</MicrosoftVisualStudioTextUIWpfVersion>
<MicrosoftVisualStudioUtilitiesVersion>14.3.25407</MicrosoftVisualStudioUtilitiesVersion>
<MicrosoftVisualStudioThreadingVersion>14.1.131 </MicrosoftVisualStudioThreadingVersion>
<MicrosoftVisualStudioThreadingVersion>16.3.13</MicrosoftVisualStudioThreadingVersion>
<!-- Libs -->
<SystemCollectionsImmutableVersion>1.3.1</SystemCollectionsImmutableVersion>
<SystemCompositionVersion>1.1.0</SystemCompositionVersion>
Expand Down
25 changes: 24 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />


<PropertyGroup>
<Features>strict</Features>
</PropertyGroup>

<!--
Language specific settings
-->
<Choose>
<!-- VB specific settings -->
<When Condition="'$(Language)' == 'VB'">
<PropertyGroup>
<LangVersion>15.5</LangVersion>
</PropertyGroup>
</When>

<!-- C# specific settings -->
<When Condition="'$(Language)' == 'C#'">
<PropertyGroup>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
</When>
</Choose>

<PropertyGroup>
<!--
When markup compilation is involved, WPF generates .g.cs files via the GenerateTemporaryTargetAssembly task.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

<!-- Package References -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="$(MicrosoftCodeAnalysisVisualBasicVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="$(MicrosoftCodeAnalysisVisualBasicVersionVS2019)" />
<PackageReference Include="Microsoft.VisualStudio.Language.StandardClassification" Version="$(MicrosoftVisualStudioLanguageStandardClassificationVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Shell.14.0" Version="$(MicrosoftVisualStudioShell140Version)" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.11.0" Version="$(MicrosoftVisualStudioShellInterop110Version)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<SolidColorBrush x:Key="SyntaxNodeText.Brush" Color="{DynamicResource {x:Static vsui:EnvironmentColors.ToolWindowTextColorKey}}"/>
<SolidColorBrush x:Key="SyntaxTokenText.Brush" Color="{DynamicResource {x:Static vsui:EnvironmentColors.ToolWindowTextColorKey}}"/>
<SolidColorBrush x:Key="SyntaxTriviaText.Brush" Color="{DynamicResource {x:Static vsui:EnvironmentColors.ToolWindowTextColorKey}}"/>
<SolidColorBrush x:Key="OperationText.Brush" Color="{DynamicResource {x:Static vsui:EnvironmentColors.ToolWindowTextColorKey}}"/>
<SolidColorBrush x:Key="ErrorSquiggle.Brush" Color="{DynamicResource {x:Static vsui:EnvironmentColors.ToolWindowTextColorKey}}"/>

<Style x:Key="SquiggleStyle" TargetType="{x:Type Shape}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// 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.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
Expand All @@ -25,7 +28,8 @@ public enum SyntaxCategory
None,
SyntaxNode,
SyntaxToken,
SyntaxTrivia
SyntaxTrivia,
Operation,
}

// A control for visually displaying the contents of a SyntaxTree.
Expand All @@ -34,6 +38,7 @@ public partial class SyntaxVisualizerControl : UserControl
private static readonly string SyntaxNodeTextBrushKey = "SyntaxNodeText.Brush";
private static readonly string SyntaxTokenTextBrushKey = "SyntaxTokenText.Brush";
private static readonly string SyntaxTriviaTextBrushKey = "SyntaxTriviaText.Brush";
private static readonly string OperationTextBrushKey = "OperationText.Brush";
private static readonly string ErrorSquiggleBrushKey = "ErrorSquiggle.Brush";
private static readonly string SquiggleStyleKey = "SquiggleStyle";

Expand Down Expand Up @@ -185,6 +190,9 @@ public void SetTreeViewColors(
var syntaxTriviaBrush = (SolidColorBrush)FindResource(SyntaxTriviaTextBrushKey);
syntaxTriviaBrush.Color = GetForegroundColor(editorFormatMap.GetProperties(classificationFormatMap.GetEditorFormatMapKey(classificationTypeRegistryService.GetClassificationType(PredefinedClassificationTypeNames.String))));

var operationBrush = (SolidColorBrush)FindResource(OperationTextBrushKey);
operationBrush.Color = GetForegroundColor(editorFormatMap.GetProperties(classificationFormatMap.GetEditorFormatMapKey(classificationTypeRegistryService.GetClassificationType(PredefinedClassificationTypeNames.Number))));

var errorBrush = (SolidColorBrush)FindResource(ErrorSquiggleBrushKey);
errorBrush.Color = GetForegroundColor(editorFormatMap.GetProperties(PredefinedErrorTypeNames.SyntaxError));
}
Expand Down Expand Up @@ -402,6 +410,12 @@ private TreeViewItem NavigateToBestMatch(TreeViewItem current, TextSpan span, st

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)
{
Expand Down Expand Up @@ -437,6 +451,123 @@ private void AddNodeOrToken(TreeViewItem parentItem, SyntaxNodeOrToken nodeOrTok
}
}

private void AddOperation(TreeViewItem parentItem, IOperation operation)
{
var node = operation.Syntax;
var kind = operation.Kind.ToString();
var tag = new SyntaxTag()
{
SyntaxNode = node,
Category = SyntaxCategory.Operation,
Span = node.Span,
FullSpan = node.FullSpan,
Kind = kind,
ParentItem = parentItem,
};

var item = CreateTreeViewItem(tag, tag.Kind + " " + node.Span.ToString(), node.ContainsDiagnostics);
item.SetResourceReference(ForegroundProperty, OperationTextBrushKey);

if (SyntaxTree is object && node.ContainsDiagnostics)
{
item.ToolTip = string.Empty;
foreach (var diagnostic in SyntaxTree.GetDiagnostics(node))
{
item.ToolTip += diagnostic.ToString() + "\n";
}

item.ToolTip = item.ToolTip.ToString().Trim();
}

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

typeTextLabel.Visibility = Visibility.Visible;
kindTextLabel.Visibility = Visibility.Visible;
typeValueLabel.Content = string.Join(", ", GetOperationInterfaces(operation));
kindValueLabel.Content = kind;
_propertyGrid.SelectedObject = operation;

item.IsExpanded = true;

if (!_isNavigatingFromSourceToTree && SyntaxNodeNavigationToSourceRequested != null)
{
SyntaxNodeNavigationToSourceRequested(node);
}

_isNavigatingFromTreeToSource = false;
e.Handled = true;
});

item.Expanded += new RoutedEventHandler((sender, e) =>
{
if (item.Items.Count == 1 && item.Items[0] == null)
{
// Remove placeholder child and populate real children.
item.Items.RemoveAt(0);

foreach (var child in operation.Children)
{
AddOperation(item, child);
}
}
});

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

if (operation.Children.Any())
{
if (IsLazy)
{
// Add placeholder child to indicate that real children need to be populated on expansion.
item.Items.Add(null);
}
else
{
// Recursively populate all descendants.
foreach (var child in operation.Children)
{
AddOperation(item, child);
}
}
}

return;

// local functions
static IEnumerable<string> GetOperationInterfaces(IOperation operation)
{
var interfaces = new List<Type>();
foreach (var interfaceType in operation.GetType().GetInterfaces())
{
if (interfaceType == typeof(IOperation)
|| !interfaceType.IsPublic
|| !interfaceType.GetInterfaces().Contains(typeof(IOperation)))
{
continue;
}

interfaces.Add(interfaceType);
}

if (interfaces.Count == 0)
{
interfaces.Add(typeof(IOperation));
}

return interfaces.OrderByDescending(x => x.GetInterfaces().Length).Select(x => x.Name);
}
}

private void AddNode(TreeViewItem parentItem, SyntaxNode node)
{
var kind = node.GetKind();
Expand Down Expand Up @@ -491,6 +622,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 })
{
AddOperation(item, operation);
}

foreach (var child in node.ChildNodesAndTokens())
{
AddNodeOrToken(item, child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

<!-- Package References -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="$(MicrosoftCodeAnalysisVisualBasicVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="$(MicrosoftCodeAnalysisVisualBasicVersionVS2019)" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources.Designer.vb">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<ItemGroup>
<PackageReference Include="EnvDTE" Version="$(EnvDTEVersion)" />
<PackageReference Include="EnvDTE80" Version="$(EnvDTE80Version)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="$(MicrosoftCodeAnalysisEditorFeaturesTextVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisWorkspacesCommonVersionVS2015)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="$(MicrosoftCodeAnalysisEditorFeaturesTextVersionVS2019)" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisWorkspacesCommonVersionVS2019)" />
<PackageReference Include="Microsoft.VisualStudio.ComponentModelHost" Version="$(MicrosoftVisualStudioComponentModelHostVersion)" />
<PackageReference Include="Microsoft.VisualStudio.CoreUtility" Version="$(MicrosoftVisualStudioCoreUtilityVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Editor" Version="$(MicrosoftVisualStudioEditorVersion)" />
Expand Down

0 comments on commit b934e46

Please sign in to comment.