Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree-sitter rolling fixes, 1.118 edition #1010

Merged
28 changes: 25 additions & 3 deletions packages/language-javascript/grammars/tree-sitter/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
; MISC
; ====

; In the JSX construct `<FOO.Bar>`, `FOO` should not be marked as
; `constant.other.js`. Block off identifiers within complex JSX tag names early
; to prevent this.

(jsx_opening_element
(member_expression
(identifier) @_IGNORE_
(#set! capture.final)))

(jsx_closing_element
(member_expression
(identifier) @_IGNORE_
(#set! capture.final)))

(jsx_self_closing_element
(member_expression
(identifier) @_IGNORE_
(#set! capture.final)))


; STRINGS
; =======
Expand Down Expand Up @@ -775,16 +797,16 @@

; The "Foo" in `<Foo />`.
(jsx_self_closing_element
name: (identifier) @entity.name.tag.js
name: (_) @entity.name.tag.js
) @meta.tag.jsx.js

; The "Foo" in `<Foo>`.
(jsx_opening_element
name: (identifier) @entity.name.tag.js)
name: (_) @entity.name.tag.js)

; The "Foo" in `</Foo>`.
(jsx_closing_element
name: (identifier) @entity.name.tag.js)
name: (_) @entity.name.tag.js)

; The "bar" in `<Foo bar={true} />`.
(jsx_attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ treeSitter:
languageSegment: 'ts.tsx'
grammar: 'tree-sitter-tsx/tree-sitter-tsx.wasm'
highlightsQuery: [
'common/highlights.scm'
'tree-sitter-tsx/highlights.scm'
'common/highlights.scm'
Comment on lines -17 to +18
Copy link
Member

Choose a reason for hiding this comment

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

Is this change meaningful?

Any insights into the purpose of it if so? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Order matters here. The contents of each file is concatenated into one query file, and earlier queries are matched before later queries.

I needed a few JSX-specific rules to act before the ordinary rules in highlights.scm — the “Block off identifiers within complex JSX tag names…” stuff matches some things so that it can prevent them from being matched by a later rule.

In this instance, it didn't otherwise matter which query file was included first. But if it had, I'd have needed to create a third file, put only those rules into it, and configure it to be included first.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, that's a pretty useful and practical explanation, with the examples.

]
indentsQuery: [
'common/indents.scm'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
; MISC
; ====

; In the JSX construct `<FOO.Bar>`, `FOO` should not be marked as
; `constant.other.ts.tsx`. Block off identifiers within complex JSX tag names
; early to prevent this.

(jsx_opening_element
(nested_identifier
(identifier) @_IGNORE_
(#set! capture.final)))

(jsx_closing_element
(nested_identifier
(identifier) @_IGNORE_
(#set! capture.final)))

(jsx_self_closing_element
(nested_identifier
(identifier) @_IGNORE_
(#set! capture.final)))

; JSX
; ===

; The "Foo" in `<Foo />`.
(jsx_self_closing_element
name: (identifier) @entity.name.tag.ts.tsx
name: (_) @entity.name.tag.ts.tsx
) @meta.tag.ts.tsx

; The "Foo" in `<Foo>`.
Expand Down