git.delta.rocks / jrsonnet / refs/commits / 9b1cb43cbd7b

difftreelog

fix(fmt) differentiate between nodes of the same type

qkluvrtkYaroslav Bolyukin2026-02-08parent: #0c7230b.patch.diff
in: master

4 files changed

addedcrates/jrsonnet-formatter/src/snapshots/jrsonnet_formatter__tests__asserts.snapdiffbeforeafterboth

no changes

modifiedcrates/jrsonnet-formatter/src/tests.rsdiffbeforeafterboth
92 )));92 )));
93}93}
94
95#[test]
96fn asserts() {
97 insta::assert_snapshot!(reformat(indoc!(
98 "
99 {
100 assert 1 > 0 : 'one should be greater than zero',
101 assert true,
102 value: 42,
103 }
104 "
105 )));
106}
94107
modifiedcrates/jrsonnet-rowan-parser/src/generated/nodes.rsdiffbeforeafterboth
14}14}
15impl SourceFile {15impl SourceFile {
16 pub fn expr(&self) -> Option<Expr> {16 pub fn expr(&self) -> Option<Expr> {
17 support::child(&self.syntax)17 support::children(&self.syntax).next()
18 }18 }
19}19}
2020
27 support::children(&self.syntax)27 support::children(&self.syntax)
28 }28 }
29 pub fn expr_base(&self) -> Option<ExprBase> {29 pub fn expr_base(&self) -> Option<ExprBase> {
30 support::child(&self.syntax)30 support::children(&self.syntax).next()
31 }31 }
32 pub fn suffixs(&self) -> AstChildren<Suffix> {32 pub fn suffixs(&self) -> AstChildren<Suffix> {
33 support::children(&self.syntax)33 support::children(&self.syntax)
46 support::token(&self.syntax, T![.])46 support::token(&self.syntax, T![.])
47 }47 }
48 pub fn index(&self) -> Option<Name> {48 pub fn index(&self) -> Option<Name> {
49 support::child(&self.syntax)49 support::children(&self.syntax).next()
50 }50 }
51}51}
5252
75 support::token(&self.syntax, T!['['])75 support::token(&self.syntax, T!['['])
76 }76 }
77 pub fn index(&self) -> Option<Expr> {77 pub fn index(&self) -> Option<Expr> {
78 support::child(&self.syntax)78 support::children(&self.syntax).next()
79 }79 }
80 pub fn r_brack_token(&self) -> Option<SyntaxToken> {80 pub fn r_brack_token(&self) -> Option<SyntaxToken> {
81 support::token(&self.syntax, T![']'])81 support::token(&self.syntax, T![']'])
88}88}
89impl SuffixSlice {89impl SuffixSlice {
90 pub fn slice_desc(&self) -> Option<SliceDesc> {90 pub fn slice_desc(&self) -> Option<SliceDesc> {
91 support::child(&self.syntax)91 support::children(&self.syntax).next()
92 }92 }
93}93}
9494
101 support::token(&self.syntax, T!['['])101 support::token(&self.syntax, T!['['])
102 }102 }
103 pub fn from(&self) -> Option<Expr> {103 pub fn from(&self) -> Option<Expr> {
104 support::child(&self.syntax)104 support::children(&self.syntax).next()
105 }105 }
106 pub fn colon_token(&self) -> Option<SyntaxToken> {106 pub fn colon_token(&self) -> Option<SyntaxToken> {
107 support::token(&self.syntax, T![:])107 support::token(&self.syntax, T![:])
108 }108 }
109 pub fn end(&self) -> Option<SliceDescEnd> {109 pub fn end(&self) -> Option<SliceDescEnd> {
110 support::child(&self.syntax)110 support::children(&self.syntax).next()
111 }111 }
112 pub fn step(&self) -> Option<SliceDescStep> {112 pub fn step(&self) -> Option<SliceDescStep> {
113 support::child(&self.syntax)113 support::children(&self.syntax).next()
114 }114 }
115 pub fn r_brack_token(&self) -> Option<SyntaxToken> {115 pub fn r_brack_token(&self) -> Option<SyntaxToken> {
116 support::token(&self.syntax, T![']'])116 support::token(&self.syntax, T![']'])
123}123}
124impl SuffixApply {124impl SuffixApply {
125 pub fn args_desc(&self) -> Option<ArgsDesc> {125 pub fn args_desc(&self) -> Option<ArgsDesc> {
126 support::child(&self.syntax)126 support::children(&self.syntax).next()
127 }127 }
128 pub fn tailstrict_kw_token(&self) -> Option<SyntaxToken> {128 pub fn tailstrict_kw_token(&self) -> Option<SyntaxToken> {
129 support::token(&self.syntax, T![tailstrict])129 support::token(&self.syntax, T![tailstrict])
168}168}
169impl StmtAssert {169impl StmtAssert {
170 pub fn assertion(&self) -> Option<Assertion> {170 pub fn assertion(&self) -> Option<Assertion> {
171 support::child(&self.syntax)171 support::children(&self.syntax).next()
172 }172 }
173 pub fn semi_token(&self) -> Option<SyntaxToken> {173 pub fn semi_token(&self) -> Option<SyntaxToken> {
174 support::token(&self.syntax, T![;])174 support::token(&self.syntax, T![;])
184 support::token(&self.syntax, T![assert])184 support::token(&self.syntax, T![assert])
185 }185 }
186 pub fn condition(&self) -> Option<Expr> {186 pub fn condition(&self) -> Option<Expr> {
187 support::child(&self.syntax)187 support::children(&self.syntax).next()
188 }188 }
189 pub fn colon_token(&self) -> Option<SyntaxToken> {189 pub fn colon_token(&self) -> Option<SyntaxToken> {
190 support::token(&self.syntax, T![:])190 support::token(&self.syntax, T![:])
191 }191 }
192 pub fn message(&self) -> Option<Expr> {192 pub fn message(&self) -> Option<Expr> {
193 support::child(&self.syntax)193 support::children(&self.syntax).nth(1usize)
194 }194 }
195}195}
196196
200}200}
201impl ExprBinary {201impl ExprBinary {
202 pub fn lhs(&self) -> Option<Expr> {202 pub fn lhs(&self) -> Option<Expr> {
203 support::child(&self.syntax)203 support::children(&self.syntax).next()
204 }204 }
205 pub fn binary_operator(&self) -> Option<BinaryOperator> {205 pub fn binary_operator(&self) -> Option<BinaryOperator> {
206 support::token_child(&self.syntax)206 support::token_child(&self.syntax)
207 }207 }
208 pub fn rhs(&self) -> Option<Expr> {208 pub fn rhs(&self) -> Option<Expr> {
209 support::child(&self.syntax)209 support::children(&self.syntax).nth(1usize)
210 }210 }
211}211}
212212
219 support::token_child(&self.syntax)219 support::token_child(&self.syntax)
220 }220 }
221 pub fn rhs(&self) -> Option<Expr> {221 pub fn rhs(&self) -> Option<Expr> {
222 support::child(&self.syntax)222 support::children(&self.syntax).next()
223 }223 }
224}224}
225225
229}229}
230impl ExprObjExtend {230impl ExprObjExtend {
231 pub fn expr(&self) -> Option<Expr> {231 pub fn expr(&self) -> Option<Expr> {
232 support::child(&self.syntax)232 support::children(&self.syntax).next()
233 }233 }
234}234}
235235
242 support::token(&self.syntax, T!['('])242 support::token(&self.syntax, T!['('])
243 }243 }
244 pub fn expr(&self) -> Option<Expr> {244 pub fn expr(&self) -> Option<Expr> {
245 support::child(&self.syntax)245 support::children(&self.syntax).next()
246 }246 }
247 pub fn r_paren_token(&self) -> Option<SyntaxToken> {247 pub fn r_paren_token(&self) -> Option<SyntaxToken> {
248 support::token(&self.syntax, T![')'])248 support::token(&self.syntax, T![')'])
301}301}
302impl ExprObject {302impl ExprObject {
303 pub fn obj_body(&self) -> Option<ObjBody> {303 pub fn obj_body(&self) -> Option<ObjBody> {
304 support::child(&self.syntax)304 support::children(&self.syntax).next()
305 }305 }
306}306}
307307
314 support::token(&self.syntax, T!['['])314 support::token(&self.syntax, T!['['])
315 }315 }
316 pub fn expr(&self) -> Option<Expr> {316 pub fn expr(&self) -> Option<Expr> {
317 support::child(&self.syntax)317 support::children(&self.syntax).next()
318 }318 }
319 pub fn comma_token(&self) -> Option<SyntaxToken> {319 pub fn comma_token(&self) -> Option<SyntaxToken> {
320 support::token(&self.syntax, T![,])320 support::token(&self.syntax, T![,])
346}346}
347impl ExprVar {347impl ExprVar {
348 pub fn name(&self) -> Option<Name> {348 pub fn name(&self) -> Option<Name> {
349 support::child(&self.syntax)349 support::children(&self.syntax).next()
350 }350 }
351}351}
352352
359 support::token(&self.syntax, T![if])359 support::token(&self.syntax, T![if])
360 }360 }
361 pub fn cond(&self) -> Option<Expr> {361 pub fn cond(&self) -> Option<Expr> {
362 support::child(&self.syntax)362 support::children(&self.syntax).next()
363 }363 }
364 pub fn then_kw_token(&self) -> Option<SyntaxToken> {364 pub fn then_kw_token(&self) -> Option<SyntaxToken> {
365 support::token(&self.syntax, T![then])365 support::token(&self.syntax, T![then])
366 }366 }
367 pub fn then(&self) -> Option<TrueExpr> {367 pub fn then(&self) -> Option<TrueExpr> {
368 support::child(&self.syntax)368 support::children(&self.syntax).next()
369 }369 }
370 pub fn else_kw_token(&self) -> Option<SyntaxToken> {370 pub fn else_kw_token(&self) -> Option<SyntaxToken> {
371 support::token(&self.syntax, T![else])371 support::token(&self.syntax, T![else])
372 }372 }
373 pub fn else_(&self) -> Option<FalseExpr> {373 pub fn else_(&self) -> Option<FalseExpr> {
374 support::child(&self.syntax)374 support::children(&self.syntax).next()
375 }375 }
376}376}
377377
381}381}
382impl TrueExpr {382impl TrueExpr {
383 pub fn expr(&self) -> Option<Expr> {383 pub fn expr(&self) -> Option<Expr> {
384 support::child(&self.syntax)384 support::children(&self.syntax).next()
385 }385 }
386}386}
387387
391}391}
392impl FalseExpr {392impl FalseExpr {
393 pub fn expr(&self) -> Option<Expr> {393 pub fn expr(&self) -> Option<Expr> {
394 support::child(&self.syntax)394 support::children(&self.syntax).next()
395 }395 }
396}396}
397397
407 support::token(&self.syntax, T!['('])407 support::token(&self.syntax, T!['('])
408 }408 }
409 pub fn params_desc(&self) -> Option<ParamsDesc> {409 pub fn params_desc(&self) -> Option<ParamsDesc> {
410 support::child(&self.syntax)410 support::children(&self.syntax).next()
411 }411 }
412 pub fn r_paren_token(&self) -> Option<SyntaxToken> {412 pub fn r_paren_token(&self) -> Option<SyntaxToken> {
413 support::token(&self.syntax, T![')'])413 support::token(&self.syntax, T![')'])
414 }414 }
415 pub fn expr(&self) -> Option<Expr> {415 pub fn expr(&self) -> Option<Expr> {
416 support::child(&self.syntax)416 support::children(&self.syntax).next()
417 }417 }
418}418}
419419
442 support::token(&self.syntax, T![error])442 support::token(&self.syntax, T![error])
443 }443 }
444 pub fn expr(&self) -> Option<Expr> {444 pub fn expr(&self) -> Option<Expr> {
445 support::child(&self.syntax)445 support::children(&self.syntax).next()
446 }446 }
447}447}
448448
452}452}
453impl SliceDescEnd {453impl SliceDescEnd {
454 pub fn expr(&self) -> Option<Expr> {454 pub fn expr(&self) -> Option<Expr> {
455 support::child(&self.syntax)455 support::children(&self.syntax).next()
456 }456 }
457}457}
458458
462}462}
463impl SliceDescStep {463impl SliceDescStep {
464 pub fn expr(&self) -> Option<Expr> {464 pub fn expr(&self) -> Option<Expr> {
465 support::child(&self.syntax)465 support::children(&self.syntax).next()
466 }466 }
467}467}
468468
472}472}
473impl Arg {473impl Arg {
474 pub fn name(&self) -> Option<Name> {474 pub fn name(&self) -> Option<Name> {
475 support::child(&self.syntax)475 support::children(&self.syntax).next()
476 }476 }
477 pub fn assign_token(&self) -> Option<SyntaxToken> {477 pub fn assign_token(&self) -> Option<SyntaxToken> {
478 support::token(&self.syntax, T![=])478 support::token(&self.syntax, T![=])
479 }479 }
480 pub fn expr(&self) -> Option<Expr> {480 pub fn expr(&self) -> Option<Expr> {
481 support::child(&self.syntax)481 support::children(&self.syntax).next()
482 }482 }
483}483}
484484
523}523}
524impl MemberBindStmt {524impl MemberBindStmt {
525 pub fn obj_local(&self) -> Option<ObjLocal> {525 pub fn obj_local(&self) -> Option<ObjLocal> {
526 support::child(&self.syntax)526 support::children(&self.syntax).next()
527 }527 }
528}528}
529529
536 support::token(&self.syntax, T![local])536 support::token(&self.syntax, T![local])
537 }537 }
538 pub fn bind(&self) -> Option<Bind> {538 pub fn bind(&self) -> Option<Bind> {
539 support::child(&self.syntax)539 support::children(&self.syntax).next()
540 }540 }
541}541}
542542
546}546}
547impl MemberAssertStmt {547impl MemberAssertStmt {
548 pub fn assertion(&self) -> Option<Assertion> {548 pub fn assertion(&self) -> Option<Assertion> {
549 support::child(&self.syntax)549 support::children(&self.syntax).next()
550 }550 }
551}551}
552552
556}556}
557impl MemberFieldNormal {557impl MemberFieldNormal {
558 pub fn field_name(&self) -> Option<FieldName> {558 pub fn field_name(&self) -> Option<FieldName> {
559 support::child(&self.syntax)559 support::children(&self.syntax).next()
560 }560 }
561 pub fn plus_token(&self) -> Option<SyntaxToken> {561 pub fn plus_token(&self) -> Option<SyntaxToken> {
562 support::token(&self.syntax, T![+])562 support::token(&self.syntax, T![+])
565 support::token_child(&self.syntax)565 support::token_child(&self.syntax)
566 }566 }
567 pub fn expr(&self) -> Option<Expr> {567 pub fn expr(&self) -> Option<Expr> {
568 support::child(&self.syntax)568 support::children(&self.syntax).next()
569 }569 }
570}570}
571571
575}575}
576impl MemberFieldMethod {576impl MemberFieldMethod {
577 pub fn field_name(&self) -> Option<FieldName> {577 pub fn field_name(&self) -> Option<FieldName> {
578 support::child(&self.syntax)578 support::children(&self.syntax).next()
579 }579 }
580 pub fn params_desc(&self) -> Option<ParamsDesc> {580 pub fn params_desc(&self) -> Option<ParamsDesc> {
581 support::child(&self.syntax)581 support::children(&self.syntax).next()
582 }582 }
583 pub fn visibility(&self) -> Option<Visibility> {583 pub fn visibility(&self) -> Option<Visibility> {
584 support::token_child(&self.syntax)584 support::token_child(&self.syntax)
585 }585 }
586 pub fn expr(&self) -> Option<Expr> {586 pub fn expr(&self) -> Option<Expr> {
587 support::child(&self.syntax)587 support::children(&self.syntax).next()
588 }588 }
589}589}
590590
594}594}
595impl FieldNameFixed {595impl FieldNameFixed {
596 pub fn id(&self) -> Option<Name> {596 pub fn id(&self) -> Option<Name> {
597 support::child(&self.syntax)597 support::children(&self.syntax).next()
598 }598 }
599 pub fn text(&self) -> Option<Text> {599 pub fn text(&self) -> Option<Text> {
600 support::token_child(&self.syntax)600 support::token_child(&self.syntax)
610 support::token(&self.syntax, T!['['])610 support::token(&self.syntax, T!['['])
611 }611 }
612 pub fn expr(&self) -> Option<Expr> {612 pub fn expr(&self) -> Option<Expr> {
613 support::child(&self.syntax)613 support::children(&self.syntax).next()
614 }614 }
615 pub fn r_brack_token(&self) -> Option<SyntaxToken> {615 pub fn r_brack_token(&self) -> Option<SyntaxToken> {
616 support::token(&self.syntax, T![']'])616 support::token(&self.syntax, T![']'])
626 support::token(&self.syntax, T![for])626 support::token(&self.syntax, T![for])
627 }627 }
628 pub fn bind(&self) -> Option<Destruct> {628 pub fn bind(&self) -> Option<Destruct> {
629 support::child(&self.syntax)629 support::children(&self.syntax).next()
630 }630 }
631 pub fn in_kw_token(&self) -> Option<SyntaxToken> {631 pub fn in_kw_token(&self) -> Option<SyntaxToken> {
632 support::token(&self.syntax, T![in])632 support::token(&self.syntax, T![in])
633 }633 }
634 pub fn expr(&self) -> Option<Expr> {634 pub fn expr(&self) -> Option<Expr> {
635 support::child(&self.syntax)635 support::children(&self.syntax).next()
636 }636 }
637}637}
638638
645 support::token(&self.syntax, T![if])645 support::token(&self.syntax, T![if])
646 }646 }
647 pub fn expr(&self) -> Option<Expr> {647 pub fn expr(&self) -> Option<Expr> {
648 support::child(&self.syntax)648 support::children(&self.syntax).next()
649 }649 }
650}650}
651651
655}655}
656impl BindDestruct {656impl BindDestruct {
657 pub fn into(&self) -> Option<Destruct> {657 pub fn into(&self) -> Option<Destruct> {
658 support::child(&self.syntax)658 support::children(&self.syntax).next()
659 }659 }
660 pub fn assign_token(&self) -> Option<SyntaxToken> {660 pub fn assign_token(&self) -> Option<SyntaxToken> {
661 support::token(&self.syntax, T![=])661 support::token(&self.syntax, T![=])
662 }662 }
663 pub fn value(&self) -> Option<Expr> {663 pub fn value(&self) -> Option<Expr> {
664 support::child(&self.syntax)664 support::children(&self.syntax).next()
665 }665 }
666}666}
667667
671}671}
672impl BindFunction {672impl BindFunction {
673 pub fn name(&self) -> Option<Name> {673 pub fn name(&self) -> Option<Name> {
674 support::child(&self.syntax)674 support::children(&self.syntax).next()
675 }675 }
676 pub fn params(&self) -> Option<ParamsDesc> {676 pub fn params(&self) -> Option<ParamsDesc> {
677 support::child(&self.syntax)677 support::children(&self.syntax).next()
678 }678 }
679 pub fn assign_token(&self) -> Option<SyntaxToken> {679 pub fn assign_token(&self) -> Option<SyntaxToken> {
680 support::token(&self.syntax, T![=])680 support::token(&self.syntax, T![=])
681 }681 }
682 pub fn value(&self) -> Option<Expr> {682 pub fn value(&self) -> Option<Expr> {
683 support::child(&self.syntax)683 support::children(&self.syntax).next()
684 }684 }
685}685}
686686
690}690}
691impl Param {691impl Param {
692 pub fn destruct(&self) -> Option<Destruct> {692 pub fn destruct(&self) -> Option<Destruct> {
693 support::child(&self.syntax)693 support::children(&self.syntax).next()
694 }694 }
695 pub fn assign_token(&self) -> Option<SyntaxToken> {695 pub fn assign_token(&self) -> Option<SyntaxToken> {
696 support::token(&self.syntax, T![=])696 support::token(&self.syntax, T![=])
697 }697 }
698 pub fn expr(&self) -> Option<Expr> {698 pub fn expr(&self) -> Option<Expr> {
699 support::child(&self.syntax)699 support::children(&self.syntax).next()
700 }700 }
701}701}
702702
706}706}
707impl DestructFull {707impl DestructFull {
708 pub fn name(&self) -> Option<Name> {708 pub fn name(&self) -> Option<Name> {
709 support::child(&self.syntax)709 support::children(&self.syntax).next()
710 }710 }
711}711}
712712
748 support::children(&self.syntax)748 support::children(&self.syntax)
749 }749 }
750 pub fn destruct_rest(&self) -> Option<DestructRest> {750 pub fn destruct_rest(&self) -> Option<DestructRest> {
751 support::child(&self.syntax)751 support::children(&self.syntax).next()
752 }752 }
753 pub fn comma_token(&self) -> Option<SyntaxToken> {753 pub fn comma_token(&self) -> Option<SyntaxToken> {
754 support::token(&self.syntax, T![,])754 support::token(&self.syntax, T![,])
764}764}
765impl DestructObjectField {765impl DestructObjectField {
766 pub fn field(&self) -> Option<Name> {766 pub fn field(&self) -> Option<Name> {
767 support::child(&self.syntax)767 support::children(&self.syntax).next()
768 }768 }
769 pub fn colon_token(&self) -> Option<SyntaxToken> {769 pub fn colon_token(&self) -> Option<SyntaxToken> {
770 support::token(&self.syntax, T![:])770 support::token(&self.syntax, T![:])
771 }771 }
772 pub fn destruct(&self) -> Option<Destruct> {772 pub fn destruct(&self) -> Option<Destruct> {
773 support::child(&self.syntax)773 support::children(&self.syntax).next()
774 }774 }
775 pub fn assign_token(&self) -> Option<SyntaxToken> {775 pub fn assign_token(&self) -> Option<SyntaxToken> {
776 support::token(&self.syntax, T![=])776 support::token(&self.syntax, T![=])
777 }777 }
778 pub fn expr(&self) -> Option<Expr> {778 pub fn expr(&self) -> Option<Expr> {
779 support::child(&self.syntax)779 support::children(&self.syntax).next()
780 }780 }
781}781}
782782
789 support::token(&self.syntax, T![...])789 support::token(&self.syntax, T![...])
790 }790 }
791 pub fn into(&self) -> Option<Name> {791 pub fn into(&self) -> Option<Name> {
792 support::child(&self.syntax)792 support::children(&self.syntax).next()
793 }793 }
794}794}
795795
799}799}
800impl DestructArrayElement {800impl DestructArrayElement {
801 pub fn destruct(&self) -> Option<Destruct> {801 pub fn destruct(&self) -> Option<Destruct> {
802 support::child(&self.syntax)802 support::children(&self.syntax).next()
803 }803 }
804}804}
805805
modifiedxtask/src/sourcegen/mod.rsdiffbeforeafterboth
1use std::path::PathBuf;1use std::{collections::HashMap, path::PathBuf};
22
3use anyhow::Result;3use anyhow::Result;
4use ast::{lower, AstSrc};4use ast::{lower, AstSrc};
202 quote!(impl ast::#trait_name for #name {})202 quote!(impl ast::#trait_name for #name {})
203 });203 });
204
205 let mut type_positions: HashMap<String, usize> = HashMap::new();
206 let field_positions: Vec<_> = node.fields.iter().map(|field| {
207 let ty_str = field.ty().to_string();
208 let pos = *type_positions.get(&ty_str).unwrap_or(&0);
209 type_positions.insert(ty_str, pos + 1);
210 pos
211 }).collect();
204212
205 let methods = node.fields.iter().map(|field| {213 let methods = node.fields.iter().zip(field_positions.iter()).map(|(field, &pos)| {
206 let method_name = field.method_name(kinds);214 let method_name = field.method_name(kinds);
207 let ty = field.ty();215 let ty = field.ty();
208216
224 support::token_child(&self.syntax)232 support::token_child(&self.syntax)
225 }233 }
226 }234 }
227 } else {235 } else if pos == 0 {
228 quote! {236 quote! {
229 pub fn #method_name(&self) -> Option<#ty> {237 pub fn #method_name(&self) -> Option<#ty> {
230 support::child(&self.syntax)238 support::children(&self.syntax).next()
231 }239 }
232 }240 }
233 }241 } else {
242 quote! {
243 pub fn #method_name(&self) -> Option<#ty> {
244 support::children(&self.syntax).nth(#pos)
245 }
246 }
247 }
234 });248 });
235 (249 (
236 quote! {250 quote! {