Skip to content

Conversation

@sigmaaa
Copy link
Collaborator

@sigmaaa sigmaaa commented Feb 13, 2025

Description

Added an option to disable/enable auto-creation of clang-format file
image

Fixes # (IEP-1445)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this been tested?

Created/built the project with this option turned off and on, then checked if clang-format was created accordingly

Test Configuration:

  • ESP-IDF Version:
  • OS (Windows,Linux and macOS):

Dependent components impacted by this PR:

  • clang-format file
  • Espressif preference page

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Added Unit Test
  • Verified on all platforms - Windows,Linux and macOS

Summary by CodeRabbit

  • New Features
    • Added a new option in the preferences that lets users enable or disable the automatic creation of the .clang-format file.
    • The new setting includes an informative tooltip and defaults to an enabled state, ensuring a consistent formatting configuration during builds.
    • Introduced new constants for preference management related to Clang format file automation.
  • Localization
    • Added new strings for button naming and tooltip messages to enhance user interface localization for the preferences page.
  • Documentation
    • Updated the documentation to include instructions on the automatic creation of .clang-format files and how to manage this setting.

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

The pull request introduces enhancements for automating the creation of the Clang format file. It adds new constants in the core preferences to manage this automation. A new method in the Clang format handler encapsulates the logic for determining file creation based on file existence and user preferences. Additionally, a new button is added to the preferences page, allowing users to enable or disable this automation feature. Localization entries and tooltips are also provided to support the new user options.

Changes

File(s) Change Summary
bundles/com.espressif.idf.core/.../IDFCorePreferenceConstants.java Added two new constants: AUTOMATE_CLANGD_FORMAT_FILE (String) and AUTOMATE_CLANGD_FORMAT_FILE_DEFAULT (boolean) for Clang format file automation.
bundles/com.espressif.idf.core/.../ClangFormatFileHandler.java Introduced a new method shouldCreateClangFormat() to decide on file creation, with updated import statements for necessary dependencies.
bundles/com.espressif.idf.ui/.../EspresssifPreferencesPage.java Added a new UI button (automateClangdFormatCreationBtn) to toggle the automation feature; updated performOk/performDefaults methods to save and set preference values.
bundles/com.espressif.idf.ui/.../Messages.java Added new localization strings for the button and tooltip related to Clang format file automation.
bundles/com.espressif.idf.ui/.../messages.properties Added entries for button name and tooltip message to support localization of the new UI feature.
docs_readme/clangd_cdt_support.md Added a new section detailing the automatic creation of .clang-format files and instructions for users to manage this feature.

Sequence Diagram(s)

sequenceDiagram
    participant CFH as ClangFormatFileHandler
    participant PS as Platform/Preference Store
    participant FS as File System

    CFH->>CFH: update()
    CFH->>CFH: shouldCreateClangFormat()
    CFH->>PS: Retrieve AUTOMATE_CLANGD_FORMAT_FILE preference
    PS-->>CFH: Return boolean value
    alt File missing and automation enabled
        CFH->>FS: Create .clang-format file
    else
        CFH-->>CFH: Skip file creation
    end
Loading
sequenceDiagram
    participant U as User
    participant EP as EspresssifPreferencesPage
    participant PS as Preference Store

    U->>EP: Toggle automateClangdFormatCreationBtn
    EP->>PS: Save updated preference (AUTOMATE_CLANGD_FORMAT_FILE)
    PS-->>EP: Preference updated
Loading

Possibly related PRs

Suggested reviewers

  • AndriiFilippov
  • alirana01
  • kolipakakondal

Poem

I’m a rabbit with coding cheer,
Hopping through constants and methods so clear.
A new button shines on the UI trail,
Automating files without fail.
With each line of code, my heart delights—
A carrot dance for automated bytes!
🐰✨


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.

@sigmaaa sigmaaa linked an issue Feb 13, 2025 that may be closed by this pull request
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: 2

🧹 Nitpick comments (2)
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ClangFormatFileHandler.java (2)

28-40: Update JavaDoc to reflect the configurable behavior.

The method's behavior has changed to respect user preferences, but this isn't reflected in the documentation.

