difftreelog
feat reformat compspecs
in: master
3 files changed
crates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -239,7 +239,6 @@
struct ObjValueInner {
cores: Vec<CcObjectCore>,
assertions_ran: Cell<bool>,
- #[trace(skip)]
has_assertions: bool,
value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,
}
crates/jrsonnet-formatter/src/lib.rsdiffbeforeafterboth450 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 }478479 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 );487488 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 }506507 out508 }509453 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 }477478 if end_comments.should_start_with_newline {479 p!(out, nl);480 }481 format_comments(&end_comments.trivia, CommentLocation::EndOfItems, out);482524483 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 {536495 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_newline540 || comp_end_comments.should_start_with_newline;541496 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 };551499 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();559500 format_comments(&mem.inline_trivia, CommentLocation::ItemInline, out);560 let body = with_indent_eoi(multi_line, body.into(), comp_end_comments);501 }561502 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));506507 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(crates/jrsonnet-formatter/src/snapshots/jrsonnet_formatter__tests__snapshots@comprehensions.jsonnet.snapdiffbeforeafterboth--- a/crates/jrsonnet-formatter/src/snapshots/jrsonnet_formatter__tests__snapshots@comprehensions.jsonnet.snap
+++ b/crates/jrsonnet-formatter/src/snapshots/jrsonnet_formatter__tests__snapshots@comprehensions.jsonnet.snap
@@ -6,8 +6,5 @@
{
arr: [x for x in [ 1, 2, 3 ]],
filtered: [x for x in [ 1, 2, 3, 4, 5 ] if x > 2],
- obj: {
- [k]: v,
- for k in [ 'a', 'b' ]for v in [ 1, 2 ]
- },
+ obj: { [k]: v for k in [ 'a', 'b' ] for v in [ 1, 2 ] },
}