Skip to content

diffs: add starlark file extensions#1012

Open
lf- wants to merge 1 commit into
pierrecomputer:mainfrom
lf-:jade/push-xmxpopxxynoq
Open

diffs: add starlark file extensions#1012
lf- wants to merge 1 commit into
pierrecomputer:mainfrom
lf-:jade/push-xmxpopxxynoq

Conversation

@lf-

@lf- lf- commented Jul 21, 2026

Copy link
Copy Markdown

If shiki ever grows Starlark support, this should be revised to use that starlark support, but Starlark is a strict subset of Python anyway.

ref for the file extensions:
https://bazel.build/concepts/build-ref
https://buck2.build/docs/rule_authors/package_files/
https://buck2.build/docs/bxl/

Description

Add support for highlighting Starlark files like those from Bazel/Buck2/Copybara.

Motivation & Context

I like my diffs for my build files to be readable.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality). You must have
    first discussed with the dev team and they should be aware that this PR is
    being opened
  • Breaking change (fix or feature that would change existing functionality).
    You must have first discussed with the dev team and they should be aware
    that this PR is being opened
  • Documentation update

Checklist

  • I have read the
    contributing guidelines
  • My code follows the code style of the project (moon run root:lint)
  • My code is formatted properly (moon run root:format)
  • I have updated the documentation accordingly (if applicable)
  • I have added tests to cover my changes (if applicable)
  • All new and existing tests pass (moonx diffs:test)

How was AI used in generating this PR

wrote this with claude then realized it was all out of order and redid it by hand lmao

Related issues

If shiki ever grows Starlark support, this should be revised to use that
starlark support, but Starlark is a strict subset of Python anyway.

ref:
https://bazel.build/concepts/build-ref
https://buck2.build/docs/rule_authors/package_files/
https://buck2.build/docs/bxl/
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

@lf- is attempting to deploy a commit to the Pierre Computer Company Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ddee11dd01

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jul 21, 2026 12:59am
pierre-docs-diffshub Ready Ready Preview Jul 21, 2026 12:59am
pierre-docs-trees Ready Ready Preview Jul 21, 2026 12:59am
pierrejs-diff-demo Ready Ready Preview Jul 21, 2026 12:59am

Request Review

@amadeus

amadeus commented Jul 21, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ddee11dd01

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// appears in shiki. For now, Starlark is highlighted like the Python subset
// it is.
BUCK: 'python',
BUILD: 'python',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle nested Starlark filenames

When a Bazel/Buck file is not at the repository root, this exact-filename entry is never used: parsed diffs keep directory prefixes (for example packages/diffs tests snapshot names like packages/diffs/src/index.ts), and getFiletypeFromFileName only checks EXTENSION_TO_FILE_FORMAT[fileName] before falling back to extensions. As a result getFiletypeFromFileName('src/BUILD') and getFiletypeFromFileName('foo/BUCK') still return text, so the common nested package files this change is trying to support won't be highlighted unless they use .bazel/.bzl.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah this issue is due to my laziness around our file name detection (i.e. i need to probably extend this to properly test the filename), but probably shouldn't be apart of this PR.

// appears in shiki. For now, Starlark is highlighted like the Python subset
// it is.
BUCK: 'python',
BUILD: 'python',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah this issue is due to my laziness around our file name detection (i.e. i need to probably extend this to properly test the filename), but probably shouldn't be apart of this PR.

BUILD: 'python',
MODULE: 'python',
PACKAGE: 'python',
WORKSPACE: 'python',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bit worried about including

BUILD, MODULE, and PACKAGE, since those feel pretty generic. The other ones definitely seem bazel related. What do you think about removing those three since there's a custom API you can use to extend for the more ambiguous ones?

Another possibility might be to say, what if we just remove all of these direct filenames, until i can improve that part of the system to properly track BUCK files in a sub directory?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Some thoughts:

Bazel is super popular, so BUILD is most likely always going to be Bazel, and false positives are probably worth the benefit for these vs the possibility to have a false positive. Approximately one MODULE file appears in a Bazel repo; so it's lower value compared to BUILD.

PACKAGE is a buck specific thing and is, of the options, the least credible just given that Buck is a lot less popular than Bazel (c.f. the time i tried to add it to linguist lmao). This is the one I would put into consumers rather than the defaults; I guess the other thought I have is that the consumers could override the decision if they don't like the defaults for BUILD or similar.

It's definitely worth distinguishing direct filenames from extensions in the recognizer.

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