The Roslyn Syntax Debugger Visualizer is an assembly that can be used in a Visual
Studio debug session to visualize Roslyn SyntaxTrees, SyntaxNodes, SyntaxTokens
and SyntaxTrivia. The project itself is just a library, and cannot be run. If you
compile it, a couple of DLLs are generated that can be used in Visual Studio to
enhance your ability to debug applications that use the Roslyn APIs.
To use the debugger visualizer, the DLLs generated by compiling the SyntaxDebuggerVisualizer
project must be copied to the ...\Documents\Visual Studio 2010\Visualizers
directory. You may need to create the Visualizers directory.
Here is a step by step outline of what to do:
- Build the SyntaxDebuggerVisualizer project.
- Copy the DLLs produced by the compilation from the bin directory of the project
into the ...\Documents\Visual Studio 2010\Visualizers directory.
- If necessary, close Visual Studio and reopen to make sure the visualizer is recognized.
- You can test the visualizer in an existing sample project, such as RFxCopConsoleCS.
- You can use the visualizer to visualize the following types of objects -
- Roslyn.Compilers.Common.CommonSyntaxTree
- Roslyn.Compilers.Common.CommonSyntaxNodeOrToken
- Roslyn.Compilers.Common.CommonSyntaxNode
- Roslyn.Compilers.Common.CommonSyntaxToken
- Roslyn.Compilers.Common.CommonSyntaxTrivia
- Roslyn.Compilers.CSharp.SyntaxTree
- Roslyn.Compilers.CSharp.SyntaxNodeOrToken
- Roslyn.Compilers.CSharp.SyntaxNode
- Roslyn.Compilers.CSharp.SyntaxToken
- Roslyn.Compilers.CSharp.SyntaxTrivia
- Roslyn.Compilers.VisualBasic.SyntaxTree
- Roslyn.Compilers.VisualBasic.SyntaxNodeOrToken
- Roslyn.Compilers.VisualBasic.SyntaxNode
- Roslyn.Compilers.VisualBasic.SyntaxToken
- Roslyn.Compilers.VisualBasic.SyntaxTrivia
- To display the visualizer click on the magnifying glass that will appear next to
instances of the above objects in Visual Studio’s debugger windows.
- The visualizer window that pops up will display SyntaxNodes, SyntaxTokens and SyntaxTrivia
in a TreeView on the left and the corresponding source code in a TextBox on the
right. The SyntaxNode / SyntaxToken / SyntaxTrivia object that you are trying to
visualize will be highlighted in the TreeView and the corresponding source text
for this object will be highlighted in the TextBox. Properties for the item currently
selected in the TreeView will be displayed in a PropertyGrid below the TreeView.
- You can click on / select any SyntaxNodes, SyntaxTokens or SyntaxTrivia in the TreeView.
When you do this, the source text corresponding to the clicked item will also be
selected in the TextBox.
- You can also position the cursor / select text anywhere in the TextBox. When you
do this, the SyntaxNode / SyntaxToken / SyntaxTrivia that best matches the selected
source text will be highlighted in the TreeView.