Skip to content

feat(rbs): Add highlight rules for inline annotations#262

Open
hakanensari wants to merge 1 commit intozed-extensions:mainfrom
hakanensari:rbs-inline-highlights
Open

feat(rbs): Add highlight rules for inline annotations#262
hakanensari wants to merge 1 commit intozed-extensions:mainfrom
hakanensari:rbs-inline-highlights

Conversation

@hakanensari
Copy link

@hakanensari hakanensari commented Mar 6, 2026

Summary

  • Add missing highlight rules from upstream tree-sitter-rbs for RBS inline annotations (#: and # @rbs comments)
  • Highlights generic modifiers (unchecked, out, in), unnamed parameters, inline keywords (inherits, generic, override, skip), doc comments, and operators (?, *, **, &)
  • All capture names follow existing conventions in the file

Test plan

  • cargo test passes (60 tests, no changes to test fixtures)
  • Manually verify RBS inline annotation highlighting in Zed

Add highlight rules from upstream tree-sitter-rbs for:
- Generic modifiers (unchecked, out, in)
- Unnamed parameters
- Inline annotation keywords (inherits, generic, override, skip)
- Inline doc comments and parameter names
- Missing operators (?, *, **, &)
Copilot AI review requested due to automatic review settings March 6, 2026 10:30
@cla-bot cla-bot bot added the cla-signed label Mar 6, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds missing Tree-sitter highlight query rules for RBS inline annotation syntax (e.g., #: / # @rbs) to improve highlighting when RBS is injected into Ruby comments.

Changes:

  • Add highlight captures for generics-related keywords/modifiers and unnamed parameters.
  • Extend operator highlighting to cover additional inline-annotation operator forms.
  • Add highlight captures for inline annotation keywords and inline doc comment structures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +110 to +115
; Generics Keywords
[
(generics_unchecked)
(generics_variance)
] @keyword

Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

There are snapshot-based query tests for Ruby/ERB, but none for RBS. As a result, these new RBS highlight patterns (e.g., generics_unchecked, inline_*, and the operator nodes) are not validated by cargo test, so a node-name mismatch with the pinned tree-sitter-rbs grammar could ship and break RBS highlighting/injections at runtime. Consider adding an RBS query snapshot test by wiring rbs into tests/support/language_for_id (and adding tree-sitter-rbs as a dev-dependency) plus a small tests/languages/rbs fixture that exercises the inline annotation syntax.

Copilot uses AI. Check for mistakes.
@hakanensari
Copy link
Author

I'm not a big fan of syntax-highlighting inline rbs because it makes the code arguably less readable, but this pr at least fills gaps in the existing highlight queries and makes things more consistent.

Here's a before and after.

1-inline-rbs-before 2-inline-rbs-after

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants