diff --git a/diffr/crates/diffr-core/src/parse/queries/ada/folds.scm b/diffr/crates/diffr-core/src/parse/queries/ada/folds.scm index a9521b069..449ab24cf 100644 --- a/diffr/crates/diffr-core/src/parse/queries/ada/folds.scm +++ b/diffr/crates/diffr-core/src/parse/queries/ada/folds.scm @@ -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 diff --git a/diffr/crates/diffr-core/src/parse/queries/bash/folds.scm b/diffr/crates/diffr-core/src/parse/queries/bash/folds.scm index ddc1675bf..96f3eb082 100644 --- a/diffr/crates/diffr-core/src/parse/queries/bash/folds.scm +++ b/diffr/crates/diffr-core/src/parse/queries/bash/folds.scm @@ -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 diff --git a/diffr/crates/diffr-core/src/parse/queries/devicetree/folds.scm b/diffr/crates/diffr-core/src/parse/queries/devicetree/folds.scm index 2c7f4507d..c34bdc2da 100644 --- a/diffr/crates/diffr-core/src/parse/queries/devicetree/folds.scm +++ b/diffr/crates/diffr-core/src/parse/queries/devicetree/folds.scm @@ -1,2 +1,2 @@ -(argument_list "(" @fold.open . (_) @fold.indent ")" @fold.close) @fold +(argument_list . "(" @fold.open . (_) @fold.indent ")" @fold.close .) @fold ((comment)+ @fold . (_)) diff --git a/diffr/crates/diffr-core/src/parse/queries/go/folds.scm b/diffr/crates/diffr-core/src/parse/queries/go/folds.scm index 9467b81e1..bc93d6113 100644 --- a/diffr/crates/diffr-core/src/parse/queries/go/folds.scm +++ b/diffr/crates/diffr-core/src/parse/queries/go/folds.scm @@ -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 diff --git a/diffr/crates/diffr-core/src/parse/queries/julia/folds.scm b/diffr/crates/diffr-core/src/parse/queries/julia/folds.scm index 238cf06ed..496706eef 100644 --- a/diffr/crates/diffr-core/src/parse/queries/julia/folds.scm +++ b/diffr/crates/diffr-core/src/parse/queries/julia/folds.scm @@ -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) diff --git a/diffr/crates/diffr-core/src/parse/queries/python/folds.scm b/diffr/crates/diffr-core/src/parse/queries/python/folds.scm index c8c8120e3..cca3268bb 100644 --- a/diffr/crates/diffr-core/src/parse/queries/python/folds.scm +++ b/diffr/crates/diffr-core/src/parse/queries/python/folds.scm @@ -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 "^\\(")) [ diff --git a/diffr/crates/diffr-core/src/parse/queries/sql/folds.scm b/diffr/crates/diffr-core/src/parse/queries/sql/folds.scm index 5193f5c5d..0998979e7 100644 --- a/diffr/crates/diffr-core/src/parse/queries/sql/folds.scm +++ b/diffr/crates/diffr-core/src/parse/queries/sql/folds.scm @@ -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 diff --git a/diffr/plugins/shape/context/plugin.wasm b/diffr/plugins/shape/context/plugin.wasm index 5f7e6cc2f..ee9d704a0 100644 Binary files a/diffr/plugins/shape/context/plugin.wasm and b/diffr/plugins/shape/context/plugin.wasm differ diff --git a/diffr/plugins/shape/context/queries/ada.scm b/diffr/plugins/shape/context/queries/ada.scm index 62b31b825..b94588c75 100644 --- a/diffr/plugins/shape/context/queries/ada.scm +++ b/diffr/plugins/shape/context/queries/ada.scm @@ -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")) diff --git a/diffr/plugins/shape/context/queries/bash.scm b/diffr/plugins/shape/context/queries/bash.scm index 532872209..f10ef2647 100644 --- a/diffr/plugins/shape/context/queries/bash.scm +++ b/diffr/plugins/shape/context/queries/bash.scm @@ -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")) diff --git a/diffr/plugins/shape/context/queries/devicetree.scm b/diffr/plugins/shape/context/queries/devicetree.scm index 4bc321d6a..9dead7313 100644 --- a/diffr/plugins/shape/context/queries/devicetree.scm +++ b/diffr/plugins/shape/context/queries/devicetree.scm @@ -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) diff --git a/diffr/plugins/shape/context/queries/go.scm b/diffr/plugins/shape/context/queries/go.scm index b89fa07de..3e56a4e93 100644 --- a/diffr/plugins/shape/context/queries/go.scm +++ b/diffr/plugins/shape/context/queries/go.scm @@ -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")) diff --git a/diffr/plugins/shape/context/queries/julia.scm b/diffr/plugins/shape/context/queries/julia.scm index cbf325ad5..f82b43cff 100644 --- a/diffr/plugins/shape/context/queries/julia.scm +++ b/diffr/plugins/shape/context/queries/julia.scm @@ -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")) diff --git a/diffr/plugins/shape/context/queries/python.scm b/diffr/plugins/shape/context/queries/python.scm index af35bbb77..6a579a1b9 100644 --- a/diffr/plugins/shape/context/queries/python.scm +++ b/diffr/plugins/shape/context/queries/python.scm @@ -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 diff --git a/diffr/plugins/shape/context/queries/sql.scm b/diffr/plugins/shape/context/queries/sql.scm index 9c0e543de..5ca4d0d9b 100644 --- a/diffr/plugins/shape/context/queries/sql.scm +++ b/diffr/plugins/shape/context/queries/sql.scm @@ -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")) diff --git a/diffr/plugins/shape/context/queries/yaml.scm b/diffr/plugins/shape/context/queries/yaml.scm index 27c83560a..a7e4d5a29 100644 --- a/diffr/plugins/shape/context/queries/yaml.scm +++ b/diffr/plugins/shape/context/queries/yaml.scm @@ -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")) diff --git a/diffr/plugins/shape/deleted-bodies/plugin.wasm b/diffr/plugins/shape/deleted-bodies/plugin.wasm index 9f56e8ca5..dfa47cda6 100644 Binary files a/diffr/plugins/shape/deleted-bodies/plugin.wasm and b/diffr/plugins/shape/deleted-bodies/plugin.wasm differ diff --git a/diffr/plugins/shape/deleted-bodies/queries/go.scm b/diffr/plugins/shape/deleted-bodies/queries/go.scm index e2b01f948..22b28af80 100644 --- a/diffr/plugins/shape/deleted-bodies/queries/go.scm +++ b/diffr/plugins/shape/deleted-bodies/queries/go.scm @@ -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")) diff --git a/diffr/plugins/shape/removed-runs/plugin.wasm b/diffr/plugins/shape/removed-runs/plugin.wasm index 6a0ad72d2..b833d1227 100644 Binary files a/diffr/plugins/shape/removed-runs/plugin.wasm and b/diffr/plugins/shape/removed-runs/plugin.wasm differ diff --git a/diffr/plugins/shape/removed-runs/queries/go.scm b/diffr/plugins/shape/removed-runs/queries/go.scm index dd6585957..1b6d69418 100644 --- a/diffr/plugins/shape/removed-runs/queries/go.scm +++ b/diffr/plugins/shape/removed-runs/queries/go.scm @@ -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")) diff --git a/diffr/plugins/shape/shared/queries/go-tests.scm b/diffr/plugins/shape/shared/queries/go-tests.scm index 5b231c998..76e06c772 100644 --- a/diffr/plugins/shape/shared/queries/go-tests.scm +++ b/diffr/plugins/shape/shared/queries/go-tests.scm @@ -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") diff --git a/diffr/plugins/shape/summarize/plugin.wasm b/diffr/plugins/shape/summarize/plugin.wasm index e36a3e4fb..b351ac257 100644 Binary files a/diffr/plugins/shape/summarize/plugin.wasm and b/diffr/plugins/shape/summarize/plugin.wasm differ diff --git a/diffr/plugins/shape/summarize/queries/go.scm b/diffr/plugins/shape/summarize/queries/go.scm index 92c665974..b6eb715cd 100644 --- a/diffr/plugins/shape/summarize/queries/go.scm +++ b/diffr/plugins/shape/summarize/queries/go.scm @@ -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")) diff --git a/diffr/plugins/shape/test-bodies/plugin.wasm b/diffr/plugins/shape/test-bodies/plugin.wasm index ef4fbdb64..b47721689 100644 Binary files a/diffr/plugins/shape/test-bodies/plugin.wasm and b/diffr/plugins/shape/test-bodies/plugin.wasm differ diff --git a/diffr/tests/fixtures/context-contracts/ada.rs b/diffr/tests/fixtures/context-contracts/ada.rs index b611da3c7..bc3c91e5d 100644 --- a/diffr/tests/fixtures/context-contracts/ada.rs +++ b/diffr/tests/fixtures/context-contracts/ada.rs @@ -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;