use indent.X syntax for captures and properties of set directives

update CONTRIBUTING.md

adjust indents for bass

fix doc capture comment
This commit is contained in:
George Harker 2023-03-20 14:44:39 -07:00 committed by Amaan Qureshi
parent b4fcc61175
commit cb568af539
80 changed files with 592 additions and 575 deletions

View file

@ -315,14 +315,14 @@ the node describing the language and `@content` to describe the injection region
### Indents ### Indents
```scheme ```scheme
@indent ; indent children when matching this node @indent.begin ; indent children when matching this node
@indent_end ; marks the end of indented block @indent.end ; marks the end of indented block
@aligned_indent ; behaves like python aligned/hanging indent @indent.align ; behaves like python aligned/hanging indent
@dedent ; dedent children when matching this node @indent.dedent ; dedent children when matching this node
@branch ; dedent itself when matching this node @indent.branch ; dedent itself when matching this node
@ignore ; do not indent in this node @indent.ignore ; do not indent in this node
@auto ; behaves like 'autoindent' buffer option @indent.auto ; behaves like 'autoindent' buffer option
@zero_indent ; sets this node at position 0 (no indent) @indent.zero ; sets this node at position 0 (no indent)
``` ```
[Matrix channel]: https://matrix.to/#/#nvim-treesitter:matrix.org [Matrix channel]: https://matrix.to/#/#nvim-treesitter:matrix.org

View file

