Skip to content

Commit

Permalink
fix(topiary-queries/scm): Fixed invalid formatting of `field_definiti…
Browse files Browse the repository at this point in the history
…on`s (#826)

* tree_sitter_query changes:
* prevent invalid formatting of `field_definition` that followed an
  `identifier`
* `predicates` parameters are now separated by a `spaced_softline`
  allowing long predicates to be broken up

* added to changelog

* Update CHANGELOG.md

Co-authored-by: Christopher Harrison <[email protected]>

* handle indentation of predicate parameters

* fixup expected header

* handle predicate_type spacing

* Update CHANGELOG.md

* PR feedback addressed on multi tag predicate scenario

* fix(query/scm): removed append_space after predicate type

---------

Co-authored-by: Christopher Harrison <[email protected]>
  • Loading branch information
mkatychev and Xophmeister authored Jan 16, 2025
1 parent 26014e1 commit 2170fa7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ This name should be decided amongst the team before the release.
### Fixed
- [#779](https://github.com/tweag/topiary/pull/779) Load relevant grammars before CLI tests
- [#799](https://github.com/tweag/topiary/pull/799) Line break after table-less pairs in TOML
- [#826](https://github.com/tweag/topiary/pull/826) Various Tree-sitter query fixes, thanks to @mkatychev

## v0.5.1 - Fragrant Frangipani - 2024-10-22

Expand Down
15 changes: 15 additions & 0 deletions topiary-cli/tests/samples/expected/tree_sitter_query.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1508,3 +1508,18 @@
.
["," ";"]* @do_nothing
)

; ================================================================================
; Predicate parameter newline separatation and indentation
; ================================================================================

(#any-of? @function.builtin @foo
"union"
"difference"
"intersection"
"circle"
)

(#set! injection.language
"doxygen"
)
11 changes: 11 additions & 0 deletions topiary-cli/tests/samples/input/tree_sitter_query.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1509,3 +1509,14 @@
.
[ "," ";" ]* @do_nothing
)

; ================================================================================
; Predicate parameter newline separatation and indentation
; ================================================================================

(#any-of? @function.builtin @foo "union" "difference" "intersection"
"circle")

(#set!
injection.language
"doxygen")
18 changes: 17 additions & 1 deletion topiary-queries/queries/tree_sitter_query.scm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
(grouping)
(list)
(named_node)
(field_definition)
"."
"("
"["
Expand All @@ -51,9 +52,24 @@
; The grammar always includes a (parameters) child node under
; (predicate), even when there are none. Topiary will deal with the
; zero-byte nodes, so we just need to set the spacing correctly.
; Add softlines and indentation after parameter capture groups and identifiers.
(predicate
(parameters
[(identifier) (capture)] @append_spaced_softline @append_indent_start
.
(string)
) @append_indent_end
)

(predicate
(parameters
(string) @append_empty_softline
)
)

(predicate
(parameters
_ @prepend_space
(_) @prepend_space
)
)

Expand Down

0 comments on commit 2170fa7

Please sign in to comment.