Skip to content

Improve clang format#7037

Merged
waruqi merged 3 commits intodevfrom
format
Nov 19, 2025
Merged

Improve clang format#7037
waruqi merged 3 commits intodevfrom
format

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Nov 19, 2025

@waruqi waruqi added this to the v3.0.5 milestone Nov 19, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @waruqi, 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 significantly enhances the clang-format plugin by introducing parallel processing capabilities. It refactors the internal file handling and provides a new user-facing option to control concurrency, aiming to improve performance and user feedback when formatting large codebases.

Highlights

  • Parallel Formatting: The clang-format plugin now supports parallel execution of formatting jobs, significantly speeding up the process for multiple files.
  • New --jobs Option: A new command-line option --jobs (-j) has been introduced, allowing users to specify the number of parallel processes for formatting.
  • Refactored File Collection: The logic for collecting source and header files to be formatted has been refactored to store them in a dedicated table before processing.
  • Progress Reporting: Added progress reporting during parallel formatting, showing the current file being processed and the overall completion percentage.
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 introduces parallel execution for the clang-format plugin, which is a great performance enhancement. It adds a new --jobs option to control the number of parallel formatting jobs. The implementation correctly uses runjobs for parallelization. I've included one suggestion to improve the robustness of handling the --jobs option value to ensure it correctly falls back to the default when an invalid value is provided. Overall, this is a valuable improvement.

Comment on lines +214 to +219
local jobs = option.get("jobs")
if jobs then
jobs = tonumber(jobs)
else
jobs = os.default_njob()
end
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The current logic for determining the number of jobs is not fully robust. If a user provides a non-numeric value for the --jobs option (e.g., xmake format -j foo), tonumber() will return nil. The jobs variable will become nil, and runjobs will be called with comax = nil, likely falling back to a hardcoded default inside runjobs instead of using os.default_njob().

Additionally, since a default value is always provided for the jobs option, option.get("jobs") will never be nil, making the else block unreachable (dead code).

A more robust approach would be to convert the option value to a number and then check if the result is a valid positive number.

        local jobs = tonumber(option.get("jobs"))
        if not jobs or jobs <= 0 then
            jobs = os.default_njob()
        end

@waruqi waruqi mentioned this pull request Nov 19, 2025
@waruqi waruqi merged commit 9eb2b81 into dev Nov 19, 2025
44 of 45 checks passed
@waruqi waruqi deleted the format branch November 19, 2025 06:02
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.

1 participant