@ -224,29 +224,29 @@ Supported options:
} }
`@indent` *nvim-treesitter-indentation-queries* `@indent` *nvim-treesitter-indentation-queries*
Queries can use the following captures: `@indent` and `@dedent`, Queries can use the following captures: `@indent.begin` and `@indent.dedent`,
`@branch`, `@indent_end` or `@aligned_indent`. An `@ignore` capture tells `@indent.branch`, `@indent.end` or `@indent.align`. An `@indent.ignore` capture tells
treesitter to ignore indentation and a `@zero_indent` capture sets treesitter to ignore indentation and a `@indent.zero` capture sets
the indentation to 0. the indentation to 0.
`@indent` *nvim-treesitter-indentation-indent* `@indent.begin` *nvim-treesitter-indentation-indent.begin*
The `@indent` specifies that the next line should be indented. Multiple The `@indent.begin` specifies that the next line should be indented. Multiple
indents on the same line get collapsed. Eg. indents on the same line get collapsed. Eg.
> >
( (
(if_statement) (if_statement)
(ERROR "else") @indent (ERROR "else") @indent.begin
) )
< <
Indent can also have `immediate_indent` set using a `#set!` directive, which Indent can also have `indent.immediate` set using a `#set!` directive, which
permits the next line to indent even when the block intended to be indented permits the next line to indent even when the block intended to be indented
has no content yet, improving interactive typing. has no content yet, improving interactive typing.
eg for python: eg for python:
> >
((if_statement) @indent ((if_statement) @indent.begin
(#set! "immediate_indent" 1)) (#set! indent.immediate 1))
< <
Will allow: Will allow:
@ -254,19 +254,19 @@ Will allow:
if True:<CR> if True:<CR>
# Auto indent to here # Auto indent to here
`@indent_end` *nvim-treesitter-indentation-indent_end* `@indent.end` *nvim-treesitter-indentation-indent.end*
An `@indent_end` capture is used to specify that the indented region ends and An `@indent.end` capture is used to specify that the indented region ends and
any text subsequent to the capture should be dedented. any text subsequent to the capture should be dedented.
`@branch` *nvim-treesitter-indentation-branch* `@indent.branch` *nvim-treesitter-indentation-indent.branch*
An `@branch` capture is used to specify that a dedented region starts An `@indent.branch` capture is used to specify that a dedented region starts
at the line including the captured nodes. at the line including the captured nodes.
`@dedent` *nvim-treesitter-indentation-dedent* `@indent.dedent` *nvim-treesitter-indentation-indent.dedent*
A `@dedent` capture specifies dedenting starting on the next line. A `@indent.dedent` capture specifies dedenting starting on the next line.
> >
`@aligned_indent` *nvim-treesitter-indentation-aligned_indent* `@indent.align` *nvim-treesitter-indentation-aligned_indent.align*
Aligned indent blocks may be specified with the `@aligned_indent` capture. Aligned indent blocks may be specified with the `@indent.align` capture.
This permits This permits
> >
@ -289,15 +289,15 @@ and finally
c c
) )
< <
To specify the delimiters to use `open_delimiter` and `close_delimiter` To specify the delimiters to use `indent.open_delimiter` and
should be used. Eg. `indent.close_delimiter` should be used. Eg.
> >
((argument_list) @aligned_indent ((argument_list) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
< <
For some languages the last line of an `aligned_indent` block must not be For some languages the last line of an `indent.align` block must not be
the same indent as the natural next line. the same indent as the natural next line.
For example in python: For example in python:
@ -314,17 +314,17 @@ Is not correct, whereas
pass pass
Would be correctly indented. This behavior may be chosen using Would be correctly indented. This behavior may be chosen using
`avoid_last_matching_next`. Eg. `indent.avoid_last_matching_next`. Eg.
> >
(if_statement (if_statement
condition: (parenthesized_expression) @aligned_indent condition: (parenthesized_expression) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")") (#set! indent.close_delimiter ")")
(#set! "avoid_last_matching_next" 1) (#set! indent.avoid_last_matching_next 1)
) )
< <
Could be used to specify that the last line of an `@aligned_indent` capture Could be used to specify that the last line of an `@indent.align` capture
should be additionally indented to avoid clashing with the indent of the first should be additionally indented to avoid clashing with the indent of the first
line of the block inside an if. line of the block inside an if.

View file

@ -52,18 +52,31 @@ end
local get_indents = tsutils.memoize_by_buf_tick(function(bufnr, root, lang) local get_indents = tsutils.memoize_by_buf_tick(function(bufnr, root, lang)
local map = { local map = {
auto = {}, indent = {
indent = {}, auto = {},
indent_end = {}, begin = {},
dedent = {}, ["end"] = {},
branch = {}, dedent = {},
ignore = {}, branch = {},
aligned_indent = {}, ignore = {},
zero_indent = {}, align = {},
zero = {},
},
} }
local function split(to_split)
local t = {}
for str in string.gmatch(to_split, "([^.]+)") do
table.insert(t, str)
end
return t
end
for name, node, metadata in queries.iter_captures(bufnr, "indents", root, lang) do for name, node, metadata in queries.iter_captures(bufnr, "indents", root, lang) do
map[name][node:id()] = metadata or {} local path = split(name)
-- node may contain a period so append directly.
table.insert(path, node:id())
queries.insert_to_path(map, path, metadata or {})
end end
return map return map
@ -116,7 +129,7 @@ function M.get_indent(lnum)
if is_empty_line then if is_empty_line then
local prevlnum = vim.fn.prevnonblank(lnum) local prevlnum = vim.fn.prevnonblank(lnum)
node = get_last_node_at_line(root, prevlnum) node = get_last_node_at_line(root, prevlnum)
if q.indent_end[node:id()] then if q.indent["end"][node:id()] then
node = get_first_node_at_line(root, lnum) node = get_first_node_at_line(root, lnum)
end end
else else
@ -134,16 +147,16 @@ function M.get_indent(lnum)
-- tracks to ensure multiple indent levels are not applied for same line -- tracks to ensure multiple indent levels are not applied for same line
local is_processed_by_row = {} local is_processed_by_row = {}
if q.zero_indent[node:id()] then if q.indent.zero[node:id()] then
return 0 return 0
end end
while node do while node do
-- do 'autoindent' if not marked as @indent -- do 'autoindent' if not marked as @indent
if if
not q.indent[node:id()] not q.indent.begin[node:id()]
and not q.aligned_indent[node:id()] and not q.indent.align[node:id()]
and q.auto[node:id()] and q.indent.auto[node:id()]
and node:start() < lnum - 1 and node:start() < lnum - 1
and lnum - 1 <= node:end_() and lnum - 1 <= node:end_()
then then
@ -153,7 +166,12 @@ function M.get_indent(lnum)
-- Do not indent if we are inside an @ignore block. -- Do not indent if we are inside an @ignore block.
-- If a node spans from L1,C1 to L2,C2, we know that lines where L1 < line <= L2 would -- If a node spans from L1,C1 to L2,C2, we know that lines where L1 < line <= L2 would
-- have their indentations contained by the node. -- have their indentations contained by the node.
if not q.indent[node:id()] and q.ignore[node:id()] and node:start() < lnum - 1 and lnum - 1 <= node:end_() then if
not q.indent.begin[node:id()]
and q.indent.ignore[node:id()]
and node:start() < lnum - 1
and lnum - 1 <= node:end_()
then
return 0 return 0
end end
@ -163,7 +181,7 @@ function M.get_indent(lnum)
if if
not is_processed_by_row[srow] not is_processed_by_row[srow]
and ((q.branch[node:id()] and srow == lnum - 1) or (q.dedent[node:id()] and srow ~= lnum - 1)) and ((q.indent.branch[node:id()] and srow == lnum - 1) or (q.indent.dedent[node:id()] and srow ~= lnum - 1))
then then
indent = indent - indent_size indent = indent - indent_size
is_processed = true is_processed = true
@ -179,16 +197,16 @@ function M.get_indent(lnum)
if if
should_process should_process
and ( and (
q.indent[node:id()] q.indent.begin[node:id()]
and (srow ~= erow or is_in_err or q.indent[node:id()].immediate_indent) and (srow ~= erow or is_in_err or q.indent.begin[node:id()]["indent.immediate"])
and (srow ~= lnum - 1 or q.indent[node:id()].start_at_same_line) and (srow ~= lnum - 1 or q.indent.begin[node:id()]["indent.start_at_same_line"])
) )
then then
indent = indent + indent_size indent = indent + indent_size
is_processed = true is_processed = true
end end
if is_in_err and not q.aligned_indent[node:id()] then if is_in_err and not q.indent.align[node:id()] then
-- only when the node is in error, promote the -- only when the node is in error, promote the
-- first child's aligned indent to the error node -- first child's aligned indent to the error node
-- to work around ((ERROR "X" . (_)) @aligned_indent (#set! "delimeter" "AB")) -- to work around ((ERROR "X" . (_)) @aligned_indent (#set! "delimeter" "AB"))
@ -196,25 +214,25 @@ function M.get_indent(lnum)
-- (ERROR "X" @aligned_indent (#set! "delimeter" "AB") . (_)) -- (ERROR "X" @aligned_indent (#set! "delimeter" "AB") . (_))
-- and we will fish it out here. -- and we will fish it out here.
for c in node:iter_children() do for c in node:iter_children() do
if q.aligned_indent[c:id()] then if q.indent.align[c:id()] then
q.aligned_indent[node:id()] = q.aligned_indent[c:id()] q.indent.align[node:id()] = q.indent.align[c:id()]
break break
end end
end end
end end
-- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum) -- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum)
if should_process and q.aligned_indent[node:id()] and (srow ~= erow or is_in_err) and (srow ~= lnum - 1) then if should_process and q.indent.align[node:id()] and (srow ~= erow or is_in_err) and (srow ~= lnum - 1) then
local metadata = q.aligned_indent[node:id()] local metadata = q.indent.align[node:id()]
local o_delim_node, o_is_last_in_line ---@type TSNode|nil, boolean|nil local o_delim_node, o_is_last_in_line ---@type TSNode|nil, boolean|nil
local c_delim_node, c_is_last_in_line ---@type TSNode|nil, boolean|nil, boolean|nil local c_delim_node, c_is_last_in_line ---@type TSNode|nil, boolean|nil, boolean|nil
local indent_is_absolute = false local indent_is_absolute = false
if metadata.open_delimiter then if metadata["indent.open_delimiter"] then
o_delim_node, o_is_last_in_line = find_delimiter(bufnr, node, metadata.open_delimiter) o_delim_node, o_is_last_in_line = find_delimiter(bufnr, node, metadata["indent.open_delimiter"])
else else
o_delim_node = node o_delim_node = node
end end
if metadata.close_delimiter then if metadata["indent.close_delimiter"] then
c_delim_node, c_is_last_in_line = find_delimiter(bufnr, node, metadata.close_delimiter) c_delim_node, c_is_last_in_line = find_delimiter(bufnr, node, metadata["indent.close_delimiter"])
else else
c_delim_node = node c_delim_node = node
end end
@ -245,7 +263,7 @@ function M.get_indent(lnum)
-- Then its indent level shouldn't be affected by `@aligned_indent` node -- Then its indent level shouldn't be affected by `@aligned_indent` node
indent = math.max(indent - indent_size, 0) indent = math.max(indent - indent_size, 0)
else else
indent = o_scol + (metadata.increment or 1) indent = o_scol + (metadata["indent.increment"] or 1)
indent_is_absolute = true indent_is_absolute = true
end end
end end
@ -254,9 +272,9 @@ function M.get_indent(lnum)
if c_srow and c_srow ~= o_srow and c_srow == lnum - 1 then if c_srow and c_srow ~= o_srow and c_srow == lnum - 1 then
-- delims end on current line, and are not open and closed same line. -- delims end on current line, and are not open and closed same line.
-- then this last line may need additional indent to avoid clashes -- then this last line may need additional indent to avoid clashes
-- with the next. `avoid_last_matching_next` controls this behavior, -- with the next. `indent.avoid_last_matching_next` controls this behavior,
-- for example this is needed for function parameters. -- for example this is needed for function parameters.
avoid_last_matching_next = metadata.avoid_last_matching_next or false avoid_last_matching_next = metadata["indent.avoid_last_matching_next"] or false
end end
if avoid_last_matching_next then if avoid_last_matching_next then
-- last line must be indented more in cases where -- last line must be indented more in cases where

View file

@ -213,6 +213,24 @@ local function prepare_query(bufnr, query_name, root, root_lang)
} }
end end
-- Given a path (i.e. a List(String)) this functions inserts value at path
---@param object any
---@param path string[]
---@param value any
function M.insert_to_path(object, path, value)
local curr_obj = object
for index = 1, (#path - 1) do
if curr_obj[path[index]] == nil then
curr_obj[path[index]] = {}
end
curr_obj = curr_obj[path[index]]
end
curr_obj[path[#path]] = value
end
---@param query Query ---@param query Query
---@param bufnr integer ---@param bufnr integer
---@param start_row integer ---@param start_row integer
@ -230,24 +248,6 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
return t return t
end end
-- Given a path (i.e. a List(String)) this functions inserts value at path
---@param object any
---@param path string[]
---@param value any
local function insert_to_path(object, path, value)
local curr_obj = object
for index = 1, (#path - 1) do
if curr_obj[path[index]] == nil then
curr_obj[path[index]] = {}
end
curr_obj = curr_obj[path[index]]
end
curr_obj[path[#path]] = value
end
local matches = query:iter_matches(qnode, bufnr, start_row, end_row) local matches = query:iter_matches(qnode, bufnr, start_row, end_row)
local function iterator() local function iterator()
@ -260,9 +260,9 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
local name = query.captures[id] -- name of the capture in the query local name = query.captures[id] -- name of the capture in the query
if name ~= nil then if name ~= nil then
local path = split(name .. ".node") local path = split(name .. ".node")
insert_to_path(prepared_match, path, node) M.insert_to_path(prepared_match, path, node)
local metadata_path = split(name .. ".metadata") local metadata_path = split(name .. ".metadata")
insert_to_path(prepared_match, metadata_path, metadata[id]) M.insert_to_path(prepared_match, metadata_path, metadata[id])
end end
end end
@ -273,10 +273,10 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
for _, pred in pairs(preds) do for _, pred in pairs(preds) do
-- functions -- functions
if pred[1] == "set!" and type(pred[2]) == "string" then if pred[1] == "set!" and type(pred[2]) == "string" then
insert_to_path(prepared_match, split(pred[2]), pred[3]) M.insert_to_path(prepared_match, split(pred[2]), pred[3])
end end
if pred[1] == "make-range!" and type(pred[2]) == "string" and #pred == 4 then if pred[1] == "make-range!" and type(pred[2]) == "string" and #pred == 4 then
insert_to_path( M.insert_to_path(
prepared_match, prepared_match,
split(pred[2] .. ".node"), split(pred[2] .. ".node"),
tsrange.TSRange.from_nodes(bufnr, match[pred[3]], match[pred[4]]) tsrange.TSRange.from_nodes(bufnr, match[pred[3]], match[pred[4]])

View file

@ -2,21 +2,21 @@
(list) (list)
(scope) (scope)
(cons) (cons)
] @indent ] @indent.begin
[ [
")" ")"
"}" "}"
"]" "]"
] @indent_end ] @indent.end
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -1,10 +1,10 @@
[ [
(entry) (entry)
] @indent ] @indent.begin
[ [
"{" "{"
"}" "}"
] @branch ] @indent.branch
(comment) @ignore (comment) @indent.ignore

View file

@ -1,18 +1,18 @@
[ [
(array) (array)
(object) (object)
] @indent ] @indent.begin
"}" @indent_end "}" @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
(diagnostic_comment) (diagnostic_comment)
] @auto ] @indent.auto

View file

@ -7,66 +7,66 @@
(initializer_list) (initializer_list)
(init_declarator) (init_declarator)
(expression_statement) (expression_statement)
] @indent ] @indent.begin
( (
ERROR ERROR
"for" "(" @indent ";" ";" ")" @indent_end) "for" "(" @indent.begin ";" ";" ")" @indent.end)
( (
(for_statement (for_statement
body: (_) @_body body: (_) @_body
) @indent ) @indent.begin
(#not-has-type? @_body compound_statement) (#not-has-type? @_body compound_statement)
) )
( (
while_statement while_statement
condition: (_) @indent condition: (_) @indent.begin
) )
( (
(while_statement (while_statement
body: (_) @_body body: (_) @_body
) @indent ) @indent.begin
(#not-has-type? @_body compound_statement) (#not-has-type? @_body compound_statement)
) )
( (
(if_statement) (if_statement)
(ERROR "else") @indent (ERROR "else") @indent.begin
) )
( (
if_statement if_statement
condition: (_) @indent condition: (_) @indent.begin
) )
;; Make sure all cases of if-else are tagged with @indent ;; Make sure all cases of if-else are tagged with @indent.begin
;; So we will offset the indents for the else case ;; So we will offset the indents for the else case
( (
(if_statement (if_statement
consequence: (compound_statement) consequence: (compound_statement)
"else" @branch "else" @indent.branch
alternative: alternative:
[ [
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
(compound_statement ["{" "}"] @branch) (compound_statement ["{" "}"] @indent.branch)
(_) (_)
] ]
) @indent ) @indent.begin
) )
( (
(if_statement (if_statement
consequence: (_ ";" @indent_end) @_consequence consequence: (_ ";" @indent.end) @_consequence
) @indent ) @indent.begin
(#not-has-type? @_consequence compound_statement) (#not-has-type? @_consequence compound_statement)
) )
( (
(if_statement (if_statement
consequence: (_) @_consequence consequence: (_) @_consequence
"else" @branch "else" @indent.branch
alternative: alternative:
[ [
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
(compound_statement ["{" "}"] @branch) (compound_statement ["{" "}"] @indent.branch)
(_) (_)
] ]
) )
@ -83,19 +83,19 @@
consequence: (_) consequence: (_)
alternative: alternative:
[ [
(if_statement consequence: (compound_statement) @dedent) (if_statement consequence: (compound_statement) @indent.dedent)
(_) (_)
] @dedent ] @indent.dedent
) )
) )
(compound_statement "}" @indent_end) (compound_statement "}" @indent.end)
[ [
")" ")"
"}" "}"
(statement_identifier) (statement_identifier)
] @branch ] @indent.branch
[ [
"#define" "#define"
@ -105,18 +105,19 @@
"#if" "#if"
"#else" "#else"
"#endif" "#endif"
] @zero_indent ] @indent.zero
[ [
(preproc_arg) (preproc_arg)
(string_literal) (string_literal)
] @ignore ] @indent.ignore
((ERROR (parameter_declaration)) @aligned_indent ((ERROR (parameter_declaration)) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
([(argument_list) (parameter_list)] @aligned_indent ([(argument_list) (parameter_list)] @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
(comment) @indent.auto
(comment) @auto

View file

@ -11,26 +11,26 @@
(struct) (struct)
(struct_shorthand) (struct_shorthand)
(union) (union)
] @indent ] @indent.begin
((struct_shorthand (property)) @aligned_indent ((struct_shorthand (property)) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
((const_list (const_value)) @aligned_indent ((const_list (const_value)) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
[ [
"}" "}"
")" ")"
] @indent_end ] @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -2,6 +2,6 @@
(intent_def) (intent_def)
(slot_def) (slot_def)
(alias_def) (alias_def)
] @indent ] @indent.begin
(ERROR "]") @indent (ERROR "]") @indent.begin

View file

@ -3,21 +3,21 @@
(map) (map)
(imap) (imap)
(array) (array)
] @indent ] @indent.begin
[ [
"]" "]"
"}" "}"
">" ">"
] @indent_end ] @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ "<" ">" ] @branch [ "<" ">" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -3,8 +3,9 @@
[ [
(class_specifier) (class_specifier)
(condition_clause) (condition_clause)
] @indent ] @indent.begin
((field_initializer_list) @indent.begin
(#set! indent.start_at_same_line 1))
(access_specifier) @indent.branch
((field_initializer_list) @indent
(#set! "start_at_same_line" 1))
(access_specifier) @branch

View file

@ -1,9 +1,9 @@
[ [
(block) (block)
(declaration) (declaration)
] @indent ] @indent.begin
(block ("}") @branch) (block ("}") @indent.branch)
("}") @dedent ("}") @indent.dedent
(comment) @ignore (comment) @indent.ignore

View file

@ -1,21 +1,21 @@
[ [
(import_spec_list) (import_spec_list)
(field) (field)
] @indent ] @indent.begin
[ [
"}" "}"
"]" "]"
")" ")"
] @indent_end ] @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -2,16 +2,16 @@
(block_statement) (block_statement)
(case_statement) (case_statement)
(token_string) (token_string)
] @indent ] @indent.begin
[ [
"(" ")" "(" ")"
"{" "}" "{" "}"
"[" "]" "[" "]"
] @branch ] @indent.branch
[ [
(line_comment) (line_comment)
(block_comment) (block_comment)
(nesting_block_comment) (nesting_block_comment)
] @ignore ] @indent.ignore

View file

@ -10,7 +10,7 @@
(list_literal) (list_literal)
(return_statement) (return_statement)
(arguments) (arguments)
] @indent ] @indent.begin
[ [
"(" "("
@ -19,13 +19,13 @@
"}" "}"
"[" "["
"]" "]"
] @branch ] @indent.branch
[ [
"}" "}"
] @indent_end ] @indent.end
; this one is for dedenting the else block ; this one is for dedenting the else block
(if_statement (block) @branch) (if_statement (block) @indent.branch)
(comment) @ignore (comment) @indent.ignore

View file

@ -2,13 +2,13 @@
(node) (node)
(property) (property)
(integer_cells) (integer_cells)
] @indent ] @indent.begin
[ [
"}" "}"
">" ">"
] @branch ] @indent.branch
[ [
(comment) (comment)
] @ignore ] @indent.ignore

View file

@ -16,42 +16,42 @@
(switch_statement) (switch_statement)
(template_substitution) (template_substitution)
(ternary_expression) (ternary_expression)
] @indent ] @indent.begin
(arguments (call_expression) @indent) (arguments (call_expression) @indent.begin)
(binary_expression (call_expression) @indent) (binary_expression (call_expression) @indent.begin)
(expression_statement (call_expression) @indent) (expression_statement (call_expression) @indent.begin)
(arrow_function (arrow_function
body: (_) @_body body: (_) @_body
(#not-has-type? @_body statement_block) (#not-has-type? @_body statement_block)
) @indent ) @indent.begin
(assignment_expression (assignment_expression
right: (_) @_right right: (_) @_right
(#not-has-type? @_right arrow_function function) (#not-has-type? @_right arrow_function function)
) @indent ) @indent.begin
(variable_declarator (variable_declarator
value: (_) @_value value: (_) @_value
(#not-has-type? @_value arrow_function call_expression function) (#not-has-type? @_value arrow_function call_expression function)
) @indent ) @indent.begin
(arguments ")" @indent_end) (arguments ")" @indent.end)
(object "}" @indent_end) (object "}" @indent.end)
(statement_block "}" @indent_end) (statement_block "}" @indent.end)
[ [
(arguments (object)) (arguments (object))
")" ")"
"}" "}"
"]" "]"
] @branch ] @indent.branch
(statement_block "{" @branch) (statement_block "{" @indent.branch)
(parenthesized_expression ("(" (_) ")" @indent_end)) (parenthesized_expression ("(" (_) ")" @indent.end))
["}" "]"] @indent_end ["}" "]"] @indent.end
[ [
(comment) (comment)
(template_string) (template_string)
] @ignore ] @indent.ignore
(ERROR) @auto (ERROR) @indent.auto

View file

@ -6,7 +6,7 @@
(stab_clause) (stab_clause)
(tuple) (tuple)
(arguments) (arguments)
] @indent ] @indent.begin
[ [
")" ")"
@ -17,7 +17,7 @@
"rescue" "rescue"
"}" "}"
"end" "end"
] @indent_end @branch ] @indent.end @indent.branch
; Elixir pipelines are not indented, but other binary operator chains are ; Elixir pipelines are not indented, but other binary operator chains are
((binary_operator operator: _ @_operator) @indent (#not-eq? @_operator "|>")) ((binary_operator operator: _ @_operator) @indent.begin (#not-eq? @_operator "|>"))

View file

@ -1,6 +1,6 @@
(reduction) @indent (reduction) @indent.begin
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -5,12 +5,12 @@
(if_statement) (if_statement)
(begin_statement) (begin_statement)
(switch_statement) (switch_statement)
] @indent ] @indent.begin
[ [
(else_if_clause) (else_if_clause)
(else_clause) (else_clause)
"end" "end"
] @branch ] @indent.branch
(comment) @ignore (comment) @indent.ignore

View file

@ -1,11 +1,11 @@
[ [
"{" "{"
"}" "}"
] @branch ] @indent.branch
[(dict) (key_value)] @indent [(dict) (key_value)] @indent.begin
[ [
(comment) (comment)
] @ignore ] @indent.ignore

View file

@ -9,7 +9,7 @@
(where_statement) (where_statement)
(derived_type_definition) (derived_type_definition)
(enum) (enum)
] @indent ] @indent.begin
[ [
(end_module_statement) (end_module_statement)
@ -24,4 +24,4 @@
(end_type_statement) (end_type_statement)
(end_enum_statement) (end_enum_statement)
(end_where_statement) (end_where_statement)
] @branch ] @indent.branch

View file

@ -5,15 +5,15 @@
(afx_element_self_closing) (afx_element_self_closing)
(eel_array) (eel_array)
(eel_object) (eel_object)
] @indent ] @indent.begin
(block end: _ @branch) (block end: _ @indent.branch)
(value_dsl end: _ @branch) (value_dsl end: _ @indent.branch)
(eel_array end: _ @branch) (eel_array end: _ @indent.branch)
(eel_object end: _ @branch) (eel_object end: _ @indent.branch)
[ [
(afx_closing_element) (afx_closing_element)
] @branch ] @indent.branch
(comment) @ignore (comment) @indent.ignore

View file

@ -12,12 +12,12 @@
(match_body) (match_body)
(set_body) (set_body)
(get_body) (get_body)
] @indent ] @indent.begin
[ [
(elif_clause) (elif_clause)
(else_clause) (else_clause)
] @branch ] @indent.branch
[ [
(string) (string)
@ -26,46 +26,46 @@
(dictionary) (dictionary)
(parenthesized_expression) (parenthesized_expression)
(ERROR) (ERROR)
] @auto ] @indent.auto
[ [
(pass_statement) (pass_statement)
(continue_statement) (continue_statement)
(break_statement) (break_statement)
(return_statement) (return_statement)
] @dedent ] @indent.dedent
[ [
(ERROR "[") (ERROR "[")
(ERROR "(") (ERROR "(")
(ERROR "{") (ERROR "{")
] @indent ] @indent.begin
;; This only works with expanded tabs. ;; This only works with expanded tabs.
; ((parameters) @aligned_indent (#set! "open_delimiter" "(") (#set! "close_delimiter" ")")) ; ((parameters) @indent.align (#set! indent.open_delimiter "(") (#set! indent.close_delimiter ")"))
; ((arguments) @aligned_indent (#set! "open_delimiter" "(") (#set! "close_delimiter" ")")) ; ((arguments) @indent.align (#set! indent.open_delimiter "(") (#set! indent.close_delimiter ")"))
;; The following queries either do not agree with the current body parsing or are ;; The following queries either do not agree with the current body parsing or are
;; attempted workarounds. Specifically as the last statement of a body. Opening ;; attempted workarounds. Specifically as the last statement of a body. Opening
;; a new line in between statements works well. ;; a new line in between statements works well.
;; ;;
;; The overall experience is poor, so I've opted for @auto. ;; The overall experience is poor, so I've opted for @indent.auto.
;; ;;
;; The gdscript parser will need to be patched to accommodate more interactive ;; The gdscript parser will need to be patched to accommodate more interactive
;; edits. As far as I can tell the parser greedily consumes whitespace ;; edits. As far as I can tell the parser greedily consumes whitespace
;; as a zero-width token which causes trouble when inserting indents. ;; as a zero-width token which causes trouble when inserting indents.
;; This indents correctly with tabs. ;; This indents correctly with tabs.
; (arguments) @indent ; (arguments) @indent.begin
; (parameters) @indent ; (parameters) @indent.begin
; (array) @indent ; (array) @indent.begin
; (dictionary) @indent ; (dictionary) @indent.begin
; (parenthesized_expression) @indent ; (parenthesized_expression) @indent.begin
;; Partial workaround for when the cursor is on the bracket character and a newline ;; Partial workaround for when the cursor is on the bracket character and a newline
;; is created with <o>. Without this the newline is opened with extra ;; is created with <o>. Without this the newline is opened with extra
;; indentation. ;; indentation.
; (body (_ (array "]" @indent_end) ) _) ; (body (_ (array "]" @indent.end) ) _)
;; Problematic behaviors occur at the last statement of a body. ;; Problematic behaviors occur at the last statement of a body.
;; with @dedent: ;; with @dedent:
;; - [ | ] i<CR> will dedent ] to 0. ;; - [ | ] i<CR> will dedent ] to 0.
@ -75,4 +75,4 @@
;; - [ | ] i<CR> same ;; - [ | ] i<CR> same
;; - [ ;; - [
;; ]| o will open new line with extra indent. ;; ]| o will open new line with extra indent.
;(body (_ (array "]" @auto) ) .) ;(body (_ (array "]" @indent.auto) ) .)

View file

@ -18,13 +18,13 @@
(todo) (todo)
(try) (try)
(tuple) (tuple)
] @indent ] @indent.begin
[ [
")" ")"
"]" "]"
"}" "}"
] @indent_end @branch ] @indent.end @indent.branch
; Gleam pipelines are not indented, but other binary expression chains are ; Gleam pipelines are not indented, but other binary expression chains are
((binary_expression operator: _ @_operator) @indent (#not-eq? @_operator "|>")) ((binary_expression operator: _ @_operator) @indent.begin (#not-eq? @_operator "|>"))

View file

@ -13,21 +13,21 @@
(call_expression) (call_expression)
(parameter_list) (parameter_list)
(struct_type) (struct_type)
] @indent ] @indent.begin
[ [
"}" "}"
] @branch ] @indent.branch
(const_declaration ")" @branch) (const_declaration ")" @indent.branch)
(import_spec_list ")" @branch) (import_spec_list ")" @indent.branch)
(var_declaration ")" @branch) (var_declaration ")" @indent.branch)
[ [
"}" "}"
")" ")"
] @indent_end ] @indent.end
(parameter_list ")" @branch) (parameter_list ")" @indent.branch)
(comment) @ignore (comment) @indent.ignore

View file

@ -1,9 +1,9 @@
[ [
(definition) (definition)
(selection) (selection)
] @indent ] @indent.begin
[ [
"{" "{"
"}" "}"
] @branch ] @indent.branch

View file

@ -12,25 +12,25 @@
(array_literal) (array_literal)
(struct_literal) (struct_literal)
(tuple_literal) (tuple_literal)
] @indent ] @indent.begin
(if_statement (if_statement
("(" condition: (_) ")") @indent) ("(" condition: (_) ")") @indent.begin)
[ [
"}" "}"
"]" "]"
")" ")"
] @indent_end ] @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
(concatenated_string) (concatenated_string)
] @auto ] @indent.auto

