mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
feat(formatter): support formatting missing nodes
This commit makes missing nodes take formatting identical to that of regular named nodes, with the only exception being that a newline will not be prepended to a node name. E.g. this pattern: ```query (MISSING identifier) ``` will *not* be changed to: ```query (MISSING (identifier)) ```
This commit is contained in:
parent
7194ff9511
commit
53a6b3993f
1 changed files with 11 additions and 0 deletions
|
|
@ -90,6 +90,7 @@ local format_queries = [[
|
|||
(grouping)
|
||||
(named_node)
|
||||
(anonymous_node)
|
||||
(missing_node)
|
||||
(field_definition)
|
||||
] @format.prepend-newline)
|
||||
|
||||
|
|
@ -101,6 +102,7 @@ local format_queries = [[
|
|||
(grouping)
|
||||
(named_node)
|
||||
(anonymous_node)
|
||||
(missing_node)
|
||||
(field_definition)
|
||||
(comment)
|
||||
] @format.cancel-prepend
|
||||
|
|
@ -156,6 +158,7 @@ local format_queries = [[
|
|||
(named_node) ; (foo (bar))
|
||||
(predicate) ; (named_node (#set!))
|
||||
(anonymous_node)
|
||||
(missing_node)
|
||||
"."
|
||||
])
|
||||
;; Honoring comment's position within a node
|
||||
|
|
@ -188,6 +191,7 @@ local format_queries = [[
|
|||
(named_node)
|
||||
(predicate)
|
||||
(anonymous_node)
|
||||
(missing_node)
|
||||
"."
|
||||
] @format.append-newline)
|
||||
|
||||
|
|
@ -213,6 +217,7 @@ local format_queries = [[
|
|||
(named_node) ; ((foo))
|
||||
(list) ; ([foo] (...))
|
||||
(anonymous_node) ; ("foo")
|
||||
(missing_node)
|
||||
(grouping . (_))
|
||||
] @format.indent.begin
|
||||
.
|
||||
|
|
@ -226,6 +231,7 @@ local format_queries = [[
|
|||
"("
|
||||
[
|
||||
(anonymous_node)
|
||||
(missing_node)
|
||||
(named_node)
|
||||
(list)
|
||||
(predicate)
|
||||
|
|
@ -240,6 +246,8 @@ local format_queries = [[
|
|||
(#not-kind-eq? @format.cancel-append "comment"))
|
||||
(grouping
|
||||
(capture) @format.prepend-space)
|
||||
(missing_node
|
||||
name: (_) @format.prepend-space)
|
||||
;; Remove unnecessary parens
|
||||
(grouping
|
||||
"(" @format.remove
|
||||
|
|
@ -254,6 +262,8 @@ local format_queries = [[
|
|||
(grouping)
|
||||
(anonymous_node
|
||||
name: (string) .)
|
||||
(missing_node
|
||||
name: (_) .)
|
||||
(named_node
|
||||
[
|
||||
"_"
|
||||
|
|
@ -300,6 +310,7 @@ local format_queries = [[
|
|||
(grouping)
|
||||
(named_node)
|
||||
(anonymous_node)
|
||||
(missing_node)
|
||||
(negated_field)
|
||||
] @format.cancel-append
|
||||
.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue