Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes folding toggling in ILSpy’s decompiled code view so that a member’s fold behaves as one logical unit with its leading XML documentation (and the signature/header line correctly targets the member instead of collapsing the enclosing type). It does this by extending the decompiler output contract to record where an entity definition begins, and by adjusting folding selection/toggle logic in the AvaloniaEdit-based UI.
Changes:
- Add
ITextOutput.MarkDefinitionStart()and emit it fromTextTokenWriterforEntityDeclarationnodes so definition folds can “logically” start before the body fold. - Tag definition-body foldings with their logical start offset (
DefinitionNewFolding) and updateToggleFoldingAtto pick folds by logical region and drag leading doc folds along. - Add headless UI tests (
FoldingGroupTests) covering grouped toggling, header-line targeting, docs-only behavior, and Toggle-All parity.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ILSpy/TextView/DefinitionNewFolding.cs | Introduces a NewFolding subtype carrying the logical definition start offset. |
| ILSpy/TextView/DecompilerTextView.axaml.cs | Updates fold selection/toggling to use logical starts and group leading doc folds; adjusts “toggle all” behavior. |
| ILSpy/TextView/AvaloniaEditTextOutput.cs | Records pending definition start and creates DefinitionNewFolding for definition folds. |
| ILSpy.Tests/Editor/FoldingGroupTests.cs | Adds regression tests for grouped folding behavior and toggle-all parity. |
| ICSharpCode.Decompiler/Output/TextTokenWriter.cs | Emits MarkDefinitionStart() for entity declarations to anchor logical fold starts. |
| ICSharpCode.Decompiler/Output/PlainTextOutput.cs | Adds MarkDefinitionStart() plumbing; includes a rollback-output recorder that must preserve isDefinition. |
| ICSharpCode.Decompiler/Output/ITextOutput.cs | Extends the output interface with MarkDefinitionStart(). |
| ICSharpCode.Decompiler.Tests/Output/TextTokenWriterTests.cs | Updates test ITextOutput implementation to satisfy the new interface member. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Toggle folding picked the innermost fold containing the offset, but a member's logical region is fragmented: the body fold starts at the opening brace, the XML documentation has an independent fold, and the header line belongs to neither, so toggling there collapsed the whole enclosing type. Visual Studio's source editor keeps documentation regions independent, but its metadata-as-source view treats the member's leading trivia as one hideable unit; for a read-only decompiler view the grouped behavior is the intuitive one. The writer now records where an entity declaration begins, and the definition's fold carries that logical start. Toggling targets the fold whose logical region innermost-contains the offset, so the header line targets the member rather than the type, and leading documentation folds follow the member fold's new state. Inside the documentation the doc fold itself is the innermost region and still toggles alone. Toggle all folding now follows Visual Studio's Toggle All Outlining parity: a mixed state expands everything, a uniform state flips. Assisted-by: Claude:claude-fable-5:Claude Code
siegfriedpammer
force-pushed
the
fix-749-fold-groups
branch
from
July 27, 2026 20:14
8e0a923 to
da14460
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #749.
Toggle folding picked the innermost fold containing the offset, but a member's logical region is fragmented: the body fold starts at the opening brace, the XML documentation has an independent fold, and the header line belongs to neither — so toggling on a signature line even collapsed the whole enclosing type.
Behavior: members now toggle as one logical unit.
///documentation; the header line targets the member, not the enclosing type.Relation to Visual Studio: VS's source editor keeps documentation regions independent, but its outlining spans start at the end of the parameter list (so a signature-line toggle targets the member — Roslyn
MethodDeclarationStructureProvider), and its metadata-as-source view merges a member's leading trivia, docs included, into a single hideable region (CSharpStructureHelpers.CollectCommentBlockSpans). For a read-only decompiler view the grouped behavior is the intuitive extension of that.Mechanism:
TextTokenWriterrecords where each entity declaration begins (newITextOutput.MarkDefinitionStart(); note this is an interface addition), and the entity's body fold carries that offset in aDefinitionNewFolding, reachable at toggle time viaFoldingSection.Tag.ToggleFoldingAtselects the fold whose logical region innermost-contains the offset (tie broken toward the tighter range) and drags the leading documentation folds along to the same state.Tests: new
FoldingGroupTests(body-toggle groups docs, header-line targets the member, docs-only toggle preserved, toggle-all parity), red-first against master. The documentation comments for the fixture come from a hand-written XML documentation file placed next to the test assembly, since enablingGenerateDocumentationFilewould trip CS1591 against warnings-as-errors. Full ILSpy.Tests 1073 passed / 3 skipped, full decompiler suite 2544 total / 0 failed.🤖 This PR was prepared by an AI agent (Claude Code) operated by @siegfriedpammer.