View file

@ -3,13 +3,13 @@
(object) (object)
(tuple) (tuple)
(function_call) (function_call)
] @indent ] @indent.begin
[ [
"]" "]"
")" ")"
"}" "}"
] @branch @indent_end ] @indent.branch @indent.end
(comment) @auto (comment) @indent.auto
(ERROR) @auto (ERROR) @indent.auto

View file

@ -3,18 +3,18 @@
(component) (component)
(slot) (slot)
(tag) (tag)
] @indent ] @indent.begin
; Dedent at the end of each tag, component, and slot ; Dedent at the end of each tag, component, and slot
[ [
(end_component) (end_component)
(end_slot) (end_slot)
(end_tag) (end_tag)
] @branch @dedent ] @indent.branch @indent.dedent
; Self-closing tags and components should not change ; Self-closing tags and components should not change
; indentation level of sibling nodes ; indentation level of sibling nodes
[ [
(self_closing_component) (self_closing_component)
(self_closing_tag) (self_closing_tag)
] @auto ] @indent.auto

View file

@ -1,3 +1,3 @@
; inherits: json ; inherits: json
(comment) @ignore (comment) @indent.ignore

View file

@ -7,7 +7,7 @@
(#not-any-of? @_not_special "meta" "link") (#not-any-of? @_not_special "meta" "link")
) )
(element (self_closing_tag)) (element (self_closing_tag))
] @indent ] @indent.begin
; These tags are usually written one-lined and doesn't use self-closing tags so special-cased them ; These tags are usually written one-lined and doesn't use self-closing tags so special-cased them
; but add indent to the tag to make sure attributes inside them are still indented if written multi-lined ; but add indent to the tag to make sure attributes inside them are still indented if written multi-lined
@ -15,20 +15,20 @@
(start_tag (start_tag
(tag_name) @_special) (tag_name) @_special)
(#any-of? @_special "meta" "link") (#any-of? @_special "meta" "link")
) @indent ) @indent.begin
; These are the nodes that will be captured when we do `normal o` ; These are the nodes that will be captured when we do `normal o`
; But last element has already been ended, so capturing this ; But last element has already been ended, so capturing this
; to mark end of last element ; to mark end of last element
(element (end_tag [">"] @indent_end)) (element (end_tag [">"] @indent.end))
(element (self_closing_tag "/>" @indent_end)) (element (self_closing_tag "/>" @indent.end))
; Script/style elements aren't indented, so only branch the end tag of other elements ; Script/style elements aren't indented, so only branch the end tag of other elements
(element (end_tag) @branch) (element (end_tag) @indent.branch)
[ [
">" ">"
"/>" "/>"
] @branch ] @indent.branch
(comment) @ignore (comment) @indent.ignore