Apply this diff to update the JavaDoc:

 /**
- * Updates the .clang-format file. If the file does not exist, it is created and initialized with default settings.
+ * Updates the .clang-format file. If the file does not exist and automatic creation is enabled in preferences,
+ * it is created and initialized with default settings.
  *
  * @throws IOException   if an I/O error occurs during file creation or writing
  * @throws CoreException if an error occurs while refreshing the project
  */

34-45: Consider validating existing .clang-format files.

The current implementation only checks for file existence, but not its validity. Consider adding validation for existing .clang-format files to ensure they are well-formed.

This would help catch corrupted files early and prevent potential issues with clang formatting. I can help implement the validation logic if you'd like.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e60d439 and 6aa32e4.

📒 Files selected for processing (5)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFCorePreferenceConstants.java (2 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ClangFormatFileHandler.java (3 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/EspresssifPreferencesPage.java (7 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/Messages.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/messages.properties (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (7)
bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFCorePreferenceConstants.java (2)

30-31: LGTM! Well-structured preference constants.

The new constants follow the established naming patterns and properly use the NON-NLS tag. Setting the default to true maintains backward compatibility with existing behavior.


45-45: LGTM! Consistent formatting.

The added empty line maintains consistent spacing between different sections of constants.

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ClangFormatFileHandler.java (2)

13-16: LGTM!

The new imports are necessary for accessing platform preferences and core constants to support the configurable .clang-format file creation feature.


47-52: LGTM!

The method implementation is clean and follows best practices:

  • Clear and descriptive method name
  • Correct logic combining file existence check with user preference
  • Proper use of preference service API
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/Messages.java (1)

8-9: LGTM! New localization strings follow existing patterns.

The new string constants for the Clang format automation button are properly declared and follow the established naming conventions.

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/EspresssifPreferencesPage.java (2)

175-180: LGTM! Clean implementation of the new preference option.

The new checkbox for controlling Clang format automation is well-implemented:

  • Properly placed in the build settings group
  • Follows the established pattern for preference options
  • Uses localized strings for text and tooltip

268-269: LGTM! Proper error handling for preference updates.

The new preference value is saved within the existing try-catch block, ensuring errors are properly logged and handled.

Comment on lines +1 to +2
EspresssifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
EspresssifPreferencesPage_AutoCreateClangFormatTooltipMsg=Ensures .clang-format exists, generating it if missing after project creation and on each build.
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix spelling and improve message organization.

  1. The key prefix has a spelling error: "Espresssif" should be "Espressif" (3 's' vs 2 's').
  2. Consider moving these entries near other build-related settings for better organization.
  3. The tooltip message could be more concise.

Apply this diff to fix the issues:

-EspresssifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
-EspresssifPreferencesPage_AutoCreateClangFormatTooltipMsg=Ensures .clang-format exists, generating it if missing after project creation and on each build.
+EspressifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
+EspressifPreferencesPage_AutoCreateClangFormatTooltipMsg=Automatically generate .clang-format file if missing during project creation and builds.

Move these entries after line 3 (EspresssifPreferencesPage_BuildGroupTxt) to group them with other build-related settings.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
EspresssifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
EspresssifPreferencesPage_AutoCreateClangFormatTooltipMsg=Ensures .clang-format exists, generating it if missing after project creation and on each build.
# ... (other entries before line 3 remain unchanged)
EspresssifPreferencesPage_BuildGroupTxt=Build Settings
EspressifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
EspressifPreferencesPage_AutoCreateClangFormatTooltipMsg=Automatically generate .clang-format file if missing during project creation and builds.
# ... (any entries after remain unchanged)

…ces/EspresssifPreferencesPage.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@AndriiFilippov
Copy link
Collaborator

AndriiFilippov commented Feb 17, 2025

@sigmaaa hi !

Tested under:
OS - Windows 11 / Mac arm64
ESP-IDF: v5.4

Created/built the project with this option turned off and on, and verified that the .clang-format file was created only when the option was enabled, confirming the expected behavior. ✅

Created .clang-format file inside root directory - build project - checked if it able to find .clang-format file outside project folder ✅

LGTM 👍

@AndriiFilippov
Copy link
Collaborator

@kolipakakondal @alirana01 hi !

Please, review

Copy link
Collaborator

@alirana01 alirana01 left a comment

Choose a reason for hiding this comment

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

LGTM just need to confirm with @AndriiFilippov and @kolipakakondal if this is okay in terms of UX
Because I am not sure if this should be under Build settings or a separate editor settings.

Copy link
Collaborator

@kolipakakondal kolipakakondal left a comment

Choose a reason for hiding this comment

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

Can you add this to the Clangd editor documentation as well? Please explain the reason for doing this and mention that it is useful for projects migrated from earlier versions (2.x to 3.x) to ensure compatibility with the Clangd editor. Otherwise, it looks good to me.

@kolipakakondal
Copy link
Collaborator

LGTM just need to confirm with @AndriiFilippov and @kolipakakondal if this is okay in terms of UX Because I am not sure if this should be under Build settings or a separate editor settings.

Agree. We are doing this during the build to address old project migrations (2.x to 3.x). We could categorize this under "Clangd Settings" so that, going forward, any additional related settings can be added here.

@kolipakakondal kolipakakondal added this to the v3.3.0 milestone Feb 19, 2025
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c8a4e5e and ce1f4c0.

📒 Files selected for processing (3)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/EspresssifPreferencesPage.java (7 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/Messages.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/messages.properties (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/messages.properties
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/Messages.java
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build_macos
🔇 Additional comments (4)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/EspresssifPreferencesPage.java (4)

46-46: LGTM!

The field declaration follows the class's naming convention and encapsulation principles.


89-101: LGTM!

The method follows the established pattern for adding preference groups and correctly initializes the UI elements. The implementation aligns with the PR objective to add a user-friendly toggle for .clang-format file creation.


276-277: LGTM!

The preference saving logic is consistent with other similar settings and properly handles errors.


324-325: LGTM!

The default value initialization is consistent with other similar settings.

Comment on lines +299 to +300
automateClangdFormatCreationBtn
.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use getDefaultBoolean for resetting to default value.

When resetting to defaults, use getDefaultBoolean instead of getBoolean to ensure the correct default value is used.

Apply this diff to fix the issue:

-				.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
+				.setSelection(getPreferenceStore().getDefaultBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
automateClangdFormatCreationBtn
.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
automateClangdFormatCreationBtn
.setSelection(getPreferenceStore().getDefaultBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));

@sigmaaa
Copy link
Collaborator Author

sigmaaa commented Feb 20, 2025

LGTM just need to confirm with @AndriiFilippov and @kolipakakondal if this is okay in terms of UX Because I am not sure if this should be under Build settings or a separate editor settings.

Agree. We are doing this during the build to address old project migrations (2.x to 3.x). We could categorize this under "Clangd Settings" so that, going forward, any additional related settings can be added here.

Hi @kolipakakondal, updated the documentation and updated Espressif preference page as follows:
image

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 (2)
docs_readme/clangd_cdt_support.md (2)

54-56: Minor Whitespace Adjustments

The insertion of these blank lines (or marker lines) helps visually separate the sections, improving readability. There is no negative impact on the output.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

54-54: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


57-63: New Section: Automatic .clang-format Creation

This section clearly documents the new feature that automatically creates a .clang-format file for each project. The step-by-step instructions (navigating to Window > Preferences > Espressif, locating the Auto-create .clang-format option, and applying changes) are concise and consistent with the overall style of the document.

Suggestions:

  • Verify that the option name (Auto-create .clang-format) exactly matches what appears in the Preferences dialog.
  • Consider adding a screenshot or an additional note for users migrating from older plugin versions to further enhance clarity.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ce1f4c0 and 2009005.

📒 Files selected for processing (1)
  • docs_readme/clangd_cdt_support.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs_readme/clangd_cdt_support.md

54-54: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_macos

@kolipakakondal
Copy link
Collaborator

LGTM

@kolipakakondal kolipakakondal merged commit cfd1a9b into master Feb 26, 2025
5 of 6 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 7, 2025
5 tasks
@kolipakakondal kolipakakondal deleted the IEP-1445 branch May 7, 2025 14: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.

Avoid creating '.clang-format' on each compilation (IEP-1445)

5 participants