Skip to content

Commit 266f809

Browse files
committed
Improve visibility handling in trace formatting
1 parent 9632b86 commit 266f809

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

R/trace.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ format.rlang_trace <- function(x,
373373
srcrefs = NULL) {
374374
switch(
375375
arg_match(simplify),
376-
none = trace_format(x, max_frames, dir, srcrefs),
376+
none = trace_format_full(x, max_frames, dir, srcrefs),
377377
collapse = trace_format_collapse(x, max_frames, dir, srcrefs),
378378
branch = trace_format_branch(x, max_frames, dir, srcrefs)
379379
)
@@ -391,6 +391,12 @@ trace_format <- function(trace, max_frames, dir, srcrefs) {
391391
cli_tree(trace_as_tree(trace, dir = dir, srcrefs = srcrefs))
392392
}
393393

394+
trace_format_full <- function(trace, max_frames, dir, srcrefs) {
395+
if (length(trace$visible)) {
396+
trace$visible <- TRUE
397+
}
398+
trace_format(trace, max_frames, dir, srcrefs)
399+
}
394400
trace_format_collapse <- function(trace, max_frames, dir, srcrefs) {
395401
trace <- trace_simplify_collapse(trace)
396402
trace_format(trace, max_frames, dir, srcrefs)
@@ -766,7 +772,7 @@ trace_simplify_collapse <- function(trace) {
766772
}
767773
}
768774

769-
trace$visible <- visible
775+
trace$visible <- visible & old_visible
770776
trace$parent <- parents
771777

772778
trace

tests/testthat/_snaps/trace.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,3 +1086,31 @@
10861086
3. h()
10871087
4. [ evalq() ] with 1 more call
10881088

1089+
# trailing `FALSE` visibility is handled
1090+
1091+
Code
1092+
# Full
1093+
print(trace, simplify = "none", dir = dir, srcrefs = srcrefs)
1094+
Output
1095+
x
1096+
1. \-f()
1097+
2. \-g()
1098+
3. \-h()
1099+
4. \-foo()
1100+
5. \-bar()
1101+
Code
1102+
# Collapsed
1103+
print(trace, simplify = "collapse", dir = dir, srcrefs = srcrefs)
1104+
Output
1105+
x
1106+
1. \-f()
1107+
2. \-g()
1108+
3. \-h()
1109+
Code
1110+
# Branch
1111+
print(trace, simplify = "branch", dir = dir, srcrefs = srcrefs)
1112+
Output
1113+
1. f()
1114+
2. g()
1115+
3. h()
1116+

tests/testthat/test-trace.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,12 @@ test_that("can detect namespace and scope from call", {
721721
trace_context("foo", ":::")
722722
)
723723
})
724+
725+
test_that("trailing `FALSE` visibility is handled", {
726+
trace <- new_trace(
727+
alist(f(), g(), h(), foo(), bar()),
728+
parent = 0:4,
729+
visible = c(TRUE, TRUE, TRUE, FALSE, FALSE)
730+
)
731+
expect_snapshot_trace(trace)
732+
})

0 commit comments

Comments
 (0)