Skip to content

Include Bzlmod globals in builtin.proto #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

arvi18
Copy link

@arvi18 arvi18 commented Apr 28, 2025

This allows consumers of the proto to learn about globals only available in MODULE.bazel under a new ApiContext MODULE.

Also adds the ApiContext.BZL globals for repository rule and module extension definition.

A new smoke test verifies that common symbols are contained in the proto for each API context.

Work towards bazel-contrib/vscode-bazel#1

fmeum added 2 commits April 9, 2024 00:25
This allows consumers of the proto to learn about globals only available in `MODULE.bazel` under a new `ApiContext`.

Also adds a smoke test to verify that common symbols are contained in the proto for each API context.
@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

FYI @withered-magic

@meteorcloudy Not sure who to assign for this part of the codebase, feel free to reassign.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

Need to figure out how to add parameters.

Parameters are now available.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

I pushed a new commit to add module_extension and repository_rule, which were also missing.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

@tetromino are you the right person to review this? It's not too complicated and looks fine to me.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

@tetromino Friendly ping

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

@tetromino Gentle ping, following up on bazelbuild#21936 (comment)

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

@tetromino Friendly ping

Copy link

coderabbitai bot commented Apr 28, 2025

Warning

Rate limit exceeded

@arvi18 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c0c98a2 and 7973756.

📒 Files selected for processing (6)
  • src/main/java/com/google/devtools/build/docgen/ApiExporter.java (1 hunks)
  • src/main/java/com/google/devtools/build/docgen/BUILD (1 hunks)
  • src/main/java/com/google/devtools/build/docgen/SymbolFamilies.java (7 hunks)
  • src/main/protobuf/builtin.proto (1 hunks)
  • src/test/java/com/google/devtools/build/lib/BUILD (1 hunks)
  • src/test/java/com/google/devtools/build/lib/BuiltinProtoSmokeTest.java (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

Hi @tetromino,

Thanks for sharing your thoughts as well as an alternative design earlier this year, and for capturing our feedback on additional requirements for the LSP use cases in bazelbuild#21979 🙂

I still agree with the overall design: aligning the generation of documentation pages and language servers to both rely on Stardoc protos is a very good solution. This makes sure that the published documentation and the in-editor suggestions from the LSP will stay in sync.

I wonder if you can share additional details on your envisioned design, timeline, roadmap by now? Maybe the opensource community could contribute somehow, if we know what you are working towards and which design and work items you are having in mind?

As one of the maintainers of the Bazel VSCode extension, I want to integrate a language server directly into the VSCode extension, such that all users can benefit from auto-completion, signature help etc. However, with the current state of both language servers (bazel-lsp by @cameron-martin and starpls by @withered-magic), I don't feel comfortable shipping them to a larger user base. We would immediately get bug reports that autocompletion only works unreliably or even not at all for bzlmod files. As such, I need your help to make this happen 🙂

I guess that Google has its own, internal language server for Starlark / Bazel and hence I understand that this is not your highest priority. If you could share your roadmap, envisioned design etc. we, the community, could maybe fill in the blanks to pave the path towards a widely available Bazel language server.

Alternatively (e.g., in case the stardoc project is not getting sufficient funding inside Google for whatever reason), I would appreciate if we could reconsider merging this pull request as well as bazelbuild#21135, at least as a stop gap solution until we can work towards the long-term stardoc-based solution

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

Hi @vogelsgesang

I wonder if you can share additional details on your envisioned design, timeline, roadmap by now? Maybe the opensource community could contribute somehow, if we know what you are working towards and which design and work items you are having in mind?

Sure.

Step zero was a series of refactorings and cleanups around stardoc_output.proto, which was finished by mid-May.

Step one was adding a way to represent the syntactic role of function params (fixed by bd1c3af) so that a documentation renderer can output *args, *, and **kwargs correctly in all cases.

Steps two and three will be to represent 2 additional bits of data in stardoc_output.proto:

I hope get this done in early July.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

Thanks for the update and the rough timeline!

Are the remaining steps 2 and 3 all that's left to be done?

Afaik, there is currently no way to dump Bazel's builtin functions, yet. From the Stardoc documentation, my understanding is that it is only possible to run stardoc on Starlark files? But Bazel's builtins are not all migrated to Starlark, and some of them probably never will.

Is there still some additional command (e.g., bazel info builtin-symbols-as-proto, similar to bazelbuild#21936) missing? Or is this also covered by bazelbuild#21979?

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.

Hello @arvi18, 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!

Summary of Changes

This pull request focuses on enhancing the builtin.proto to include Bzlmod globals, specifically those available in MODULE.bazel files. This is achieved by adding a new ApiContext called MODULE. Additionally, the PR incorporates ApiContext.BZL globals for repository rule and module extension definitions. A new smoke test is introduced to verify that common symbols are present in the proto for each API context. This work is related to addressing issue bazel-contrib/vscode-bazel#1.

Highlights

  • ApiContext Enhancement: A new ApiContext.MODULE is added to builtin.proto to represent globals available in MODULE.bazel files. This is reflected in src/main/protobuf/builtin.proto by adding MODULE = 3; to the ApiContext enum.
  • Bzlmod Globals Inclusion: The changes in src/main/java/com/google/devtools/build/docgen/ApiExporter.java and src/main/java/com/google/devtools/build/docgen/SymbolFamilies.java ensure that globals specific to MODULE.bazel files are included when generating the builtin.proto. This involves adding a call to appendGlobals with ApiContext.MODULE and collecting module file globals.
  • Smoke Test Implementation: A new smoke test, BuiltinProtoSmokeTest.java, is added to verify the presence of common symbols in the generated builtin.proto for different API contexts. This test ensures that essential symbols like bazel_dep are correctly documented under the MODULE context.
  • Dependency Injection: The BUILD file in src/main/java/com/google/devtools/build/docgen/BUILD is updated to include //src/main/java/com/google/devtools/build/lib/bazel/bzlmod:resolution as a runtime dependency for the ApiExporter.

Changelog

Click here to see the changelog
  • src/main/java/com/google/devtools/build/docgen/ApiExporter.java
    • Added logic to append globals specifically for the MODULE ApiContext.
    • Modified to include module file globals when writing builtins.
  • src/main/java/com/google/devtools/build/docgen/BUILD
    • Added //src/main/java/com/google/devtools/build/lib/bazel/bzlmod:resolution as a runtime dependency.
  • src/main/java/com/google/devtools/build/docgen/SymbolFamilies.java
    • Added FakeRepositoryModule import.
    • Added moduleFileGlobals field to store globals available in MODULE.bazel files.
    • Modified constructor to collect module file globals.
    • Added getter method for moduleFileGlobals.
    • Modified collectBzlGlobals to add methods from FakeRepositoryModule.
    • Added collectModuleFileGlobals method to collect globals specifically for MODULE.bazel files.
  • src/main/protobuf/builtin.proto
    • Added MODULE enum value to the ApiContext enum.
  • src/test/java/com/google/devtools/build/lib/BUILD
    • Added BuiltinProtoSmokeTest java test target.
  • src/test/java/com/google/devtools/build/lib/BuiltinProtoSmokeTest.java
    • Created a new smoke test to verify the presence of common symbols in the generated builtin.proto for different API contexts.
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.


In Bzlmod's realm, a module's call,
Globals defined, embracing all.
From proto's core,
New contexts soar,
Bazel's extension, standing tall.

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

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

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.

2 participants