feat: Map BUILD to Python (Starlark) for Bazel (fixes #3575)#3576
feat: Map BUILD to Python (Starlark) for Bazel (fixes #3575)#3576vorburger wants to merge 2 commits intosharkdp:masterfrom
Conversation
|
Re. 2 failing checks, let me add a line to But that "[Minimum supported rust version" failure must be unrelated to this PR. |
There was a problem hiding this comment.
Pull request overview
This pull request adds a syntax mapping for Bazel BUILD files to be highlighted as Python (Starlark), addressing issue #3575. The change adds a new configuration file that maps the filename "BUILD" to Python syntax highlighting.
Changes:
- Added
50-bazel.tomlconfiguration file to map BUILD files to Python syntax
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,2 @@ | |||
| [mappings] | |||
| "Python" = ["BUILD"] | |||
There was a problem hiding this comment.
This change will break the existing test 'syntax_detection_first_line' in src/assets.rs:540-541. The test expects files named "build" (lowercase) with a bash shebang to use first-line fallback detection and be identified as "Bourne Again Shell (bash)". However, with this mapping, "build" will match the case-insensitive "BUILD" pattern and be mapped to Python, preventing first-line fallback and causing the test to fail.
| "Python" = ["BUILD"] | |
| # Intentionally no mapping for bare "BUILD" to avoid conflicting with | |
| # first-line fallback detection for lowercase "build" files. |
| @@ -0,0 +1,2 @@ | |||
| [mappings] | |||
| "Python" = ["BUILD"] | |||
There was a problem hiding this comment.
No test coverage has been added for the new BUILD file mapping. Consider adding a test case to src/assets.rs in the syntax_detection_basic test function, similar to the existing tests for other filename mappings like PKGBUILD and Makefile. For example: assert_eq!(test.syntax_for_file("BUILD"), "Python");
| @@ -0,0 +1,2 @@ | |||
| [mappings] | |||
| "Python" = ["BUILD"] | |||
There was a problem hiding this comment.
The pattern "BUILD" will match files named "build" (lowercase) due to case-insensitive glob matching (see src/syntax_mapping.rs:22). This overrides the existing mapping in 99-unset-ambiguous-filenames.toml that intentionally maps "build" to MapToUnknown to prevent incorrect syntax detection for NAnt Build Files. This breaks existing behavior.
Since Bazel BUILD files are typically uppercase, consider either:
- Finding a way to make this mapping case-sensitive (would require code changes to the make_glob_matcher function)
- Documenting this as a known limitation and accepting that lowercase "build" files will now be treated as Python
- Not adding this mapping and relying on users to configure it manually via --map-syntax if needed
The issue noted in 99-unset-ambiguous-filenames.toml is that "NAnt Build File" should only match *.build files (with extension), not files named "build" (no extension). This PR's case-insensitive "BUILD" pattern will cause lowercase "build" files to be mapped to Python instead of remaining as MapToUnknown.
| "Python" = ["BUILD"] |
|
@keith-hall hm, is Copilot right about the case sensitivity? Given the test failures, I guess this would need more work. My time is limited and my Rust is too rusty to implement that... BTW see #3577. Also, would you want to see a test, to accept merging this? |
|
Yep, looks like Copilot is correct about the case-insensitivity, which is indeed why the tests are failing. Hmm, yeah I guess we need to introduce a way to map a filename case sensitively to proceed further. As for tests, a simple test case like Copilot suggested at #3576 (comment) would suffice, if all the existing tests continue to pass unmodified. |
@keith-hall like this, for #3575 ?
Full disclosure: I have NOT actually tested this... as in, for #3575 I HAVE tested
bat --map-syntax='BUILD:Python' BUILDlocally on a pre-built binary, and looking around https://github.com/sharkdp/bat/tree/master/src/syntax_mapping/builtins/common I kinda gathered that's what you meant with your comment in #3575 - but I haven't actually rebuiltbatwith this... but it looks about right (I hope).