Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect tabber id counts with nested tabbers #215

Conversation

nobbyfix
Copy link
Contributor

@nobbyfix nobbyfix commented Jan 27, 2025

Fix for the first issue in #207.

Tabber count is updated after render, but during render, recursiveTagParse is called. With nested tabbers, this causes the first nested one to use the still unupdated count, which it then shares with the parent tabber.

Summary by CodeRabbit

  • Bug Fixes
    • Updated tab counting mechanism to ensure accurate tab numbering in the Tabber extension.

Copy link

coderabbitai bot commented Jan 27, 2025

Walkthrough

The pull request introduces a subtle modification to the parserHook method in the Tabber class within the includes/Tabber.php file. The primary change involves altering the count increment mechanism for the tabber-count extension data. The implementation shifts from using a pre-increment operator to a post-increment approach, which affects how the tab count is calculated and stored during processing.

Changes

File Change Summary
includes/Tabber.php Modified parserHook method's count increment logic from ++$count to $count + 1 for tabber-count extension data

Possibly related PRs

Poem

🐰 A Tabber's Tale of Counting Delight

With plus one, the count takes flight,
Pre or post, the increment's might,
Tabs dancing in algorithmic glee,
A rabbit's logic, precise and free!

Code hops, count leaps with grace! 🦊


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
includes/Tabber.php (1)

54-56: Consider tracking parent-child tabber relationships.

The current implementation treats all tabbers independently. To ensure correct counting with nested tabbers, consider tracking parent-child relationships.

Example approach:

private static $tabberStack = [];

public static function parserHook( ?string $input, array $args, Parser $parser, PPFrame $frame ) {
    // ... existing code ...
    
    $parentCount = end(self::$tabberStack) ?? null;
    self::$tabberStack[] = $count;
    
    $html = self::render( $input, $count, $args, $parser, $frame );
    
    array_pop(self::$tabberStack);
    // ... rest of the code ...
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1ecc1a and dd19b1c.

📒 Files selected for processing (1)
  • includes/Tabber.php (1 hunks)
🔇 Additional comments (2)
includes/Tabber.php (2)

Line range hint 147-148: Verify recursiveTagParse behavior with nested tabbers.

The getTabContent method uses recursiveTagParse which can trigger nested tabber parsing. We should ensure that the count increment fix works correctly in this context.

✅ Verification successful

Count increment fix is safe with nested tabbers

The codebase deliberately uses recursiveTagParse() with a safe recursion depth limit, as confirmed by issue #27. The count increment fix works correctly in this context.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are any special handling for nested parsing
# or related issues in the codebase.

# Look for recursiveTagParse usage and related comments/issues
rg -B 5 -A 5 'recursiveTagParse'

# Search for any nested parsing related issues
rg -l 'nested.*tab|recursive.*parse' .github/

Length of output: 5039


Script:

#!/bin/bash
# Search for test cases and nested tabber handling
rg -B 3 -A 3 "nested.*tabber" tests/
rg -B 3 -A 3 "test.*nested" tests/

# Look up issue #27 details
gh issue view 27 || true

# Search for any special handling or comments about nested tabbers
ast-grep --pattern 'class Tabber {
  $$$
  // $$$nested$$$
  $$$
}'

rg -B 3 -A 3 "nested" includes/

Length of output: 1250


55-55: Verify if this fix addresses nested tabber counts correctly.

While changing ++$count to $count + 1 prevents modifying the count before storing, we should verify if this fully resolves the nested tabber count issue.

Let's verify the fix with a test case containing nested tabbers:

Additionally, consider adding a test case that specifically validates nested tabber behavior:

// Test case suggestion
$input = "<tabber>
Tab1 = <tabber>
  NestedTab1 = Content1
  NestedTab2 = Content2
</tabber>
Tab2 = Content
</tabber>";
✅ Verification successful

Fix for nested tabber count is correct and properly implemented.

The implementation correctly handles nested tabber counts by:

  • Incrementing the count atomically before content parsing
  • Using extension data to maintain state
  • Supporting nested tabbers through parser functions

The change from ++$count to $count + 1 ensures each tabber (including nested ones) gets its own unique count, as the original count value remains unmodified during the parsing of nested content.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for test cases or examples with nested tabbers
# to verify if the count increment fix works correctly.

# Look for nested tabber test cases
rg -A 10 '<tabber.*<tabber' tests/

Length of output: 83


Script:

#!/bin/bash
# Find test and documentation files
echo "=== Looking for test directories ==="
fd -t d -i "test|spec|phpunit"

echo -e "\n=== Looking for test files ==="
fd -e test.php -e Test.php -e spec.php

echo -e "\n=== Looking for documentation ==="
fd -i "readme|documentation|wiki" -e md -e txt

echo -e "\n=== Searching for tabber patterns in all files ==="
rg -l "tabber"

Length of output: 2195


Script:

#!/bin/bash
# Check documentation and implementation

echo "=== README.md content ==="
cat README.md

echo -e "\n=== Recent CHANGELOG entries ==="
cat CHANGELOG.md

echo -e "\n=== Tabber.php implementation ==="
rg -B 5 -A 10 "recursiveTagParse|appendExtensionData" includes/Tabber.php

echo -e "\n=== Searching for nested tabber mentions ==="
rg -i "nest.*tabber"

Length of output: 42073

@alistair3149 alistair3149 merged commit 2430ad0 into StarCitizenTools:main Jan 27, 2025
2 checks passed
@nobbyfix nobbyfix deleted the patch-nested-tabber-incorrect-count branch January 28, 2025 00:57
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.

2 participants