├── DotNetSyntaxTreeVisualizer ├── ClientApp │ ├── public │ │ ├── favicon.ico │ │ ├── manifest.json │ │ └── index.html │ ├── src │ │ ├── custom.css │ │ ├── components │ │ │ ├── NavMenu.css │ │ │ ├── Layout.js │ │ │ ├── NavMenu.js │ │ │ └── Home.js │ │ ├── App.test.js │ │ ├── App.js │ │ ├── index.js │ │ └── registerServiceWorker.js │ ├── .gitignore │ ├── package.json │ └── README.md ├── Pages │ ├── _ViewImports.cshtml │ ├── Error.cshtml │ └── Error.cshtml.cs ├── .config │ └── dotnet-tools.json ├── appsettings.Development.json ├── appsettings.json ├── Properties │ └── launchSettings.json ├── Program.cs ├── Controllers │ └── SyntaxTreeController.cs ├── Startup.cs ├── DotNetSyntaxTreeVisualizer.csproj ├── SyntaxTreeNode.cs └── .gitignore ├── azure-pipelines.yml ├── README.md ├── DotNetSyntaxTreeVisualizer.sln ├── .gitattributes ├── .gitignore └── .editorconfig /DotNetSyntaxTreeVisualizer/ClientApp/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Youssef1313/DotNetSyntaxTreeVisualizer/HEAD/DotNetSyntaxTreeVisualizer/ClientApp/public/favicon.ico -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/Pages/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using DotNetSyntaxTreeVisualizer 2 | @namespace DotNetSyntaxTreeVisualizer.Pages 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-ef": { 6 | "version": "3.1.5", 7 | "commands": [ 8 | "dotnet-ef" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/src/custom.css: -------------------------------------------------------------------------------- 1 | /* Provide sufficient contrast against white background */ 2 | a { 3 | color: #0366d6; 4 | } 5 | 6 | code { 7 | color: #E01A76; 8 | } 9 | 10 | .btn-primary { 11 | color: #fff; 12 | background-color: #1b6ec2; 13 | border-color: #1861ac; 14 | } 15 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/src/components/NavMenu.css: -------------------------------------------------------------------------------- 1 | a.navbar-brand { 2 | white-space: normal; 3 | text-align: center; 4 | word-break: break-all; 5 | } 6 | 7 | html { 8 | font-size: 14px; 9 | } 10 | @media (min-width: 768px) { 11 | html { 12 | font-size: 16px; 13 | } 14 | } 15 | 16 | .box-shadow { 17 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); 18 | } 19 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "DotNetSyntaxTreeVisualizer", 3 | "name": "DotNetSyntaxTreeVisualizer", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import { MemoryRouter } from 'react-router-dom'; 4 | import App from './App'; 5 | 6 | it('renders without crashing', async () => { 7 | const div = document.createElement('div'); 8 | ReactDOM.render( 9 | 10 | 11 | , div); 12 | await new Promise(resolve => setTimeout(resolve, 1000)); 13 | }); 14 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/src/components/Layout.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { Container } from 'reactstrap'; 3 | import { NavMenu } from './NavMenu'; 4 | 5 | export class Layout extends Component { 6 | static displayName = Layout.name; 7 | 8 | render () { 9 | return ( 10 |
11 | 12 | 13 | {this.props.children} 14 | 15 |
16 | ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { Route } from 'react-router'; 3 | import { Layout } from './components/Layout'; 4 | import { Home } from './components/Home'; 5 | 6 | import './custom.css' 7 | 8 | export default class App extends Component { 9 | static displayName = App.name; 10 | 11 | render () { 12 | return ( 13 | 14 | 15 | 16 | ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/src/index.js: -------------------------------------------------------------------------------- 1 | import 'bootstrap/dist/css/bootstrap.css'; 2 | import React from 'react'; 3 | import ReactDOM from 'react-dom'; 4 | import { BrowserRouter } from 'react-router-dom'; 5 | import App from './App'; 6 | import registerServiceWorker from './registerServiceWorker'; 7 | 8 | const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href'); 9 | const rootElement = document.getElementById('root'); 10 | 11 | ReactDOM.render( 12 | 13 | 14 | , 15 | rootElement); 16 | 17 | registerServiceWorker(); 18 | 19 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:56607", 7 | "sslPort": 44310 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "DotNetSyntaxTreeVisualizer": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace DotNetSyntaxTreeVisualizer 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model ErrorModel 3 | @{ 4 | ViewData["Title"] = "Error"; 5 | } 6 | 7 |

Error.

8 |

An error occurred while processing your request.

9 | 10 | @if (Model.ShowRequestId) 11 | { 12 |

13 | Request ID: @Model.RequestId 14 |

15 | } 16 | 17 |

Development Mode

18 |

19 | Swapping to the Development environment displays detailed information about the error that occurred. 20 |

21 |

22 | The Development environment shouldn't be enabled for deployed applications. 23 | It can result in displaying sensitive information from exceptions to end users. 24 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 25 | and restarting the app. 26 |

27 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.AspNetCore.Mvc.RazorPages; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace DotNetSyntaxTreeVisualizer.Pages 11 | { 12 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 13 | public class ErrorModel : PageModel 14 | { 15 | private readonly ILogger _logger; 16 | 17 | public ErrorModel(ILogger logger) 18 | { 19 | _logger = logger; 20 | } 21 | 22 | public string RequestId { get; set; } 23 | 24 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 25 | 26 | public void OnGet() 27 | { 28 | RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # ASP.NET 2 | # Build and test ASP.NET projects. 3 | # Add steps that publish symbols, save build artifacts, deploy, and more: 4 | # https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4 5 | 6 | trigger: 7 | - main 8 | 9 | pool: 10 | vmImage: 'windows-latest' 11 | 12 | variables: 13 | solution: '**/*.sln' 14 | buildPlatform: 'Any CPU' 15 | buildConfiguration: 'Release' 16 | 17 | steps: 18 | - task: NuGetToolInstaller@1 19 | 20 | - task: NuGetCommand@2 21 | inputs: 22 | restoreSolution: '$(solution)' 23 | 24 | - task: VSBuild@1 25 | inputs: 26 | solution: '$(solution)' 27 | msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"' 28 | platform: '$(buildPlatform)' 29 | configuration: '$(buildConfiguration)' 30 | 31 | - task: VSTest@2 32 | inputs: 33 | platform: '$(buildPlatform)' 34 | configuration: '$(buildConfiguration)' 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DotNetSyntaxTreeVisualizer 2 | 3 | .NET Syntax Tree Visualizer, A C# ASP.NET Core app with ReactJS in front-end that shows Roslyn's syntax tree for a given source code. 4 | 5 | The app is deployed [here](https://DotNetSyntaxTreeVisualizer.azurewebsites.net/). If you encountered any problems, do a hard refresh using Ctrl+F5 from your browser. 6 | 7 | ## Visual Studio already has a graph visualizer 8 | 9 | That's true. But not all developers work on Visual Studio. Some developers might be using Rider, VS Code, or whatever. Or you might just be lazy to open Visual Studio! 10 | 11 | ## Why to inspect a syntax tree 12 | 13 | - For fun, if you just want to see what's the syntax tree Roslyn is generating. 14 | - For writing Roslyn's analyzers and codefixes requies knowledge of how the syntax tree for the case you're inspecting looks like. 15 | 16 | ## Screenshot 17 | 18 | ![image](https://user-images.githubusercontent.com/31348972/85202525-31363300-b307-11ea-8b96-2d44fc742bf4.png) 19 | 20 | ## Features 21 | 22 | ### Current features 23 | 24 | - Collapsing and expanding a node. 25 | - Zooming 26 | 27 | ### TODO 28 | 29 | - Support Visual Basic [#6](https://github.com/Youssef1313/DotNetSyntaxTreeVisualizer/issues/6). 30 | - Allow sharing snippets [#9](https://github.com/Youssef1313/DotNetSyntaxTreeVisualizer/issues/9). 31 | - Add Syntax Highlighting [#4](https://github.com/Youssef1313/DotNetSyntaxTreeVisualizer/issues/4). 32 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/src/components/NavMenu.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { Collapse, Container, Navbar, NavbarBrand, NavbarToggler, NavItem, NavLink } from 'reactstrap'; 3 | import { Link } from 'react-router-dom'; 4 | import './NavMenu.css'; 5 | 6 | export class NavMenu extends Component { 7 | static displayName = NavMenu.name; 8 | 9 | constructor (props) { 10 | super(props); 11 | 12 | this.toggleNavbar = this.toggleNavbar.bind(this); 13 | this.state = { 14 | collapsed: true 15 | }; 16 | } 17 | 18 | toggleNavbar () { 19 | this.setState({ 20 | collapsed: !this.state.collapsed 21 | }); 22 | } 23 | 24 | render () { 25 | return ( 26 |
27 | 28 | 29 | DotNetSyntaxTreeVisualizer 30 | 31 | 32 |
    33 | 34 | Home 35 | 36 |
37 |
38 |
39 |
40 |
41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30011.22 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetSyntaxTreeVisualizer", "DotNetSyntaxTreeVisualizer\DotNetSyntaxTreeVisualizer.csproj", "{3EE110F1-13B2-46A9-88C8-25C0FCD6C3A2}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2B8EECB2-71A3-4BFA-BE01-6592B88CEBF1}" 9 | ProjectSection(SolutionItems) = preProject 10 | .editorconfig = .editorconfig 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {3EE110F1-13B2-46A9-88C8-25C0FCD6C3A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {3EE110F1-13B2-46A9-88C8-25C0FCD6C3A2}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {3EE110F1-13B2-46A9-88C8-25C0FCD6C3A2}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {3EE110F1-13B2-46A9-88C8-25C0FCD6C3A2}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {B4883D2D-7978-4205-BA7C-032F0FA8ADCF} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dotnetsyntaxtreevisualizer", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "bootstrap": "^4.1.3", 7 | "jquery": "^3.4.1", 8 | "merge": "^2.1.1", 9 | "oidc-client": "^1.9.0", 10 | "react": "^16.0.0", 11 | "react-d3-tree": "^1.16.1", 12 | "react-dom": "^16.0.0", 13 | "react-router-bootstrap": "^0.25.0", 14 | "react-router-dom": "^5.1.2", 15 | "react-scripts": "^3.4.0", 16 | "reactstrap": "^8.4.1", 17 | "rimraf": "^2.6.2" 18 | }, 19 | "devDependencies": { 20 | "ajv": "^6.9.1", 21 | "cross-env": "^5.2.0", 22 | "typescript": "^3.7.5", 23 | "eslint": "^6.8.0", 24 | "eslint-config-react-app": "^5.2.0", 25 | "eslint-plugin-flowtype": "^4.6.0", 26 | "eslint-plugin-import": "^2.20.1", 27 | "eslint-plugin-jsx-a11y": "^6.2.3", 28 | "eslint-plugin-react": "^7.18.3" 29 | }, 30 | "eslintConfig": { 31 | "extends": "react-app" 32 | }, 33 | "scripts": { 34 | "start": "rimraf ./build && react-scripts start", 35 | "build": "react-scripts build", 36 | "test": "cross-env CI=true react-scripts test --env=jsdom", 37 | "eject": "react-scripts eject", 38 | "lint": "eslint ./src/" 39 | }, 40 | "browserslist": { 41 | "production": [ 42 | ">0.2%", 43 | "not dead", 44 | "not op_mini all" 45 | ], 46 | "development": [ 47 | "last 1 chrome version", 48 | "last 1 firefox version", 49 | "last 1 safari version" 50 | ] 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 23 | DotNetSyntaxTreeVisualizer 24 | 25 | 26 | 29 |
30 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /DotNetSyntaxTreeVisualizer/ClientApp/src/components/Home.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Tree from 'react-d3-tree'; 3 | 4 | const containerStyles = { 5 | width: '100%', 6 | height: '100vh', 7 | } 8 | 9 | const helloWorldCode = 'using System;\r\n\r\npublic class Program\r\n{\r\n public static void Main(string[] args)\r\n {\r\n Console.WriteLine("Hello, world");\r\n }\r\n}' 10 | 11 | export class Home extends Component { 12 | static displayName = Home.name; 13 | 14 | state = { 15 | treeJson: {}, 16 | sourceCodeText: helloWorldCode 17 | }; 18 | 19 | componentDidMount() { 20 | const dimensions = this.treeContainer.getBoundingClientRect(); 21 | this.setState({ 22 | translate: { 23 | x: dimensions.width / 2, 24 | y: dimensions.height / 2 25 | } 26 | }); 27 | this.handleChanged({ 28 | target: { 29 | value: helloWorldCode 30 | } 31 | }); 32 | } 33 | 34 | handleChanged = (event) => { 35 | const requestOptions = { 36 | method: 'POST', 37 | headers: { 'Content-Type': 'text/plain;charset=UTF-8' }, 38 | body: event.target.value 39 | }; 40 | fetch('SyntaxTree/CSharp', requestOptions) 41 | .then(response => response.json()) 42 | .then(data => this.setState({ treeJson: data })); 43 | } 44 | 45 | render() { 46 | return ( 47 | 48 |