Skip to content

fix: recurse into nested child tabs in DocsService#218

Open
allenhutchison wants to merge 2 commits intomainfrom
fix/207-nested-child-tabs
Open

fix: recurse into nested child tabs in DocsService#218
allenhutchison wants to merge 2 commits intomainfrom
fix/207-nested-child-tabs

Conversation

@allenhutchison
Copy link
Contributor

Problem

Fixes #207

The Google Docs API returns tabs as a tree structure where each tab can have childTabs. The current code only iterates the top-level res.data.tabs array, so nested (child) tabs are silently ignored.

Affected methods: getText, appendText, replaceText.

Solution

Added a recursive _flattenTabs helper that walks the tab tree depth-first and returns a flat array. Updated all three methods to use it (one-line change each).

Tests

Added 4 new test cases covering nested child tab scenarios:

  • getText — includes text from nested child tabs
  • getText — finds a child tab by tabId
  • appendText — appends to a nested child tab by tabId
  • replaceText — replaces text in a nested child tab by tabId

All 390 tests pass across 25 suites.

The Google Docs API returns tabs as a tree structure where each tab can
have childTabs. getText, appendText, and replaceText only iterated the
top-level array, silently ignoring nested child tabs.

Add a recursive _flattenTabs helper that walks the tab tree depth-first
and returns a flat array. Update all three methods to use it.

Fixes #207
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @allenhutchison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a limitation where the DocsService was not correctly processing nested child tabs returned by the Google Docs API. By introducing a recursive utility function to flatten the tab hierarchy, the service's core text manipulation methods now fully support documents with complex tab structures, enhancing the robustness and completeness of the Google Docs integration.

Highlights

  • Nested Tab Handling: The Google Docs API returns tabs in a tree structure, but the previous implementation only processed top-level tabs. This PR introduces a recursive helper to correctly flatten the tab structure, ensuring all nested (child) tabs are included.
  • Affected Methods: The getText, appendText, and replaceText methods in DocsService have been updated to utilize the new tab flattening logic, allowing them to correctly interact with nested child tabs.
  • Comprehensive Testing: Four new test cases were added to cover scenarios involving nested child tabs for getText, appendText, and replaceText, ensuring the new functionality works as expected.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • workspace-server/src/tests/services/DocsService.test.ts
    • Added new test cases for getText to verify inclusion of text from nested child tabs and finding a child tab by ID.
    • Added a test case for appendText to confirm appending text to a nested child tab by ID.
    • Added a test case for replaceText to ensure text replacement in a nested child tab by ID.
  • workspace-server/src/services/DocsService.ts
    • Added a private recursive helper method _flattenTabs to convert a hierarchical tab structure into a flat array.
    • Updated getText to use _flattenTabs for comprehensive tab processing.
    • Updated appendText to use _flattenTabs for comprehensive tab processing.
    • Updated replaceText to use _flattenTabs for comprehensive tab processing.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the issue of nested child tabs not being processed in DocsService. The introduction of the _flattenTabs helper is a clean solution, and applying it to getText, appendText, and replaceText ensures consistent behavior. The new tests are comprehensive and cover the nested tab scenarios well, confirming the fix. I have one suggestion to make the _flattenTabs implementation even more concise and idiomatic.

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.

docs.getText (and other tab methods) do not recurse into nested/child tabs

1 participant