Skip to content

fix(grit): biome native node field names now work#9739

Open
dyc3 wants to merge 1 commit intomainfrom
dyc3/grit-native-node-field-names
Open

fix(grit): biome native node field names now work#9739
dyc3 wants to merge 1 commit intomainfrom
dyc3/grit-native-node-field-names

Conversation

@dyc3
Copy link
Copy Markdown
Contributor

@dyc3 dyc3 commented Mar 30, 2026

Summary

This makes it so that users can use our field names in grit queries for things like:

JsConditionalExpression(
  consequent = $cons,
  alternate = $alt
)

generated by gpt 5.4, but had a really hard time wrangling the agent for this because its more of an added feature rather than a fix.

Essentially, we now grab the AstSrc from the parsed .ungram file to generate the metadata.

#9734 brought it to my attention.

Test Plan

added snapshot tests

Docs

biomejs/website#4129

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 30, 2026

🦋 Changeset detected

Latest commit: 5f77a1f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Tooling Area: internal tools L-Grit Language: GritQL labels Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 53145 53145 0
Passed 51925 51925 0
Failed 1178 1178 0
Panics 42 42 0
Coverage 97.70% 97.70% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 38 38 0
Passed 37 37 0
Failed 1 1 0
Panics 0 0 0
Coverage 97.37% 97.37% 0.00%

markdown/commonmark

Test result main count This PR count Difference
Total 652 652 0
Passed 652 652 0
Failed 0 0 0
Panics 0 0 0
Coverage 100.00% 100.00% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5467 5467 0
Passed 1915 1915 0
Failed 3552 3552 0
Panics 0 0 0
Coverage 35.03% 35.03% 0.00%

ts/babel

Test result main count This PR count Difference
Total 640 640 0
Passed 569 569 0
Failed 71 71 0
Panics 0 0 0
Coverage 88.91% 88.91% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18876 18876 0
Passed 13014 13014 0
Failed 5861 5861 0
Panics 1 1 0
Coverage 68.94% 68.94% 0.00%

@dyc3 dyc3 force-pushed the dyc3/grit-native-node-field-names branch from 4c0e707 to da741be Compare March 30, 2026 21:56
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 30, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks
⏩ 247 skipped benchmarks1


Comparing dyc3/grit-native-node-field-names (5f77a1f) with main (878c476)2

Open in CodSpeed

Footnotes

  1. 247 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (d5ca672) during the generation of this report, so 878c476 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@dyc3 dyc3 force-pushed the dyc3/grit-native-node-field-names branch 2 times, most recently from dfbfc4e to 4ab3417 Compare March 31, 2026 00:19
@dyc3
Copy link
Copy Markdown
Contributor Author

dyc3 commented Mar 31, 2026

cc @arendjr was this intended to be implemented originally?

@dyc3 dyc3 marked this pull request as ready for review March 31, 2026 14:33
@dyc3 dyc3 requested review from a team March 31, 2026 14:33
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR separates legacy Tree‑sitter and native Biome node-name resolution for Grit patterns. It adds a public GritNodePatternSource enum and GritTargetLanguage::resolve_node_pattern_name returning (kind, source), splits generated mapping outputs into legacy_kind_by_name, native_kind_by_name and native_slots_for_name, updates target-language implementations and codegen to be node/source-aware, refactors the pattern compiler to use trimmed token names and the new resolve API, and adds multiple grit/css/ts/tsx test fixtures exercising mixed legacy/native patterns.

Possibly related PRs

Suggested reviewers

  • ematipico
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly describes the main change: enabling native Biome node field names in grit queries, which is the core objective of this changeset.
Description check ✅ Passed The PR description clearly explains the motivation (enabling native field names in grit queries), provides concrete examples, and references related issues.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dyc3/grit-native-node-field-names

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/biome_grit_patterns/src/grit_target_language/json_target_language.rs (1)

59-69: ⚠️ Potential issue | 🟠 Major

Add native slot support for JSON to match JS/CSS architecture.

The source parameter is ignored, and this always returns legacy TreeSitter slots. Unlike JS and CSS implementations, there's no routing to native_slots_for_name(node_name) when source == Native.

Critically, JSON's native patterns like JsonMemberName, JsonMemberList, and JsonArrayElementList have no legacy TreeSitter equivalents, so they silently return empty slots. This prevents named field matching for native JSON patterns and creates an architectural inconsistency—JS and CSS both properly route based on source; JSON should too.