View file

@ -1,3 +1,3 @@
(paired_statement) @indent (paired_statement) @indent.begin
(end_paired_statement) @indent_end (end_paired_statement) @indent.end
(branch_statement) @branch (branch_statement) @indent.branch

View file

@ -8,9 +8,9 @@
(array_initializer) (array_initializer)
(argument_list) (argument_list)
(formal_parameters) (formal_parameters)
] @indent ] @indent.begin
(expression_statement (method_invocation) @indent) (expression_statement (method_invocation) @indent.begin)
[ [
"(" "("
@ -19,13 +19,14 @@
"}" "}"
"[" "["
"]" "]"
] @branch ] @indent.branch
"}" @indent_end "}" @indent.end
(line_comment) @ignore (line_comment) @indent.ignore
[ [
(ERROR) (ERROR)
(block_comment) (block_comment)
] @auto ] @indent.auto

View file

@ -1,9 +1,9 @@
[ [
(object) (object)
(array) (array)
] @indent ] @indent.begin
[ [
"}" "}"
"]" "]"
] @branch ] @indent.branch

View file

@ -1,3 +1,3 @@
; inherits: json ; inherits: json
(comment) @ignore (comment) @indent.ignore

View file

@ -3,19 +3,19 @@
(jsx_element) (jsx_element)
(jsx_self_closing_element) (jsx_self_closing_element)
(jsx_expression) (jsx_expression)
] @indent ] @indent.begin
(jsx_fragment (jsx_fragment
("<" ">" (_) "<" @branch "/" ">" @indent_end) ("<" ">" (_) "<" @indent.branch "/" ">" @indent.end)
) )
(jsx_closing_element (">" @indent_end)) (jsx_closing_element (">" @indent.end))
(jsx_self_closing_element ">" @indent_end) (jsx_self_closing_element ">" @indent.end)
[ [
(jsx_closing_element) (jsx_closing_element)
">" ">"
] @branch ] @indent.branch
; <button ; <button
; /> ; />
(jsx_self_closing_element "/" @branch) (jsx_self_closing_element "/" @indent.branch)

