Registry Mirror
Skip to content

Conversation

@siegfriedpammer

Copy link
Copy Markdown
Member

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.

  • Toggling from the body or the header line folds the member together with its /// documentation; the header line targets the member, not the enclosing type.
  • With the caret inside the documentation, the doc fold 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.

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: TextTokenWriter records where each entity declaration begins (new ITextOutput.MarkDefinitionStart(); note this is an interface addition), and the entity's body fold carries that offset in a DefinitionNewFolding, reachable at toggle time via FoldingSection.Tag. ToggleFoldingAt selects 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 enabling GenerateDocumentationFile would 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 from TextTokenWriter for EntityDeclaration nodes so definition folds can “logically” start before the body fold.
  • Tag definition-body foldings with their logical start offset (DefinitionNewFolding) and update ToggleFoldingAt to 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
siegfriedpammer merged commit 800efc6 into master Jul 28, 2026
13 checks passed
@siegfriedpammer
siegfriedpammer deleted the fix-749-fold-groups branch July 28, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Toggle folding should also toggle xml doc comments

2 participants