To fix this, you'll need to generate native_slots_for_name in the JSON generated mappings and update named_slots_for_node to route based on the source parameter.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_grit_patterns/src/grit_target_language/json_target_language.rs`
around lines 59 - 69, The current named_slots_for_node implementation always
returns legacy_treesitter_slots_for_kind and ignores the _source parameter,
which prevents native JSON patterns from returning slots; update
named_slots_for_node (in json_target_language.rs) to match the JS/CSS pattern:
check kind.as_json_kind(), then match on the provided source
(GritNodePatternSource) and, when source == Native, call
native_slots_for_name(node_name) (ensure native_slots_for_name is generated into
the JSON mappings), otherwise fall back to
legacy_treesitter_slots_for_kind(kind); this will expose native slots for
JsonMemberName/JsonMemberList/JsonArrayElementList and keep legacy behavior for
TreeSitter source.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/thirty-lines-sit.md:
- Line 5: Update the changeset description to include the GitHub issue reference
at the start using the required format: prefix the existing line "Fixed Grit
queries that use native Biome AST node names with native field names. Queries
such as `JsConditionalExpression(consequent = $cons, alternate = $alt)` now
compile successfully in `biome search`." with "Fixed
[`#9734`](https://github.com/biomejs/biome/issues/9734):" so the final description
begins "Fixed [`#9734`](https://github.com/biomejs/biome/issues/9734): Fixed Grit
queries..." ensuring the issue number and link are present as per guidelines.

---

Outside diff comments:
In `@crates/biome_grit_patterns/src/grit_target_language/json_target_language.rs`:
- Around line 59-69: The current named_slots_for_node implementation always
returns legacy_treesitter_slots_for_kind and ignores the _source parameter,
which prevents native JSON patterns from returning slots; update
named_slots_for_node (in json_target_language.rs) to match the JS/CSS pattern:
check kind.as_json_kind(), then match on the provided source
(GritNodePatternSource) and, when source == Native, call
native_slots_for_name(node_name) (ensure native_slots_for_name is generated into
the JSON mappings), otherwise fall back to
legacy_treesitter_slots_for_kind(kind); this will expose native slots for
JsonMemberName/JsonMemberList/JsonArrayElementList and keep legacy behavior for
TreeSitter source.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 06559229-fa55-45b3-90c4-fcf9c9dde786

📥 Commits

Reviewing files that changed from the base of the PR and between 2d3f143 and 4ab3417.

⛔ Files ignored due to path filters (11)
  • crates/biome_grit_patterns/tests/specs/css/declaration_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/css/function_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/css/native_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/css/selector_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/if_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/legacy_conditional_slots.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/member_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/mixed_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/native_slot_aliases.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/while_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/tsx/jsx_attribute_slot_names.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (32)
  • .changeset/thirty-lines-sit.md
  • .claude/skills/changeset/SKILL.md
  • crates/biome_grit_patterns/src/grit_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/css_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/css_target_language/generated_mappings.rs
  • crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/js_target_language/generated_mappings.rs
  • crates/biome_grit_patterns/src/grit_target_language/json_target_language.rs
  • crates/biome_grit_patterns/src/pattern_compiler/node_like_compiler.rs
  • crates/biome_grit_patterns/tests/specs/css/declaration_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/declaration_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/css/function_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/function_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/css/native_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/native_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/css/selector_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/selector_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/if_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/if_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/ts/legacy_conditional_slots.grit
  • crates/biome_grit_patterns/tests/specs/ts/legacy_conditional_slots.ts
  • crates/biome_grit_patterns/tests/specs/ts/member_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/member_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/ts/mixed_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/mixed_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/ts/native_slot_aliases.grit
  • crates/biome_grit_patterns/tests/specs/ts/native_slot_aliases.ts
  • crates/biome_grit_patterns/tests/specs/ts/while_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/while_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/tsx/jsx_attribute_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/tsx/jsx_attribute_slot_names.tsx
  • xtask/codegen/src/generate_grit_mappings.rs

@arendjr
Copy link
Copy Markdown
Contributor

arendjr commented Apr 1, 2026

@dyc3 yeah, this was intended.

I prefer not to review AI generated PRs though, so I hope you can finish this one without my involvement.

@dyc3 dyc3 force-pushed the dyc3/grit-native-node-field-names branch from 4ab3417 to aea0fef Compare April 4, 2026 17:53
@github-actions github-actions bot added the A-Project Area: project label Apr 4, 2026
Copy link
Copy Markdown
Contributor

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
xtask/codegen/src/generate_grit_mappings.rs (1)

118-159: ⚠️ Potential issue | 🟠 Major

Teach codegen about the JSON aliases before xtask bins them.

crates/biome_grit_patterns/src/grit_target_language/json_target_language/generated_mappings.rs Lines 95-107 now accept aliases such as json_root, json_member_name, and key, but this generator can only emit one name per TreeSitterPattern. The next regeneration will drop those arms and quietly regress JSON queries. Please encode aliases in the generator so the generated file stays reproducible.

💡 Sketch
 struct TreeSitterPattern {
     name: &'static str,
+    aliases: &'static [&'static str],
     biome_kind: &'static str,
     slots: &'static [(&'static str, u32)],
 }

