Skip to content

feat(extensions): Custom Rule Source Provider#8141

Open
JamyDev wants to merge 3 commits intobazelbuild:ijwbfrom
JamyDev:feat/custom-rule-sources
Open

feat(extensions): Custom Rule Source Provider#8141
JamyDev wants to merge 3 commits intobazelbuild:ijwbfrom
JamyDev:feat/custom-rule-sources

Conversation

@JamyDev
Copy link
Contributor

@JamyDev JamyDev commented Feb 5, 2026

The CustomRuleSourceConfig extension point allows plugins to specify which attributes contain sources for custom rule types. This is useful when you have custom Bazel rules that have custom source attributes beyond the standard srcs (as per #8140

Checklist

  • I have filed an issue about this change and discussed potential changes with the maintainers.
  • I have received the approval from the maintainers to make this change.
  • This is not a stylistic, refactoring, or cleanup change.

Discussion thread for this change

Issue number: #8140

Description of this change

  • Modifies (cc|java|python)_info aspect templates to support code generator
  • Adds CUSTOM_RULE_SOURCES to code_generator_info.bzl
  • Adds CustomRuleSources extension point that lets external plugin provide the getSourceAttributes value.
    • This value gets used in aspect/intellij_info_impl.bzl to provide the updated sources, then passes that to the relevant ide_info struct.

@github-actions github-actions bot added product: CLion CLion plugin product: IntelliJ IntelliJ plugin product: GoLand GoLand plugin awaiting-review Awaiting review from Bazel team on PRs labels Feb 5, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @JamyDev, 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 Bazel plugin's ability to integrate with custom Bazel rules by providing a flexible mechanism for defining and collecting non-standard source attributes. By introducing a new extension point and updating the aspect generation logic, the IDE can now better understand and provide language support for projects utilizing custom rule types, improving the overall development experience and reducing manual configuration needs for specialized build setups.

Highlights

  • New Extension Point: Introduced a new extension point, CustomRuleSourceConfig, allowing plugins to define custom source attributes for Bazel rules. This enables the IDE to correctly identify and process source files from non-standard attributes.
  • Aspect Template Updates: Modified code_generator_info.bzl to include a CUSTOM_RULE_SOURCES struct, which stores configurations for custom rule source attributes. intellij_info_impl.bzl now uses this information to collect sources and populate language-specific IDE info (Go, Python, C/C++).
  • Documentation: Added comprehensive documentation (docs/extension_points/custom_rule_source.md) explaining how to implement and register CustomRuleSourceConfig extensions, including examples for custom Go rules.
Changelog
  • aspect/cc_info.bzl
    • Adjusted indentation for template include blocks.
  • aspect/code_generator_info.bzl
    • Added CUSTOM_RULE_SOURCES struct to hold custom rule source configurations.
    • Introduced get_custom_rule_source_config function to retrieve configurations by rule kind.
  • aspect/intellij_info_impl.bzl
    • Imported CcInfoCompat and get_custom_rule_source_config.
    • Added collect_custom_rule_info function to process custom rule sources based on configurations.
    • Integrated collect_custom_rule_info into the main intellij_info_aspect_impl to handle custom rule source collection.
  • aspect/java_info.bzl
    • Adjusted indentation for template include blocks.
  • aspect/python_info.bzl
    • Adjusted indentation for template include blocks.
  • aspect/scala_info.bzl
    • Adjusted indentation for template include blocks.
  • base/src/META-INF/blaze-base.xml
    • Registered the new com.google.idea.blaze.CustomRuleSourceConfig extension point.
  • base/src/com/google/idea/blaze/base/sync/aspects/CustomRuleSourceConfig.java
    • Added new interface CustomRuleSourceConfig for defining custom rule source attributes, including methods for getRuleKind, getLanguageClass, and getSourceAttributes.
  • base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectTemplateWriter.kt
    • Imported CustomRuleSourceConfig.
    • Modified to collect all registered CustomRuleSourceConfig extensions.
    • Passed customRuleSourceConfigs to the code_generator_info.bzl template for dynamic generation.
    • Added CustomRuleSourceConfigInfo data class to model custom rule source configurations for template generation.
  • docs/extension_points/custom_rule_source.md
    • Added new documentation file detailing the CustomRuleSourceConfig extension point.
    • Provided an overview, how-to guide, example for custom Go rules, supported languages, and implementation details.
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

@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 a new extension point CustomRuleSourceConfig to allow plugins to specify source attributes for custom Bazel rules. This is a great feature for improving IDE support. The implementation looks mostly good, with new extension points in Java, updates to aspect template writers in Kotlin, and new documentation.

However, I've found a couple of critical issues in the Starlark aspect implementation (intellij_info_impl.bzl). The logic for collecting sources from custom attributes doesn't handle single-item attributes, and more importantly, the ide_info data structures created for custom rules are inconsistent with the existing ones, which will likely break parsing on the IDE side. I've provided suggestions to fix these issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review Awaiting review from Bazel team on PRs product: CLion CLion plugin product: GoLand GoLand plugin product: IntelliJ IntelliJ plugin

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

4 participants