View file

@ -22,7 +22,7 @@
(comprehension_expression) (comprehension_expression)
(matrix_expression) (matrix_expression)
(vector_expression) (vector_expression)
] @indent ] @indent.begin
[ [
"end" "end"
@ -34,10 +34,10 @@
(elseif_clause) (elseif_clause)
(catch_clause) (catch_clause)
(finally_clause) (finally_clause)
] @branch ] @indent.branch
[ [
(line_comment) (line_comment)
(block_comment) (block_comment)
] @ignore ] @indent.ignore

View file

@ -1,7 +1,7 @@
(node (node_children) @indent) (node (node_children) @indent.begin)
"}" @indent_end "}" @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch

View file

@ -1,3 +1,3 @@
[ [
(journal_item) (journal_item)
] @indent ] @indent.begin

View file

@ -13,17 +13,17 @@
(table_constructor) (table_constructor)
(arguments) (arguments)
(return_statement) (return_statement)
] @indent ] @indent.begin
[ [
"end" "end"
")" ")"
"}" "}"
] @indent_end ] @indent.end
(return_statement (return_statement
(expression_list (expression_list
(function_call))) @dedent (function_call))) @indent.dedent
[ [
"end" "end"
@ -35,8 +35,9 @@
(elseif_statement) (elseif_statement)
"else" "else"
(else_statement) (else_statement)
] @branch ] @indent.branch
(comment) @auto (comment) @indent.auto
(string) @indent.auto
(string) @auto

