git.delta.rocks / jrsonnet / refs/commits / 0afd46183b60

difftreelog

feat reformat compspecs

uxuyslyzYaroslav Bolyukin2026-04-01parent: #0b2a41f.patch.diff
in: master

3 files changed

modifiedcrates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth
239struct ObjValueInner {239struct ObjValueInner {
240 cores: Vec<CcObjectCore>,240 cores: Vec<CcObjectCore>,
241 assertions_ran: Cell<bool>,241 assertions_ran: Cell<bool>,
242 #[trace(skip)]
243 has_assertions: bool,242 has_assertions: bool,
244 value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,243 value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,
245}244}
modifiedcrates/jrsonnet-formatter/src/lib.rsdiffbeforeafterboth
450 fn print(&self, out: &mut PrintItems) {450 fn print(&self, out: &mut PrintItems) {
451 match self {451 match self {
452 Self::ObjBodyComp(l) => {452 Self::ObjBodyComp(l) => {
453 fn gen_obj_comp(
454 members: Vec<Child<Member>>,
455 member_end_comments: EndingComments,
456 compspecs: Vec<Child<CompSpec>>,
457 multi_line: ConditionResolver,
458 ) -> PrintItems {
459 let mut out = PrintItems::new();
460 for mem in members {
461 if mem.should_start_with_newline {
462 p!(out, nl);
463 }
464 format_comments(
465 &mem.before_trivia,
466 CommentLocation::AboveItem,
467 &mut out,
468 );
469 p!(&mut out, {mem.value});
470 p!(out, if("trailing comma", multi_line, str(",")));
471 format_comments(
472 &mem.inline_trivia,
473 CommentLocation::ItemInline,
474 &mut out,
475 );
476 p!(out, if_else("member-comp sep", multi_line, nl)(sonl));
477 }
478
479 if member_end_comments.should_start_with_newline {
480 p!(out, nl);
481 }
482 format_comments(
483 &member_end_comments.trivia,
484 CommentLocation::EndOfItems,
485 &mut out,
486 );
487
488 let mut compspecs = compspecs.into_iter().peekable();
489 while let Some(mem) = compspecs.next() {
490 if mem.should_start_with_newline {
491 p!(out, nl);
492 }
493 format_comments(
494 &mem.before_trivia,
495 CommentLocation::AboveItem,
496 &mut out,
497 );
498 p!(&mut out, { mem.value });
499 format_comments(
500 &mem.inline_trivia,
501 CommentLocation::ItemInline,
502 &mut out,
503 );
504 p!(out, if_else("comp spec sep", multi_line, nl)(sonl));
505 }
506
507 out
508 }
509
453 let (children, mut end_comments) = children_between::<Member>(510 let (children, mut end_comments) = children_between::<Member>(
454 l.syntax().clone(),511 l.syntax().clone(),
464 None,521 None,
465 );522 );
466 let trailing_for_comp = end_comments.extract_trailing();523 let trailing_for_comp = end_comments.extract_trailing();
467 p!(out, str("{") >i nl);
468 for mem in children {
469 if mem.should_start_with_newline {
470 p!(out, nl);
471 }
472 format_comments(&mem.before_trivia, CommentLocation::AboveItem, out);
473 p!(out, {mem.value} str(","));
474 format_comments(&mem.inline_trivia, CommentLocation::ItemInline, out);
475 p!(out, nl);
476 }
477
478 if end_comments.should_start_with_newline {
479 p!(out, nl);
480 }
481 format_comments(&end_comments.trivia, CommentLocation::EndOfItems, out);
482524
483 let (compspecs, end_comments) = children_between::<CompSpec>(525 let (compspecs, comp_end_comments) = children_between::<CompSpec>(
484 l.syntax().clone(),526 l.syntax().clone(),
485 l.member_comps()527 l.member_comps()
486 .last()528 .last()
491 l.r_brace_token().map(Into::into).as_ref(),533 l.r_brace_token().map(Into::into).as_ref(),
492 Some(trailing_for_comp),534 Some(trailing_for_comp),
493 );535 );
494 for mem in compspecs {536
495 if mem.should_start_with_newline {537 let source_is_multiline = children.iter().any(|c| c.triggers_multiline)
538 || compspecs.iter().any(|c| c.triggers_multiline)
539 || end_comments.should_start_with_newline
540 || comp_end_comments.should_start_with_newline;
541
496 p!(out, nl);542 let start = LineNumber::new("obj comp start line");
497 }543 let end = LineNumber::new("obj comp end line");
544 let multi_line: ConditionResolver = if source_is_multiline {
545 true_resolver()
546 } else {
498 format_comments(&mem.before_trivia, CommentLocation::AboveItem, out);547 Rc::new(move |ctx: &mut ConditionResolverContext| {
548 is_multiple_lines(ctx, start, end)
549 })
550 };
551
499 p!(out, { mem.value });552 let body = new_line_group(gen_obj_comp(
553 children,
554 end_comments,
555 compspecs,
556 multi_line.clone(),
557 ))
558 .into_rc_path();
559
500 format_comments(&mem.inline_trivia, CommentLocation::ItemInline, out);560 let body = with_indent_eoi(multi_line, body.into(), comp_end_comments);
501 }561
502 if end_comments.should_start_with_newline {
503 p!(out, nl);562 p!(out, str("{") info(start));
504 }
505 format_comments(&end_comments.trivia, CommentLocation::EndOfItems, out);563 p!(out, items(body));
506
507 p!(out, nl <i str("}"));564 p!(out, str("}") info(end));
508 }565 }
509 Self::ObjBodyMemberList(l) => {566 Self::ObjBodyMemberList(l) => {
510 fn gen_members(567 fn gen_members(
modifiedcrates/jrsonnet-formatter/src/snapshots/jrsonnet_formatter__tests__snapshots@comprehensions.jsonnet.snapdiffbeforeafterboth
6{6{
7 arr: [x for x in [ 1, 2, 3 ]],7 arr: [x for x in [ 1, 2, 3 ]],
8 filtered: [x for x in [ 1, 2, 3, 4, 5 ] if x > 2],8 filtered: [x for x in [ 1, 2, 3, 4, 5 ] if x > 2],
9 obj: {9 obj: { [k]: v for k in [ 'a', 'b' ] for v in [ 1, 2 ] },
10 [k]: v,
11 for k in [ 'a', 'b' ]for v in [ 1, 2 ]
12 },
13}10}
1411