Skip to content
5 changes: 3 additions & 2 deletions diffr/crates/diffr-core/src/parse/queries/ada/folds.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
((comment)+ @fold . (_))
(if_statement statements: (_) @fold @fold.indent statements: (_)* @fold)
(if_statement else_statements: (_) @fold @fold.indent else_statements: (_)* @fold)
; A statement may fold itself, so the token before a body owns its fold.
(if_statement "then" @fold . statements: (_) @fold.indent statements: (_)* @fold)
(if_statement "else" @fold @fold.open . (_) @fold.indent "end" @fold @fold.close)
(handled_sequence_of_statements . (_) @fold.indent) @fold
2 changes: 1 addition & 1 deletion diffr/crates/diffr-core/src/parse/queries/bash/folds.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(array "(" @fold.open . (_) @fold.indent ")" @fold.close) @fold
(do_group "do" @fold.open . (_) @fold.indent "done" @fold.close) @fold
((comment)+ @fold . (_))
(else_clause "else" . (_) @fold @fold.indent (_)* @fold)
(else_clause "else" @fold.open . (_) @fold.indent) @fold
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(argument_list "(" @fold.open . (_) @fold.indent ")" @fold.close) @fold
(argument_list . "(" @fold.open . (_) @fold.indent ")" @fold.close .) @fold
((comment)+ @fold . (_))
10 changes: 5 additions & 5 deletions diffr/crates/diffr-core/src/parse/queries/go/folds.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
; folds whichever plugin imports this file. Comments are left to
; docstrings.scm, which folds a run of them as one region. These patterns
; set no tags; the plugins that import them tag what they need.
; gofmt outdents labels, so a labelled statement gives the indent.
((block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold
; gofmt outdents a label on its own line, so the statement it labels gives
; the indent.
((block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n"))
((block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n"))
(field_declaration_list "{" @fold.open . (_) @fold.indent "}" @fold.close) @fold
(literal_value "{" @fold.open . (_) @fold.indent "}" @fold.close) @fold
Expand Down
2 changes: 1 addition & 1 deletion diffr/crates/diffr-core/src/parse/queries/julia/folds.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
((line_comment)+ @fold . (_))
(else_clause "else" @fold.open . (_) @fold.indent) @fold
(elseif_clause "elseif" @fold.open . (_) @fold.indent) @fold
(if_statement condition: (_) @fold @fold.open . (_) @fold.indent "end" @fold @fold.close)
(if_statement "if" @fold condition: (_) @fold.open . (_) @fold.indent "end" @fold @fold.close)
2 changes: 1 addition & 1 deletion diffr/crates/diffr-core/src/parse/queries/python/folds.scm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(list "[" @fold.open . (_) @fold.indent "]" @fold.close)
(dictionary "{" @fold.open . (_) @fold.indent "}" @fold.close)
(set "{" @fold.open . (_) @fold.indent "}" @fold.close)
(tuple "(" @fold.open . (_) @fold.indent ")" @fold.close)
(tuple . "(" @fold.open . (_) @fold.indent ")" @fold.close)
] @fold
((tuple) @fold (#not-match? @fold "^\\("))
[
Expand Down
6 changes: 4 additions & 2 deletions diffr/crates/diffr-core/src/parse/queries/sql/folds.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
((comment_statement)+ @fold . (_))
(select_expression . (_) @fold.indent) @fold

(function_body (keyword_begin) @fold.open . (_) @fold.indent (keyword_end) @fold.close) @fold
(function_body (keyword_as) (dollar_quote) @fold.open . [(statement) (keyword_return)] @fold.indent (dollar_quote) @fold.close) @fold
(function_body (keyword_begin) @fold.open . (keyword_atomic) @fold.indent (keyword_end) @fold.close) @fold
(function_body (keyword_as) . (dollar_quote) . (keyword_begin) @fold.open . (_) @fold.indent (keyword_end) @fold.close) @fold
(function_body (keyword_as) . (dollar_quote) . (keyword_declare) (keyword_begin) @fold.open . (_) @fold.indent (keyword_end) @fold.close) @fold
(function_body (keyword_as) . (dollar_quote) @fold.open . [(statement) (keyword_return)] @fold.indent (dollar_quote) @fold.close) @fold
Binary file modified diffr/plugins/shape/context/plugin.wasm
Binary file not shown.
5 changes: 2 additions & 3 deletions diffr/plugins/shape/context/queries/ada.scm
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
(exception_handler)
] @fold (#set! tag "context:clause"))

((if_statement statements: (_) @fold @fold.indent statements: (_)* @fold) (#set! tag "context:body"))
((if_statement else_statements: (_) @fold @fold.indent else_statements: (_)* @fold) (#set! tag "context:body"))
((if_statement "else" @fold) (#set! tag "context:relevant"))
((if_statement "then" @fold . statements: (_) @fold.indent statements: (_)* @fold) (#set! tag "context:body"))
((if_statement "else" @fold @fold.open . (_) @fold.indent "end" @fold @fold.close) (#set! tag "context:body"))
((if_statement "elsif" @fold) (#set! tag "context:relevant"))
((handled_sequence_of_statements . (_) @fold.indent) @fold (#set! tag "context:body"))

Expand Down
6 changes: 2 additions & 4 deletions diffr/plugins/shape/context/queries/bash.scm
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
(case_item)
(case_statement)
(elif_clause)
(else_clause)
] @fold (#set! tag "context:clause"))

((else_clause "else" . (_) @fold @fold.indent (_)* @fold) (#set! tag "context:body"))

((else_clause) @fold (#set! tag "context:scope"))
((else_clause "else" @fold.open . (_) @fold.indent) @fold (#set! tag "context:body"))
((else_clause "else" @fold (_) @fold .) (#set! tag "context:scope") (#set! tag "context:clause"))
2 changes: 1 addition & 1 deletion diffr/plugins/shape/context/queries/devicetree.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; inherits: builtin:core/queries/devicetree/folds.scm
((argument_list "(" @fold.open . (_) @fold.indent ")" @fold.close) @fold (#set! tag "context:body"))
((argument_list . "(" @fold.open . (_) @fold.indent ")" @fold.close .) @fold (#set! tag "context:body"))
([
(call_expression)
(conditional_expression)
Expand Down
8 changes: 4 additions & 4 deletions diffr/plugins/shape/context/queries/go.scm
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
((select_statement) @fold
(#set! tag "context:scope"))

((block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold
((block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "context:body"))
((block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "context:body"))
((field_declaration_list "{" @fold.open . (_) @fold.indent "}" @fold.close) @fold (#set! tag "context:body"))
Expand Down
4 changes: 2 additions & 2 deletions diffr/plugins/shape/context/queries/julia.scm
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
((comprehension_expression (if_clause) @fold) (#set! tag "context:relevant"))
((else_clause "else" @fold.open . (_) @fold.indent) @fold (#set! tag "context:body"))
((elseif_clause "elseif" @fold.open . (_) @fold.indent) @fold (#set! tag "context:body"))
((if_statement condition: (_) @fold @fold.open . (_) @fold.indent "end" @fold @fold.close) (#set! tag "context:body"))
((if_statement condition: (_) @fold @fold.open . (_) @fold.indent "end" @fold @fold.close) (#set! tag "context:branches"))
((if_statement "if" @fold condition: (_) @fold.open . (_) @fold.indent "end" @fold @fold.close) (#set! tag "context:body"))
((if_statement "if" @fold condition: (_) @fold.open . (_) @fold.indent "end" @fold @fold.close) (#set! tag "context:branches"))
2 changes: 1 addition & 1 deletion diffr/plugins/shape/context/queries/python.scm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(list "[" @fold.open . (_) @fold.indent "]" @fold.close)
(dictionary "{" @fold.open . (_) @fold.indent "}" @fold.close)
(set "{" @fold.open . (_) @fold.indent "}" @fold.close)
(tuple "(" @fold.open . (_) @fold.indent ")" @fold.close)
(tuple . "(" @fold.open . (_) @fold.indent ")" @fold.close)
] @fold (#set! tag "context:body"))

((argument_list "(" @fold.open . (_) @fold.indent ")" @fold.close) @fold
Expand Down
6 changes: 4 additions & 2 deletions diffr/plugins/shape/context/queries/sql.scm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
((create_function [(function_language) (function_security) (function_volatility)
(function_leakproof) (function_safety) (function_strictness) (function_cost)
(function_rows) (function_support)] @fold) (#set! tag "context:relevant"))
([(function_body (keyword_begin) @fold.open . (_) @fold.indent (keyword_end) @fold.close)
(function_body (keyword_as) (dollar_quote) @fold.open . [(statement) (keyword_return)] @fold.indent (dollar_quote) @fold.close)] @fold (#set! tag "context:body"))
([(function_body (keyword_begin) @fold.open . (keyword_atomic) @fold.indent (keyword_end) @fold.close)
(function_body (keyword_as) . (dollar_quote) . (keyword_begin) @fold.open . (_) @fold.indent (keyword_end) @fold.close)
(function_body (keyword_as) . (dollar_quote) . (keyword_declare) (keyword_begin) @fold.open . (_) @fold.indent (keyword_end) @fold.close)
(function_body (keyword_as) . (dollar_quote) @fold.open . [(statement) (keyword_return)] @fold.indent (dollar_quote) @fold.close)] @fold (#set! tag "context:body"))
((create_function (function_body (keyword_end) @fold . ";" @fold . (dollar_quote) @fold)) (#set! tag "context:relevant"))
2 changes: 1 addition & 1 deletion diffr/plugins/shape/context/queries/yaml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

((block_mapping) @fold (#set! tag "context:open-ended"))
((block_mapping_pair) @fold (#set! tag "context:open-ended"))
((block_sequence) @fold (#set! tag "context:open-ended"))
((block_sequence . (_) @fold.indent) @fold (#set! tag "context:open-ended"))
((block_sequence_item) @fold (#set! tag "context:open-ended"))
((block_sequence . (_) @fold.indent) @fold (#set! tag "context:body"))

Binary file modified diffr/plugins/shape/deleted-bodies/plugin.wasm
Binary file not shown.
16 changes: 8 additions & 8 deletions diffr/plugins/shape/deleted-bodies/queries/go.scm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
; inherits: builtin:core/queries/go/folds.scm, builtin:core/queries/go/docstrings.scm
((function_declaration body: (block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold)
((function_declaration body: (block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold)
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "deleted-bodies:function"))
((function_declaration body: (block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold)
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "deleted-bodies:function"))
((method_declaration body: (block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold)
((method_declaration body: (block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold)
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "deleted-bodies:function"))
((method_declaration body: (block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold)
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "deleted-bodies:function"))
Binary file modified diffr/plugins/shape/removed-runs/plugin.wasm
Binary file not shown.
16 changes: 8 additions & 8 deletions diffr/plugins/shape/removed-runs/queries/go.scm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
; inherits: builtin:core/queries/go/folds.scm
((function_declaration body: (block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold)
((function_declaration body: (block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold)
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "removed-runs:function"))
((function_declaration body: (block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold)
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "removed-runs:function"))
((method_declaration body: (block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold)
((method_declaration body: (block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold)
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "removed-runs:function"))
((method_declaration body: (block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold)
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "removed-runs:function"))
10 changes: 6 additions & 4 deletions diffr/plugins/shape/shared/queries/go-tests.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
; Test bodies, tagged for every plugin that treats tests specially.
((function_declaration name: (identifier) @_name body: (block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold)
((function_declaration name: (identifier) @_name body: (block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold)
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#match? @_name "^Test")
(#set! tag "summarize:test")
(#set! tag "test-bodies:test"))
((function_declaration name: (identifier) @_name body: (block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold)
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#match? @_name "^Test")
(#set! tag "summarize:test")
Expand Down
Binary file modified diffr/plugins/shape/summarize/plugin.wasm
Binary file not shown.
16 changes: 8 additions & 8 deletions diffr/plugins/shape/summarize/queries/go.scm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
; inherits: builtin:core/queries/go/folds.scm, builtin:core/queries/go/docstrings.scm, builtin:shared/queries/go-tests.scm
((function_declaration body: (block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold)
((function_declaration body: (block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold)
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "summarize:function"))
((function_declaration body: (block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold)
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "summarize:function"))
((method_declaration body: (block "{" @fold.open (statement_list . [
(labeled_statement (label_name) . (_) @fold.indent)
(_) @fold.indent
]) "}" @fold.close) @fold)
((method_declaration body: (block "{" @fold.open (statement_list . (labeled_statement (label_name) . (_) @fold.indent) @_first) "}" @fold.close) @fold)
(#match? @_first "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "summarize:function"))
((method_declaration body: (block "{" @fold.open (statement_list . (_) @fold.indent) "}" @fold.close) @fold)
(#not-match? @fold.indent "^[A-Za-z_][A-Za-z0-9_]*:\\s*\n")
(#set! tag "summarize:function"))
Binary file modified diffr/plugins/shape/test-bodies/plugin.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions diffr/tests/fixtures/context-contracts/ada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ end Send;
8 - Dispatch (previous);
8 + Dispatch (updated);
9 9 After;
… base 10–12 / head 10–12 collapsed [fold_state_id=33] …
… base 10–12 / head 10–12 collapsed [fold_state_id=31] …
13 13 else
… base 14–16 / head 14–16 collapsed [fold_state_id=11] …
… base 14–16 / head 14–16 collapsed [fold_state_id=10] …
17 17 end if;
18 18 end Send;

Expand Down
Loading