Skip to content

fix: incorrect formatting when term is empty#335

Merged
QuadnucYard merged 1 commit intotypstyle-rs:masterfrom
QuadnucYard:fix-empty-term
Jun 27, 2025
Merged

fix: incorrect formatting when term is empty#335
QuadnucYard merged 1 commit intotypstyle-rs:masterfrom
QuadnucYard:fix-empty-term

Conversation

@QuadnucYard
Copy link
Copy Markdown
Collaborator

fixes #334

Copy link
Copy Markdown
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.

Summary of Changes

Hello @QuadnucYard, 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 bug where empty terms were incorrectly formatted by the pretty-printer. The changes refine the markup processing logic to correctly identify and handle empty terms, ensuring they are either ignored or formatted appropriately. New snapshot tests have been added to validate the fix across various empty term scenarios.

Highlights

  • Formatting Logic Refinement: Introduced a seen_term boolean flag within the PrettyPrinter's convert_flow_like method. This flag is now set to true when a SyntaxKind::Colon is encountered, indicating that a term has been processed.
  • Conditional Markup Processing: Modified the handling of SyntaxKind::Markup to conditionally ignore empty markup elements. Previously, empty markup was always ignored. Now, it is only ignored if a term (colon) has already been seen and the markup itself has no children. This prevents incorrect formatting for cases where a term is empty (e.g., / :).
  • Code Cleanup: Removed a redundant seen_term = true assignment and simplified the return logic within the SyntaxKind::Markup processing block, as the seen_term flag is now correctly updated earlier.
  • New Test Cases: Added a new input test file (term-empty.typ) and corresponding snapshot test files (term-empty.typ-*.snap) to validate the correct formatting behavior for various scenarios involving empty terms, terms with spaces, and terms with newlines.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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
Copy Markdown
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

The pull request fixes an issue where incorrect formatting occurred when the term was empty. The changes involve adjusting the logic for handling SyntaxKind::Colon and SyntaxKind::Markup within the PrettyPrinter struct to correctly manage the seen_term flag and ensure proper formatting in cases where the term is empty.

@github-actions
Copy link
Copy Markdown

📊 Benchmark Performance Report

group                        base                                   pr
-----                        ----                                   --
pretty-cetz-manual           1.00   839.8±10.46µs        ? ?/sec    1.01    844.4±6.66µs        ? ?/sec
pretty-codly                 1.00  1964.8±12.40µs        ? ?/sec    1.02  1994.4±10.34µs        ? ?/sec
pretty-cpe                   1.00     13.1±0.65ms        ? ?/sec    1.00     13.2±0.26ms        ? ?/sec
pretty-deep-nested-args      1.00    779.0±3.37ms        ? ?/sec    1.01    788.6±2.45ms        ? ?/sec
pretty-fletcher-diagram      1.00    562.1±6.50µs        ? ?/sec    1.01   565.0±15.71µs        ? ?/sec
pretty-fletcher-draw         1.00  1360.3±14.74µs        ? ?/sec    1.01  1373.2±31.47µs        ? ?/sec
pretty-tablex                1.00      3.6±0.02ms        ? ?/sec    1.00      3.6±0.01ms        ? ?/sec
pretty-touying-core          1.00      2.3±0.01ms        ? ?/sec    1.01      2.4±0.01ms        ? ?/sec
pretty-touying-utils         1.00  1312.4±12.18µs        ? ?/sec    1.01  1326.0±22.03µs        ? ?/sec
pretty-undergraduate-math    1.00   916.1±11.25µs        ? ?/sec    1.02   938.5±13.48µs        ? ?/sec

Generated by GitHub Actions on Thu Jun 26 11:38:53 UTC 2025

@QuadnucYard QuadnucYard merged commit ae0bd0a into typstyle-rs:master Jun 27, 2025
17 checks passed
@QuadnucYard QuadnucYard deleted the fix-empty-term branch June 27, 2025 08:23
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.

Formatting change in blank term list item

2 participants