Skip to content

Fix ShowWindow not displaying all example Introduction items (#26676)#26860

Open
kdt523 wants to merge 4 commits intoPowerShell:masterfrom
kdt523:fix/showwindow-example-introduction-26676
Open

Fix ShowWindow not displaying all example Introduction items (#26676)#26860
kdt523 wants to merge 4 commits intoPowerShell:masterfrom
kdt523:fix/showwindow-example-introduction-26676

Conversation

@kdt523
Copy link

@kdt523 kdt523 commented Feb 20, 2026

Fixes #26676

Get-Help <cmdlet> -ShowWindow was silently truncating example content.
Only the first element of the Introduction array was rendered in the ShowWindow UI, causing examples to appear incomplete or missing entirely.

PR Summary

New PlatyPS stores each example's introduction as a PSObject[] (an array of text nodes).
The ShowWindow rendering path in HelpParagraphBuilder.AddExamples() was calling
GetTextFromArray(example, "introduction"), which only ever returns
introductionObjects[0].text, silently dropping every subsequent element in the array.

Root cause:

// BUG: GetTextFromArray returns only [0] — all remaining items dropped
introductionText = GetTextFromArray(example, "introduction");
// ... then baked as a prefix into the codeLine string

Fix — inline foreach that renders every element in order:

PSObject[] introductionObjects =
    HelpParagraphBuilder.GetPropertyObject(example, "introduction") as PSObject[];

if (introductionObjects != null)
{
    foreach (PSObject intro in introductionObjects)
    {
        string introText = GetPropertyString(intro, "text");
        if (introText != null)
        {
            this.AddText(HelpParagraphBuilder.AddIndent(introText), false);
        }
    }
}

All introduction elements are now rendered through the same existing AddText pipeline, in the correct order, before the code block.

PR Context

  • GetTextFromArray() is intentionally left unchanged — it correctly serves description, notes/alert, and parameter description sections which are all single-text-node scenarios.
  • Null-safe:
    • null array → skipped
    • null element .text → skipped
  • No behavior change for single-element Introduction arrays (old MAML format).
  • No architectural changes, no new abstractions, no renamed methods.
  • Only AddExamples() in HelpParagraphBuilder.cs is modified.

Files Changed

File Change
src/Microsoft.Management.UI.Internal/HelpWindow/HelpParagraphBuilder.cs Bug fix in AddExamples()
test/powershell/engine/Help/HelpSystem.Tests.ps1 Regression test (CI tag)

PR Checklist

  • PR has a meaningful title
  • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1, and .psm1 files have the correct copyright header
  • This PR is ready to merge

Breaking changes

None

User-facing changes

Documentation needed
Issue filed: #26676

Testing - New and feature

Added regression test to test/powershell/engine/Help/HelpSystem.Tests.ps1, tagged for CI.

The test defines a helper function with a .EXAMPLE block in comment-based help, retrieves it via Get-Help -Full, and asserts that all elements of example.introduction are non-null — validating the data structure that the fixed foreach loop reads.

The ShowWindow WPF window cannot be launched in headless CI; the test validates the PSObject[] data layer that AddExamples() consumes.

…ell#26676)

AddExamples() was calling GetTextFromArray() which only returned
Introduction[0].text, silently dropping all subsequent array elements
when new PlatyPS stores example introduction as string[].

Fix: replace the single GetTextFromArray call with an inline foreach
over the raw PSObject[], rendering each element via AddText in order.

Null-safe: null array and null element text are both guarded.
No other sections or callers are changed.

Test: regression test added to HelpSystem.Tests.ps1 (CI tag).
@kdt523 kdt523 requested a review from a team as a code owner February 20, 2026 07:28
Copilot AI review requested due to automatic review settings February 20, 2026 07:28
@kdt523
Copy link
Author

kdt523 commented Feb 20, 2026

@kdt523 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a bug in the Get-Help -ShowWindow feature where only the first element of an example's introduction array was displayed. With new PlatyPS, help examples store introduction content as a PSObject[] array, but the rendering code in HelpParagraphBuilder.AddExamples() only extracted the first element using GetTextFromArray(), which by design returns only introductionObjects[0].text.

Changes:

  • Replaced GetTextFromArray() call with inline foreach loop to iterate all introduction array elements
  • Removed introduction text from code format string since it's now added separately
  • Added regression test to validate introduction array accessibility

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Microsoft.Management.UI.Internal/HelpWindow/HelpParagraphBuilder.cs Fixed AddExamples() to iterate all introduction elements instead of only [0]
test/powershell/engine/Help/HelpSystem.Tests.ps1 Added regression test for introduction array structure

string introText = GetPropertyString(intro, "text");
if (introText != null)
{
this.AddText(HelpParagraphBuilder.AddIndent(introText), false);
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

Missing line break after each introduction text element. The current code adds introduction text without a line break between elements, which will cause multiple introduction lines to run together without spacing.

Following the pattern used in AddDescription (lines 467-472) and the remarks section (lines 552-562), each introduction element should be followed by a line break. After line 534, add:
this.AddText("\r\n", false);

This ensures proper spacing between introduction array elements, matching the formatting used elsewhere in the codebase for similar array-based text rendering.

Suggested change
this.AddText(HelpParagraphBuilder.AddIndent(introText), false);
this.AddText(HelpParagraphBuilder.AddIndent(introText), false);
this.AddText("\r\n", false);

Copilot uses AI. Check for mistakes.
Comment on lines +732 to +745
It 'example introduction elements are all accessible as an array' {
$help = Get-Help -Name Get-HelpExampleIntroTest -Full
$help.examples | Should -Not -BeNullOrEmpty
$example = $help.examples.example[0]
$example | Should -Not -BeNullOrEmpty

# introduction is a PSObject[] - every element must have a non-null text value
# so that AddExamples' foreach loop can render all of them without data loss
if ($null -ne $example.introduction) {
foreach ($intro in $example.introduction) {
$intro | Should -Not -BeNullOrEmpty
}
}
}
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The test doesn't validate that multiple introduction elements exist or are rendered correctly. The example in the test function only has a single-line example with "PS C:> Get-HelpExampleIntroTest" followed by "Runs the test function." This may not produce multiple introduction array elements.

Consider adding a test that:

  1. Verifies that example.introduction is actually an array with multiple elements (e.g., $example.introduction.Count | Should -BeGreaterThan 1)
  2. Or uses an example that is known to produce multiple introduction elements
  3. Validates the actual text content of multiple introduction elements

This would better ensure the fix correctly handles the multi-element scenario described in the PR.

Copilot uses AI. Check for mistakes.
- HelpParagraphBuilder.cs: add \r\n after each introduction text element,
  matching the pattern in AddDescription and the remarks loop.
- HelpSystem.Tests.ps1: replace weak comment-based-help test with a test
  that loads a real MAML XML file (MultiIntroExample-help.xml) containing
  two <maml:para> introduction elements and asserts Count -gt 1 plus
  validates the text of each element.
@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Mar 4, 2026
@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review - Needed The PR is being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With ShowWindow, Get-Help does not display examples

2 participants