View file

@ -2,5 +2,5 @@
(pool) (pool)
(rule) (rule)
(build) (build)
] @indent ] @indent.begin

View file

@ -14,9 +14,9 @@
(recInitializer) (recInitializer)
(arrInitializer) (arrInitializer)
(defaultValue) (defaultValue)
] @indent ] @indent.begin
(defProc (block) @indent) (defProc (block) @indent.begin)
[ [
(kEnd) (kEnd)
@ -29,4 +29,4 @@
(declSection) (declSection)
"]" "]"
")" ")"
] @branch ] @indent.branch

View file

@ -11,18 +11,18 @@
(match_block) (match_block)
(case_statement) (case_statement)
"[" "["
] @indent ] @indent.begin
[ [
")" ")"
"}" "}"
"]" "]"
] @branch ] @indent.branch
[ [
(comment) (comment)
] @auto ] @indent.auto
(compound_statement "}" @indent_end) (compound_statement "}" @indent.end)
(ERROR) @auto (ERROR) @indent.auto

View file

@ -1,5 +1,5 @@
(block) @indent (block) @indent.begin
(ERROR) @auto (ERROR) @indent.auto
(comment) @ignore (comment) @indent.ignore

View file

@ -14,97 +14,91 @@
(lambda) (lambda)
(concatenated_string) (concatenated_string)
] @indent ] @indent.begin
((list) @aligned_indent ((list) @indent.align
(#set! "open_delimiter" "[") (#set! indent.open_delimiter "[")
(#set! "close_delimiter" "]") (#set! indent.close_delimiter "]")
(#set! "dedent_lone_close_delimiter" 1)
) )
((dictionary) @aligned_indent ((dictionary) @indent.align
(#set! "open_delimiter" "{") (#set! indent.open_delimiter "{")
(#set! "close_delimiter" "}") (#set! indent.close_delimiter "}")
(#set! "dedent_lone_close_delimiter" 1)
) )
((set) @aligned_indent ((set) @indent.align
(#set! "open_delimiter" "{") (#set! indent.open_delimiter "{")
(#set! "close_delimiter" "}") (#set! indent.close_delimiter "}")
(#set! "dedent_lone_close_delimiter" 1)
) )
((for_statement) @indent ((for_statement) @indent.begin
(#set! "immediate_indent" 1)) (#set! indent.immediate 1))
((if_statement) @indent ((if_statement) @indent.begin
(#set! "immediate_indent" 1)) (#set! indent.immediate 1))
((while_statement) @indent ((while_statement) @indent.begin
(#set! "immediate_indent" 1)) (#set! indent.immediate 1))
((try_statement) @indent ((try_statement) @indent.begin
(#set! "immediate_indent" 1)) (#set! indent.immediate 1))
(ERROR "try" ":" @indent (#set! "immediate_indent" 1)) (ERROR "try" ":" @indent.begin (#set! indent.immediate 1))
((function_definition) @indent ((function_definition) @indent.begin
(#set! "immediate_indent" 1)) (#set! indent.immediate 1))
((class_definition) @indent ((class_definition) @indent.begin
(#set! "immediate_indent" 1)) (#set! indent.immediate 1))
((with_statement) @indent ((with_statement) @indent.begin
(#set! "immediate_indent" 1)) (#set! indent.immediate 1))
(if_statement (if_statement
condition: (parenthesized_expression) @aligned_indent condition: (parenthesized_expression) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")") (#set! indent.close_delimiter ")")
(#set! "avoid_last_matching_next" 1) (#set! indent.avoid_last_matching_next 1)
) )
(while_statement (while_statement
condition: (parenthesized_expression) @aligned_indent condition: (parenthesized_expression) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")") (#set! indent.close_delimiter ")")
(#set! "avoid_last_matching_next" 1) (#set! indent.avoid_last_matching_next 1)
) )
(ERROR "(" @aligned_indent (#set! "open_delimiter" "(") (#set! "close_delimiter" ")") . (_)) (ERROR "(" @indent.align (#set! indent.open_delimiter "(") (#set! indent.close_delimiter ")") . (_))
((argument_list) @aligned_indent ((argument_list) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
((parameters) @aligned_indent ((parameters) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")") (#set! indent.close_delimiter ")")
(#set! "avoid_last_matching_next" 1)) (#set! indent.avoid_last_matching_next 1))
((tuple) @aligned_indent ((tuple) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
(ERROR "[" @aligned_indent (#set! "open_delimiter" "[") (#set! "close_delimiter" "]") . (_)) (ERROR "[" @indent.align (#set! indent.open_delimiter "[") (#set! indent.close_delimiter "]") . (_))
(list "]" @indent_end)
(ERROR "{" @aligned_indent (#set! "open_delimiter" "{") (#set! "close_delimiter" "}") . (_)) (ERROR "{" @indent.align (#set! indent.open_delimiter "{") (#set! indent.close_delimiter "}") . (_))
(dictionary "}" @indent_end)
(set "}" @indent_end)
(parenthesized_expression ")" @indent_end) (parenthesized_expression ")" @indent.end)
(generator_expression ")" @indent_end) (generator_expression ")" @indent.end)
(list_comprehension "]" @indent_end) (list_comprehension "]" @indent.end)
(set_comprehension "}" @indent_end) (set_comprehension "}" @indent.end)
(dictionary_comprehension "}" @indent_end) (dictionary_comprehension "}" @indent.end)
(tuple_pattern ")" @indent_end) (tuple_pattern ")" @indent.end)
(list_pattern "]" @indent_end) (list_pattern "]" @indent.end)
(return_statement (return_statement
[ [
(_) @indent_end (_) @indent.end
(_ (_
[ [
(_) (_)
")" ")"
"}" "}"
"]" "]"
] @indent_end .) ] @indent.end .)
(attribute (attribute
attribute: (_) @indent_end) attribute: (_) @indent.end)
(call (call
arguments: (_ ")" @indent_end)) arguments: (_ ")" @indent.end))
"return" @indent_end "return" @indent.end
] .) ] .)
[ [
@ -115,7 +109,7 @@
(else_clause) (else_clause)
(except_clause) (except_clause)
(finally_clause) (finally_clause)
] @branch ] @indent.branch
(string) @auto (string) @indent.auto

View file

@ -4,20 +4,20 @@
(classMember) (classMember)
(classlessPredicate) (classlessPredicate)
(quantified) (quantified)
] @indent ] @indent.begin
[ [
")" ")"
"}" "}"
] @indent_end ] @indent.end
[ [
")" ")"
"}" "}"
] @branch ] @indent.branch
[ [
(block_comment) (block_comment)
(line_comment) (line_comment)
(qldoc) (qldoc)
] @ignore ] @indent.ignore

View file

@ -1,8 +1,8 @@
[ [
(list) (list)
] @indent ] @indent.begin
[ [
"[" "["
"]" "]"
] @branch ] @indent.begin

View file

@ -10,24 +10,24 @@
"while" "while"
"repeat" "repeat"
"for" "for"
] @indent ] @indent.begin
((binary operator: (special)) @indent) ((binary operator: (special)) @indent.begin)
[ [
"}" "}"
")" ")"
] @branch ] @indent.branch
((formal_parameters (identifier)) @aligned_indent ((formal_parameters (identifier)) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
[ [
")" ")"
"}" "}"
] @indent_end ] @indent.end
[ [
(comment) (comment)
] @ignore ] @indent.ignore

View file

@ -1,5 +1,5 @@
(rule_set) @indent (rule_set) @indent.begin
(block "}" @branch) (block "}" @indent.branch)
(comment) @ignore (comment) @indent.ignore

View file

@ -3,10 +3,10 @@
(map) (map)
(tuple) (tuple)
(struct) (struct)
] @indent ] @indent.begin
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch

View file

@ -19,14 +19,14 @@
(unless) (unless)
(assignment) (assignment)
(parenthesized_statements) (parenthesized_statements)
] @indent ] @indent.begin
[ [
"end" "end"
")" ")"
"}" "}"
"]" "]"
] @indent_end ] @indent.end
[ [
"end" "end"
@ -38,6 +38,6 @@
(else) (else)
(rescue) (rescue)
(ensure) (ensure)
] @branch ] @indent.branch
(comment) @ignore (comment) @indent.ignore

View file

@ -22,38 +22,39 @@
(parameters) (parameters)
(token_tree) (token_tree)
(macro_definition) (macro_definition)
] @indent ] @indent.begin
(trait_item body: (_) @indent) (trait_item body: (_) @indent.begin)
(string_literal (escape_sequence)) @indent (string_literal (escape_sequence)) @indent.begin
(block "}" @indent_end) (block "}" @indent.end)
(enum_item (enum_item
body: (enum_variant_list "}" @indent_end)) body: (enum_variant_list "}" @indent.end))
(impl_item (impl_item
body: (declaration_list "}" @indent_end)) body: (declaration_list "}" @indent.end))
(match_expression (match_expression
body: (match_block "}" @indent_end)) body: (match_block "}" @indent.end))
(mod_item (mod_item
body: (declaration_list "}" @indent_end)) body: (declaration_list "}" @indent.end))
(struct_item (struct_item
body: (field_declaration_list "}" @indent_end)) body: (field_declaration_list "}" @indent.end))
(trait_item (trait_item
body: (declaration_list "}" @indent_end)) body: (declaration_list "}" @indent.end))
(impl_item (where_clause) @dedent) (impl_item (where_clause) @indent.dedent)
[ [
"where" "where"
")" ")"
"]" "]"
"}" "}"
] @branch ] @indent.branch
(impl_item (declaration_list) @branch) (impl_item (declaration_list) @indent.branch)
[ [
(line_comment) (line_comment)
(string_literal) (string_literal)
] @ignore ] @indent.ignore
(raw_string_literal) @auto (raw_string_literal) @indent.auto

View file

@ -4,4 +4,4 @@
(mixin_statement) (mixin_statement)
(while_statement) (while_statement)
(each_statement) (each_statement)
] @indent ] @indent.begin

View file

@ -5,10 +5,10 @@
(handler_body) (handler_body)
(consequence_body) (consequence_body)
(global_single) (global_single)
] @indent ] @indent.begin
"}" @indent_end "}" @indent.end
(comment) @auto (comment) @indent.auto
(string_literal) @auto (string_literal) @indent.auto

View file

@ -9,7 +9,7 @@
(sparse_switch_directive) (sparse_switch_directive)
(subannotation_directive) (subannotation_directive)
(list) (list)
] @indent ] @indent.begin
[ [
".end annotation" ".end annotation"
@ -22,11 +22,11 @@
".end sparse-switch" ".end sparse-switch"
".end subannotation" ".end subannotation"
"}" "}"
] @indent_end ] @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -8,10 +8,10 @@
(data_block) (data_block)
(blank_node_property_list) (blank_node_property_list)
(collection) (collection)
] @indent ] @indent.begin
[ [
"}" "}"
"]" "]"
")" ")"
(triples_same_subject) (triples_same_subject)
] @branch ] @indent.branch

View file

@ -15,39 +15,39 @@
(foreach_statement) (foreach_statement)
; (try_statement) ; (try_statement)
(catch_statement) (catch_statement)
] @indent ] @indent.begin
( (
(if_statement) (if_statement)
(ERROR "else") @indent (ERROR "else") @indent.begin
) )
(if_statement (if_statement
condition: (_) @indent) condition: (_) @indent.begin)
(if_statement (if_statement
consequence: (_) consequence: (_)
(else_statement) @indent) (else_statement) @indent.begin)
(do_while_statement (do_while_statement
"do" "do"
(_) @indent) (_) @indent.begin)
(try_statement (try_statement
(_) @indent (_) @indent.begin
(catch_statement) @indent) (catch_statement) @indent.begin)
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ [
"}" "}"
")" ")"
"]" "]"
] @indent_end ] @indent.end
[ [
(ERROR) (ERROR)
@ -55,4 +55,4 @@
(string) (string)
(verbatim_string) (verbatim_string)
] @auto ] @indent.auto

View file

@ -19,28 +19,28 @@
(lambda) (lambda)
(function_definition) (function_definition)
] @indent ] @indent.begin
(if_statement (if_statement
condition: (parenthesized_expression) @aligned_indent condition: (parenthesized_expression) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")") (#set! indent.close_delimiter ")")
) )
((ERROR "(" . (_)) @aligned_indent ((ERROR "(" . (_)) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
((argument_list) @aligned_indent ((argument_list) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
((argument_list) @aligned_indent ((argument_list) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
((parameters) @aligned_indent ((parameters) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
((tuple) @aligned_indent ((tuple) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
[ [
")" ")"
@ -48,6 +48,6 @@
"}" "}"
(elif_clause) (elif_clause)
(else_clause) (else_clause)
] @branch ] @indent.branch
(string) @auto (string) @indent.auto

View file

@ -13,7 +13,7 @@
(variable_definition_sequence (variable_definition)) (variable_definition_sequence (variable_definition))
(control_structure) (control_structure)
(return_statement) (return_statement)
] @indent ] @indent.begin
[ [
(parameter_call_list (argument_calls)) (parameter_call_list (argument_calls))
@ -23,9 +23,9 @@
"}" "}"
"[" "["
"]" "]"
] @branch ] @indent.branch
[ [
(block_comment) (block_comment)
(line_comment) (line_comment)
] @ignore ] @indent.ignore

View file

@ -3,7 +3,7 @@
(component) (component)
(tag) (tag)
(block) (block)
] @indent ] @indent.begin
; Dedent at the end of each tag, as well as a subblock ; Dedent at the end of each tag, as well as a subblock
[ [
@ -11,4 +11,4 @@
(end_component) (end_component)
(end_block) (end_block)
(subblock) (subblock)
] @branch ] @indent.branch

View file

@ -5,7 +5,7 @@
(await_statement) (await_statement)
(script_element) (script_element)
(style_element) (style_element)
] @indent ] @indent.begin
[ [
(end_tag) (end_tag)
@ -15,6 +15,6 @@
(await_end_expr) (await_end_expr)
">" ">"
"/>" "/>"
] @branch ] @indent.branch
(comment) @ignore (comment) @indent.ignore

View file

@ -9,19 +9,19 @@
(if) (if)
(let) (let)
(value_suffix) (value_suffix)
] @indent ] @indent.begin
[ [
"}" "}"
"]" "]"
")" ")"
">" ">"
] @indent_end ] @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ "<" ">" ] @branch [ "<" ">" ] @indent.branch

View file

@ -6,7 +6,7 @@
(if_statement) (if_statement)
(return_statement) (return_statement)
(while_statement) (while_statement)
] @indent ] @indent.begin
[ [
"{" "{"
@ -15,4 +15,4 @@
")" ")"
"end" "end"
"then" "then"
] @branch ] @indent.branch

View file

@ -1,16 +1,16 @@
(definition) @indent (definition) @indent.begin
((parameters (parameter)) @aligned_indent ((parameters (parameter)) @indent.align
(#set! "open_delimiter" "(") (#set! indent.open_delimiter "(")
(#set! "close_delimiter" ")")) (#set! indent.close_delimiter ")"))
"}" @indent_end "}" @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -1,69 +1,69 @@
; Control flow {{{ ; Control flow {{{
(if_expression) @indent (if_expression) @indent.begin
"then" @branch "then" @indent.branch
"else" @branch "else" @indent.branch
(while_expression) @indent (while_expression) @indent.begin
"do" @branch "do" @indent.branch
(for_expression) @indent (for_expression) @indent.begin
"to" @branch "to" @indent.branch
; }}} ; }}}
; Class {{{ ; Class {{{
(class_declaration) @indent (class_declaration) @indent.begin
(class_declaration "}" @indent_end) (class_declaration "}" @indent.end)
(class_type) @indent (class_type) @indent.begin
(class_type "}" @indent_end) (class_type "}" @indent.end)
; }}} ; }}}
; Groups {{{ ; Groups {{{
(let_expression) @indent (let_expression) @indent.begin
"in" @branch "in" @indent.branch
"end" @branch "end" @indent.branch
(let_expression "end" @indent_end) (let_expression "end" @indent.end)
(sequence_expression) @indent (sequence_expression) @indent.begin
")" @branch ")" @indent.branch
(sequence_expression ")" @indent_end) (sequence_expression ")" @indent.end)
; }}} ; }}}
; Functions and methods {{{ ; Functions and methods {{{
(parameters) @indent (parameters) @indent.begin
(parameters ")" @indent_end) (parameters ")" @indent.end)
(function_call) @indent (function_call) @indent.begin
(method_call) @indent (method_call) @indent.begin
")" @branch ")" @indent.branch
(function_declaration) @indent (function_declaration) @indent.begin
(primitive_declaration) @indent (primitive_declaration) @indent.begin
(method_declaration) @indent (method_declaration) @indent.begin
; }}} ; }}}
; Values and expressions {{{ ; Values and expressions {{{
(array_value) @indent (array_value) @indent.begin
"]" @branch "]" @indent.branch
(array_value "]" @indent_end) (array_value "]" @indent.end)
(array_expression) @indent (array_expression) @indent.begin
"of" @branch "of" @indent.branch
(record_expression) @indent (record_expression) @indent.begin
"}" @branch "}" @indent.branch
(record_expression "}" @indent_end) (record_expression "}" @indent.end)
(record_type) @indent (record_type) @indent.begin
"}" @branch "}" @indent.branch
(record_type "}" @indent_end) (record_type "}" @indent.end)
(variable_declaration) @indent (variable_declaration) @indent.begin
; }}} ; }}}
; Misc{{{ ; Misc{{{
(comment) @ignore (comment) @indent.ignore
(string_literal) @ignore (string_literal) @indent.ignore
; }}} ; }}}
; vim: sw=2 foldmethod=marker ; vim: sw=2 foldmethod=marker

View file

@ -1,11 +1,11 @@
[ [
(array) (array)
(inline_table) (inline_table)
] @indent ] @indent.begin
[ [
"[" "["
"]" "]"
"{" "{"
"}" "}"
] @branch ] @indent.branch

View file

@ -2,9 +2,9 @@
(statement) (statement)
(blank_node_property_list) (blank_node_property_list)
(collection) (collection)
] @indent ] @indent.begin
[ [
"]" "]"
")" ")"
] @branch ] @indent.branch

View file

@ -4,4 +4,4 @@
(enum_declaration) (enum_declaration)
(interface_declaration) (interface_declaration)
(object_type) (object_type)
] @indent ] @indent.begin

View file

@ -1,6 +1,6 @@
(node) @indent (node) @indent.begin
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -1,17 +1,17 @@
(memory_execution) @auto (memory_execution) @indent.auto
[ [
(subroutine) (subroutine)
(brackets) (brackets)
] @indent ] @indent.begin
"}" @indent_end "}" @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -7,11 +7,11 @@
(map) (map)
(call_expression) (call_expression)
(parameter_list)] (parameter_list)]
@indent @indent.begin
[ "}"] [ "}"]
@branch @indent.branch
(parameter_list ")" @branch) (parameter_list ")" @indent.branch)
(comment) @ignore (comment) @indent.ignore

View file

@ -2,6 +2,6 @@
[ [
(template_element) (template_element)
] @indent ] @indent.begin
(template_element (end_tag ">" @indent_end) @branch) (template_element (end_tag ">" @indent.end) @indent.branch)

View file

@ -3,17 +3,17 @@
(compound_statement) (compound_statement)
(loop_statement) (loop_statement)
(struct_declaration) (struct_declaration)
] @indent ] @indent.begin
(compound_statement "}" @indent_end) (compound_statement "}" @indent.end)
(loop_statement "}" @indent_end) (loop_statement "}" @indent.end)
(function_declaration ")" @indent_end) (function_declaration ")" @indent.end)
(struct_declaration "}" @indent_end) (struct_declaration "}" @indent.end)
[ [
"else" "else"
")" ")"
"}" "}"
] @branch ] @indent.branch
[(line_comment) (block_comment)] @auto [(line_comment) (block_comment)] @indent.auto

View file

@ -4,4 +4,4 @@
"#ifndef" "#ifndef"
"#else" "#else"
"#endif" "#endif"
] @zero_indent ] @indent.zero

View file

@ -1,6 +1,6 @@
[ [
(block_mapping_pair value: (block_node)) (block_mapping_pair value: (block_node))
(block_sequence_item) (block_sequence_item)
] @indent ] @indent.begin
(ERROR) @auto (ERROR) @indent.auto

View file

@ -1,11 +1,11 @@
(module) @indent (module) @indent.begin
(submodule) @indent (submodule) @indent.begin
(statement) @indent (statement) @indent.begin
(extension_statement) @indent (extension_statement) @indent.begin
(statement ";" @indent_end) (statement ";" @indent.end)
(extension_statement ";" @indent_end) (extension_statement ";" @indent.end)
(block "}" @indent_end @branch) (block "}" @indent.end @indent.branch)
((string) @aligned_indent ((string) @indent.align
(#set! "open_delimiter" "\"") (#set! indent.open_delimiter "\"")
(#set! "close_delimiter" "\"")) (#set! indent.close_delimiter "\""))

View file

@ -5,22 +5,22 @@
(json_array) (json_array)
(json_object) (json_object)
(parenthesized_expression) (parenthesized_expression)
] @indent ] @indent.begin
; TODO: can't get this to work, goal is to indent at the property ":" prefix ; TODO: can't get this to work, goal is to indent at the property ":" prefix
; ((list (identifier) (property)) @aligned_indent ; ((list (identifier) (property)) @indent.align
; (#set! "open_delimiter" "(") ; (#set! indent.open_delimiter "(")
; (#set! "close_delimiter" ")")) ; (#set! indent.close_delimiter ")"))
[")" "}" "]"] @indent_end [")" "}" "]"] @indent.end
[ "{" "}" ] @branch [ "{" "}" ] @indent.branch
[ "(" ")" ] @branch [ "(" ")" ] @indent.branch
[ "[" "]" ] @branch [ "[" "]" ] @indent.branch
[ [
(ERROR) (ERROR)
(comment) (comment)
] @auto ] @indent.auto

View file

@ -3,9 +3,9 @@
(ContainerDecl) (ContainerDecl)
(SwitchExpr) (SwitchExpr)
(InitList) (InitList)
] @indent ] @indent.begin
(Block "}" @indent_end) (Block "}" @indent.end)
[ [
"(" "("
@ -14,11 +14,11 @@
"]" "]"
"{" "{"
"}" "}"
] @branch ] @indent.branch
[ [
(line_comment) (line_comment)
(container_doc_comment) (container_doc_comment)
(doc_comment) (doc_comment)
(LINESTRING) (LINESTRING)
] @ignore ] @indent.ignore