Uh oh!
There was an error while loading. Please reload this page.
Fix right side panel C# code viewer for Roslyn compilation - #95
Conversation
Co-authored-by: snakex64 <39806655+snakex64@users.noreply.github.com>
Co-authored-by: snakex64 <39806655+snakex64@users.noreply.github.com>
snakex64
commented
Jan 5, 2026
@copilot No need to store the generated C#, we can build on the fly. Also, explore the possibility of getting only the result of the method build (the SyntaxNode) and only using that to create the string, this would prevent having to do string manipulation to find the method in the whole class |
- Remove _lastGeneratedSourceCode field (no longer storing generated code) - Replace GetGeneratedCSharpCode() with on-the-fly generation using RoslynGraphBuilder - Get MethodDeclarationSyntax directly from RoslynGraphBuilder.BuildMethod() - Convert syntax node to string using NormalizeWhitespace().ToFullString() - Eliminate complex string parsing logic - now uses Roslyn's syntax tree directly Co-authored-by: snakex64 <39806655+snakex64@users.noreply.github.com>
Done in d72b6bf. The implementation now:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Uh oh!
There was an error while loading. Please reload this page.
The right side panel stopped working after migrating from expression tree generation to Roslyn compilation. The viewer was calling the old
GetBodyAsCsAndMsilCode()method which relied on expression tree APIs.Changes
Project.cs: Added
GetGeneratedCSharpCode()method that builds C# code on-the-fly usingRoslynGraphBuilder. Gets theMethodDeclarationSyntaxdirectly from the graph builder and converts it to string using Roslyn'sNormalizeWhitespace().ToFullString(). No storage of generated code needed.SourceViewer.razor: Replaced expression tree-based code extraction with on-demand Roslyn code generation. IL Code tab now shows placeholder message.
E2E Tests: Added
SourceViewerTests.cscovering panel display, null method handling, and method switching scenarios.Implementation
The C# code generation now uses Roslyn's syntax tree API directly instead of string parsing:
This approach is cleaner and more efficient - it generates code only when requested and uses Roslyn's built-in syntax tree APIs instead of complex string manipulation.
Screenshots
Generated C# Code Display

IL Code Placeholder

Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.