-                .map(|p| {
-                    format!(
-                        r#"        "{}" => Some({syntax_kind_type}::{}),"#,
-                        p.name,
-                        p.biome_kind,
-                        syntax_kind_type = lang.syntax_kind_type
-                    )
-                })
+                .flat_map(|p| {
+                    std::iter::once(p.name)
+                        .chain(p.aliases.iter().copied())
+                        .map(move |name| {
+                            format!(
+                                r#"        "{}" => Some({syntax_kind_type}::{}),"#,
+                                name,
+                                p.biome_kind,
+                                syntax_kind_type = lang.syntax_kind_type
+                            )
+                        })
+                })

Then add the JSON aliases to JSON_TREESITTER_PATTERNS — including a JSON_MEMBER_NAME entry for property_name / key.

Also applies to: 251-255, 405-451

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@xtask/codegen/src/generate_grit_mappings.rs` around lines 118 - 159, The
generator currently emits only a single name per TreeSitterPattern which drops
JSON aliases (e.g., json_root, json_member_name, key) and causes
non-reproducible generated_mappings.rs; update the code that builds
legacy_kind_mappings / legacy_kind_by_name so it iterates over all alias names
for each pattern (not just p.name) and emits a match arm for each alias, and
also update the JSON source data used by the generator (JSON_TREESITTER_PATTERNS
and add JSON_MEMBER_NAME entries) so the aliases (property_name/key, json_root,
json_member_name, etc.) are present for generation; locate and change the
mapping construction in generate_grit_mappings.rs (symbols legacy_kind_mappings
and legacy_kind_by_name) to loop through pattern.aliases (or the equivalent
field) and format a separate '"alias" =>
Some({syntax_kind_type}::{biome_kind}),' arm for each alias.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@xtask/codegen/src/generate_grit_mappings.rs`:
- Around line 118-159: The generator currently emits only a single name per
TreeSitterPattern which drops JSON aliases (e.g., json_root, json_member_name,
key) and causes non-reproducible generated_mappings.rs; update the code that
builds legacy_kind_mappings / legacy_kind_by_name so it iterates over all alias
names for each pattern (not just p.name) and emits a match arm for each alias,
and also update the JSON source data used by the generator
(JSON_TREESITTER_PATTERNS and add JSON_MEMBER_NAME entries) so the aliases
(property_name/key, json_root, json_member_name, etc.) are present for
generation; locate and change the mapping construction in
generate_grit_mappings.rs (symbols legacy_kind_mappings and legacy_kind_by_name)
to loop through pattern.aliases (or the equivalent field) and format a separate
'"alias" => Some({syntax_kind_type}::{biome_kind}),' arm for each alias.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be573e67-9b19-4a99-b1ee-899faca5776c

📥 Commits

Reviewing files that changed from the base of the PR and between 4ab3417 and aea0fef.

