Skip to content

Commit

Permalink
fix(treesitter): JSX/TSX tags are missing highlights
Browse files Browse the repository at this point in the history
Fixes: #360
  • Loading branch information
tmillr committed Aug 7, 2024
1 parent 6025b63 commit 46c8c80
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic

## [unreleased]

### Issues Fix

- Fixed JSX/TSX tags are missing highlights with nvim 0.10 (#360)

## [v1.1.2] - 05 August 2024

_This release contains a crucial ***hotfix*** for a bug that prevented the ability to
Expand Down
5 changes: 3 additions & 2 deletions lua/github-theme/group/modules/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ If you want to stay on nvim 0.7, disable the module, or track on 'v0.0.x' branch
--- XML Tags -----------------------------------------------------------------------------

['@tag'] = { fg = syn.tag }, -- Tags like HTML tag names
['@tag.builtin'] = { link = '@tag' }, -- Tags, but only non-user-defined ones (e.g. `<a>`)
['@tag.attribute'] = { link = '@variable.member' }, -- Tag attributes (e.g. HTML element attributes)
['@tag.delimiter'] = FALLBACK_OR_NONE, -- Tag delimiter like `<`, `>`, `/`, etc.

Expand Down Expand Up @@ -252,8 +253,8 @@ If you want to stay on nvim 0.7, disable the module, or track on 'v0.0.x' branch
-- ['@variable.javascript'] = { link = '@constant' },

-- JSX/TSX
['@tag.javascript'] = FALLBACK_OR_NONE,
['@tag.tsx'] = FALLBACK_OR_NONE,
['@tag.javascript'] = { link = '@type.javascript' },
['@tag.tsx'] = { link = '@type.tsx' },
['@tag.delimiter.javascript'] = { link = '@tag.attribute.javascript' },
['@tag.delimiter.tsx'] = { link = '@tag.attribute.tsx' },

Expand Down
22 changes: 22 additions & 0 deletions queries/ecma/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
;; extends

; These fix an nvim-treesitter bug where the `Abc` in `Abc.Xyz` is captured as a
; builtin tag. They also change the capture for `Xyz` to `@variable.member`
; instead of e.g. `@tag` (which gives the property a different color).
(jsx_opening_element
name: (member_expression
; If the tag name contains a dot (operator), it must always be a custom
; tag? Therefore, we're not even going to try matching a `@tag.builtin`
; here.
object: (identifier) @tag (#set! "priority" 115)
property: (property_identifier) @variable.member (#set! "priority" 115)))

(jsx_closing_element
name: (member_expression
object: (identifier) @tag (#set! "priority" 115)
property: (property_identifier) @variable.member (#set! "priority" 115)))

(jsx_self_closing_element
name: (member_expression
object: (identifier) @tag (#set! "priority" 115)
property: (property_identifier) @variable.member (#set! "priority" 115)))

0 comments on commit 46c8c80

Please sign in to comment.