mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
The Debug Steps pane previously only served the ILAst language (one node per IL transform). The C# decompiler's intermediate AST states were instead exposed as a row of extra "C# - after TRANSFORM" dropdown languages, which cluttered the language list and only let you jump to one fixed step at a time. Generalise the pane to an IDebugStepProvider interface: ILAst keeps its IL steps, and the C# language now contributes one step per AST transform, mapping a selected step onto options.StepLimit (already honoured by CreateDecompiler). Each language also supplies its own options object, so the writing-options checkboxes show for ILAst and nothing for C#. The per-transform dropdown languages are removed in favour of this. Assisted-by: Claude:claude-opus-4-8:Claude Codepull/3755/head
8 changed files with 194 additions and 173 deletions
@ -1,86 +0,0 @@
@@ -1,86 +0,0 @@
|
||||
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#if DEBUG
|
||||
|
||||
using System.Linq; |
||||
|
||||
using Avalonia.Headless.NUnit; |
||||
|
||||
using AwesomeAssertions; |
||||
|
||||
using ICSharpCode.Decompiler.CSharp; |
||||
|
||||
using ILSpy.AppEnv; |
||||
using ILSpy.Languages; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.ILSpy.Tests.Languages; |
||||
|
||||
/// <summary>
|
||||
/// Pins the WPF parity feature: in Debug builds the C# language pipeline contributes one
|
||||
/// extra language per AST transform, named <c>"C# - no transforms"</c>, <c>"C# - after
|
||||
/// <em>TransformName</em>"</c>, … so a developer can pick the dropdown entry and see the
|
||||
/// decompiler's intermediate AST at that stage. Each variant sets <c>showAllMembers</c>
|
||||
/// so compiler-generated members aren't hidden — visibility into the synthetic ones is
|
||||
/// the whole point of the feature.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class CSharpDebugTransformLanguagesTests |
||||
{ |
||||
[Test] |
||||
public void GetDebugLanguages_Yields_A_Pipeline_Step_Per_Ast_Transform_Plus_The_No_Transforms_Baseline() |
||||
{ |
||||
var transforms = CSharpDecompiler.GetAstTransforms().ToList(); |
||||
transforms.Should().NotBeEmpty( |
||||
"the decompiler must publish at least one AST transform — otherwise the debug-languages feature would be meaningless"); |
||||
|
||||
var debugLanguages = CSharpLanguage.GetDebugLanguages().ToList(); |
||||
|
||||
// One baseline ("no transforms"), one variant per transform, plus a final "after
|
||||
// <last transform>" entry. So count = transforms.Count + 1.
|
||||
debugLanguages.Should().HaveCount(transforms.Count + 1, |
||||
"one variant for the baseline + one per transform step (the last yields the fully-transformed AST)"); |
||||
|
||||
debugLanguages.Select(l => l.Name).Should().Contain("C# - no transforms", |
||||
"the first dropdown entry is the baseline before any transform runs"); |
||||
|
||||
// Spot-check the second entry is named after the first transform, matching WPF —
|
||||
// each subsequent variant is named after the transform that just ran.
|
||||
debugLanguages[1].Name.Should().Be("C# - after " + transforms[0].GetType().Name); |
||||
} |
||||
|
||||
[AvaloniaTest] |
||||
public void LanguageService_Registers_The_Debug_Transform_Languages_In_The_Dropdown() |
||||
{ |
||||
// MEF-side wiring: LanguageService aggregates [Export(Language)]-resolved instances
|
||||
// plus the manually-yielded debug variants under #if DEBUG. Without the registration
|
||||
// step the variants never reach the toolbar — even though GetDebugLanguages itself
|
||||
// would return a populated list.
|
||||
var languageService = AppComposition.Current.GetExport<LanguageService>(); |
||||
var names = languageService.Languages.Select(l => l.Name).ToList(); |
||||
|
||||
names.Should().Contain("C# - no transforms", |
||||
"LanguageService must include the no-transforms baseline in its Languages list"); |
||||
names.Should().Contain(n => n.StartsWith("C# - after "), |
||||
"LanguageService must include at least one 'after <TransformName>' variant"); |
||||
} |
||||
} |
||||
|
||||
#endif
|
||||
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#if DEBUG
|
||||
|
||||
using System; |
||||
|
||||
using ICSharpCode.Decompiler; |
||||
using ICSharpCode.Decompiler.CSharp; |
||||
using ICSharpCode.Decompiler.IL.Transforms; |
||||
|
||||
using ILSpy.AppEnv; |
||||
using ILSpy.Docking; |
||||
using ILSpy.TextView; |
||||
using ILSpy.ViewModels; |
||||
|
||||
namespace ILSpy.Languages |
||||
{ |
||||
/// <summary>
|
||||
/// Debug Steps support for the C# language: coarse, one step per AST transform, shown in the
|
||||
/// Debug Steps pane like the ILAst language already does for IL transforms. The step list is
|
||||
/// static -- the C# AST pipeline (<see cref="CSharpDecompiler.GetAstTransforms"/>) is the same
|
||||
/// for every member -- so a selected step's index maps straight onto <see
|
||||
/// cref="DecompilationOptions.StepLimit"/>, which CreateDecompiler turns into the number of AST
|
||||
/// transforms to keep before re-rendering.
|
||||
/// </summary>
|
||||
partial class CSharpLanguage : IDebugStepProvider |
||||
{ |
||||
Stepper? stepper; |
||||
|
||||
public Stepper Stepper => stepper ??= BuildStepper(); |
||||
|
||||
public event EventHandler? StepperUpdated; |
||||
|
||||
// The C# AST step view has no options of its own (yet); the pane shows nothing above the
|
||||
// tree for C#, unlike ILAst's writing-options checkboxes.
|
||||
public object? StepOptions => null; |
||||
|
||||
// One node per AST transform, in pipeline order. Stepper.Step assigns BeginStep=i /
|
||||
// EndStep=i+1 automatically, so "show state before step i" re-decompiles with StepLimit=i
|
||||
// (run i transforms) and "after" with StepLimit=i+1 -- exactly the cap CreateDecompiler wants.
|
||||
static Stepper BuildStepper() |
||||
{ |
||||
var s = new Stepper(); |
||||
foreach (var transform in CSharpDecompiler.GetAstTransforms()) |
||||
s.Step(transform.GetType().Name); |
||||
return s; |
||||
} |
||||
|
||||
partial void OnCSharpDecompiled(ITextOutput output, DecompilationOptions options) |
||||
{ |
||||
// The button always shows so the pane is one click away; mirrors the ILAst language.
|
||||
// DockWorkspace is resolved lazily (an ImportingConstructor import would form a MEF
|
||||
// cycle via LanguageService -> Languages).
|
||||
(output as ISmartTextOutput)?.AddButton(Images.Images.ViewCode, "Show Steps", delegate { |
||||
AppComposition.TryGetExport<DockWorkspace>()?.ShowToolPane(DebugStepsPaneModel.PaneContentId); |
||||
}); |
||||
// Only a full run refreshes the step list; a step-limited re-decompile (triggered by the
|
||||
// pane itself) must leave the tree and the user's selection intact.
|
||||
if (options.StepLimit == int.MaxValue) |
||||
{ |
||||
_ = Stepper; |
||||
StepperUpdated?.Invoke(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
#endif
|
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#if DEBUG
|
||||
|
||||
using System; |
||||
|
||||
using ICSharpCode.Decompiler.IL.Transforms; |
||||
|
||||
namespace ILSpy.Languages |
||||
{ |
||||
/// <summary>
|
||||
/// A language that surfaces a <see cref="Stepper"/> of decompiler-pipeline steps for the
|
||||
/// Debug Steps pane to visualise. Implemented by <see cref="ILAstLanguage"/> (one node per IL
|
||||
/// transform step) and <see cref="CSharpLanguage"/> (one node per C# AST transform). The pane
|
||||
/// binds to whichever current language is an <see cref="IDebugStepProvider"/>, so it no longer has to
|
||||
/// know the concrete language type.
|
||||
/// </summary>
|
||||
internal interface IDebugStepProvider |
||||
{ |
||||
/// <summary>The step tree produced by the most recent full decompile.</summary>
|
||||
Stepper Stepper { get; } |
||||
|
||||
/// <summary>Raised after a full (non step-limited) decompile refreshes <see cref="Stepper"/>.</summary>
|
||||
event EventHandler? StepperUpdated; |
||||
|
||||
/// <summary>
|
||||
/// Language-specific options object the Debug Steps pane renders above the step tree
|
||||
/// (e.g. ILAst's writing-options checkboxes), or <see langword="null"/> when the language
|
||||
/// has no step options. The pane picks a template by the object's runtime type, so each
|
||||
/// language contributes its own controls.
|
||||
/// </summary>
|
||||
object? StepOptions { get; } |
||||
} |
||||
} |
||||
|
||||
#endif
|
||||
Loading…
Reference in new issue