⛔ Files ignored due to path filters (11)
  • crates/biome_grit_patterns/tests/specs/css/declaration_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/css/function_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/css/native_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/css/selector_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/if_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/legacy_conditional_slots.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/member_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/mixed_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/native_slot_aliases.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/ts/while_slot_names.snap is excluded by !**/*.snap and included by **
  • crates/biome_grit_patterns/tests/specs/tsx/jsx_attribute_slot_names.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (33)
  • .changeset/thirty-lines-sit.md
  • .claude/skills/changeset/SKILL.md
  • crates/biome_grit_patterns/src/grit_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/css_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/css_target_language/generated_mappings.rs
  • crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/js_target_language/generated_mappings.rs
  • crates/biome_grit_patterns/src/grit_target_language/json_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/json_target_language/generated_mappings.rs
  • crates/biome_grit_patterns/src/pattern_compiler/node_like_compiler.rs
  • crates/biome_grit_patterns/tests/specs/css/declaration_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/declaration_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/css/function_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/function_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/css/native_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/native_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/css/selector_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/selector_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/if_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/if_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/ts/legacy_conditional_slots.grit
  • crates/biome_grit_patterns/tests/specs/ts/legacy_conditional_slots.ts
  • crates/biome_grit_patterns/tests/specs/ts/member_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/member_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/ts/mixed_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/mixed_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/ts/native_slot_aliases.grit
  • crates/biome_grit_patterns/tests/specs/ts/native_slot_aliases.ts
  • crates/biome_grit_patterns/tests/specs/ts/while_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/while_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/tsx/jsx_attribute_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/tsx/jsx_attribute_slot_names.tsx
  • xtask/codegen/src/generate_grit_mappings.rs
✅ Files skipped from review due to trivial changes (24)
  • crates/biome_grit_patterns/tests/specs/ts/legacy_conditional_slots.grit
  • crates/biome_grit_patterns/tests/specs/ts/native_slot_aliases.ts
  • crates/biome_grit_patterns/tests/specs/ts/if_slot_names.ts
  • .claude/skills/changeset/SKILL.md
  • crates/biome_grit_patterns/tests/specs/css/function_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/selector_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/css/selector_slot_names.css
  • crates/biome_grit_patterns/tests/specs/css/native_slot_names.css
  • crates/biome_grit_patterns/tests/specs/ts/member_slot_names.ts
  • .changeset/thirty-lines-sit.md
  • crates/biome_grit_patterns/tests/specs/css/function_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/native_slot_aliases.grit
  • crates/biome_grit_patterns/tests/specs/ts/member_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/css/declaration_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/while_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/css/declaration_slot_names.css
  • crates/biome_grit_patterns/tests/specs/ts/legacy_conditional_slots.ts
  • crates/biome_grit_patterns/tests/specs/ts/mixed_slot_names.ts
  • crates/biome_grit_patterns/tests/specs/ts/if_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/tsx/jsx_attribute_slot_names.tsx
  • crates/biome_grit_patterns/tests/specs/css/native_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/tsx/jsx_attribute_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/mixed_slot_names.grit
  • crates/biome_grit_patterns/tests/specs/ts/while_slot_names.grit
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/biome_grit_patterns/src/grit_target_language/css_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/json_target_language.rs
  • crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs

@dyc3 dyc3 force-pushed the dyc3/grit-native-node-field-names branch from dd3beb2 to 80e2dfe Compare April 4, 2026 18:11
@github-actions github-actions bot removed the A-Project Area: project label Apr 4, 2026
@dyc3 dyc3 force-pushed the dyc3/grit-native-node-field-names branch from 80e2dfe to 1eca78b Compare April 4, 2026 18:16
@github-actions github-actions bot added the A-Project Area: project label Apr 4, 2026
Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

This doesn't feel like a bug fix. This PR unblocks new things that users weren't able able to do before.

It needs a more descriptive changeset. This doesn't affect only the search command, but plugins too. Also, we need to update the documentation, and provide new examples.

Ironically, the changset mentions the search command, but no tests were added. We need tests for it too.

/// Returns the native Biome slot mappings for a node name.
pub fn native_slots_for_name(node_name: &str) -> &'static [(&'static str, u32)] {
match node_name {
"CssAtRule" => &[("rule", 1)],
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.

Can you point to me where the indexes are used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Essentially, it eventually gets wired into GritNodePatternArg::new(slot_index, pattern).

args.push(GritNodePatternArg::new(slot_index, pattern));

My understanding is that every node has slots, and some of them can be replaced with grit metavariables. During execution the index is used to look up which child is being referenced.

match node.child_by_slot_index(*slot_index) {

@dyc3
Copy link
Copy Markdown
Contributor Author

dyc3 commented Apr 6, 2026

This doesn't feel like a bug fix.

While I somewhat agree, we tell our users to refer to the .ungram file for node names and their parameters. One could argue that we already advertise this fix as a feature, and it not working is a bug. Being able to use Biome's node names but not Biome's field names is a confusing inconsistency. That's why I want to land this as a patch.

no tests were added

There are plenty of snapshot tests that prove these new queries can compile and execute. I can have the agent make more snapshot tests for this, but it's probably going to be low signal. Are you saying we need cli tests? We already know the plumbing of search and plugins works.

@dyc3 dyc3 force-pushed the dyc3/grit-native-node-field-names branch from db9cdbb to 330c6b5 Compare April 6, 2026 13:19
@github-actions github-actions bot removed the A-Project Area: project label Apr 6, 2026
@ematipico
Copy link
Copy Markdown
Member

Are you saying we need cli tests?

Yes, at least one so that we prove that the diagnostics correctly map to the new nodes.

As for the entity of the change: that's fine, but I hope you agree with me that we need new docs, since we're enabling new queries that before weren't possible. There's little to no value saying "we fixed this bug" in the changset without properly showing what users can do. And that's why, to me is a new feature.

However, I don't want to rush this PR as a patch without proper docs.

@dyc3
Copy link
Copy Markdown
Contributor Author

dyc3 commented Apr 6, 2026

Yup, agree completely. I'll have a docs pr up soon.

@dyc3
Copy link
Copy Markdown
Contributor Author

dyc3 commented Apr 6, 2026

done biomejs/website#4129

@dyc3 dyc3 force-pushed the dyc3/grit-native-node-field-names branch from 330c6b5 to 5f77a1f Compare April 6, 2026 16:18
@github-actions github-actions bot added the A-CLI Area: CLI label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Tooling Area: internal tools L-Grit Language: GritQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants