-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_outline()
functions feedback
#28
Comments
Thanks again for building this! I have been using this for my project, but I wanted to intersperse different levels of headings with my TODO items. I had a lot of trouble figuring out context for my to-do items in the middle of a large notebook. To accomplish this, I wrote a printing function that takes
I am still playing with the formatting. I started using Below is the code I'm using. First, I simplify the outline tibble to something that makes sense to me. Then, I make the outline_data <- reuseme::file_outline(path = "test.qmd") %>%
# Convert the many is_ columns into mutually exclusive "outline row types"
pivot_longer(
names_to = "type", names_prefix = "is_", c(
starts_with("is_"), -is_md, -is_second_level_heading_or_more, -is_roxygen_comment, -is_notebook
)
) %>%
# # Double check that types are mututally exclusive
# filter(all(value == F), .by = c(file_short, title, line_id))
# filter(sum(value) > 1, .by = c(file_short, title, line_id))
filter(value == T) %>%
# We drop these because they don't serve to add much context to TODOs (they don't affect heirarchy)
filter(type != "tab_or_plot_title") %>%
# Some useful definitions!
mutate(
title = coalesce(outline_el, title_el),
file_short = fs::path_file(file),
n_leading_hash = type %>% case_match(
c("todo_fixme", "tab_or_plot_title") ~ NA,
.default = n_leading_hash
)
) %>%
# For each file, stick a item at the top of the outline
group_by(file, file_short) %>%
group_modify(\(data, group) data %>% add_row(
.before = 0,
n_leading_hash = -1,
title = group$file_short,
type = "file"
)) %>%
mutate(
# Processing how title displays based on type
print_title = type %>% case_match(
"todo_fixme" ~ link,
.default = link_rs_api
) %>% coalesce(title) %>% map_chr(cli::format_inline),
# Assign TODO items (and other items missing n_leading_hash)
# to be indented under the last seen header level
indent = coalesce(n_leading_hash, zoo::na.locf0(n_leading_hash+1)),
# If there are any headers that skip an intermediate level, pick them up
skip_level = indent > lag(indent)+1,
skip_level_should_be = ifelse(skip_level, lag(indent)+1, NA),
skip_level_adjust = case_when(
# All the items below on the outline should be adjusted backwards
skip_level ~ skip_level_should_be-indent,
# Unless we reach a point on the outline where we're back up in
# the hierachy, so stop adjusting.
indent <= zoo::na.locf0(skip_level_should_be) ~ 0
) %>%
# Carry the adjustments to later rows
zoo::na.locf0() %>% coalesce(0),
indent = indent + skip_level_adjust
) %>%
ungroup() %>%
select(title, type, n_leading_hash, indent, print_title)
outline_data %>%
mutate(
# Give items IDs so titles do not have to be unique
item_id = as.character(row_number()),
indent_wider = indent,
x = TRUE
) %>%
# We need these wide cumsum `header1` type fields to determine which items belong to which parents
pivot_wider(names_from = indent_wider, values_from = x, values_fill = F, names_prefix = "header") %>%
mutate(across(starts_with("header"), cumsum)) %>%
# For each row, pick the IDs of all direct children from the outline
pmap(function(...) with(list(..., childdata = .), tibble(
title,
print_title,
indent,
item_id,
type,
parent_level_id = get(stringr::str_c("header", indent)),
children_ids = childdata %>%
dplyr::rename(childindent = indent) %>%
dplyr::filter(
childindent == indent+1,
cumsum(childindent == indent) == parent_level_id
) %>%
dplyr::pull(item_id) %>% list()
))) %>%
list_rbind() %>%
# View()
select(item_id, children_ids, print_title) %>%
cli::tree()
And here's the qmd text I used: ---
title: "Test"
format: html
editor: visual
---
## Quarto
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
## Running Code
When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
```{r}
1 + 1
# TODO: fix this in the code
```
You can add options to executable code like this
### A sub header
```{r}
#| echo: false
2 * 2
```
The `echo: false` option disables the printing of code (only output is displayed).
TODO: here's a todo in the text
# Back to header 1
## Dont skip me
##### header 5
TODO: testing section
## Another sub header
TODO: section test
|
thank you so much for your insightful comments! I am trying to wrap up parsing roxygen2 comments properly. I will get to this soon! I really like that you created an example code! I will try to see what I can come up with! For indentation, it is planned. As you can see, there are already different colors for first level headings vs the rest. I divided topics between "important" and "not_important", but I can add more categories, colors and more levels of indentation! |
Good to hear! For Let me know if it still breaks for you. Also instead of showing Done v?, could also just be green done clickable emoji? I just disabled it generally in 92c7a66 (only keeping it for active file and files named TODO.R Apologies in advance for potentially breaking your code I think I will disable roxygen comments parsing I really like how you style differently the text!
|
@violetcereza I am looking forward to your PR! Feel free to open smaller chunks PRs first to get changes you'd like to see first. https://code-review.tidyverse.org/author/focused.html Add as much snapshot tests as you can, so it is easy to visualize output. Therefore, if some things end up changing, we will have a visual reference. https://testthat.r-lib.org/articles/snapshotting.html Let me know if you have any questions |
👍 looking forward to seeing examples of this!
That is a good idea!
Not strong opinions there. Recently, I fixed titles h3 to escape markup b4803a2#diff-708c3b67fc1b91c821cc6c00c9c8108cabcdd44c7edd9366cf62a373b717ca0cR440 in outline.R
If possible, file this a separate PR?
I will be happy to see this too! Separate PR if possible too :) I am looking forward. Here, I am seeing 3 steps.
At the end of if (isTRUE(getOption("reuseme.outline_tree") {
# modify result to be tree in `outline_tree()` helper.
result <- outline_tree(result)
class(result) <- c("cli_tree", "outline_report", "tbl_df", "tbl", "data.frame")
} This way, this could just use the `cli:::print.cli_tree() method? Alternatively (maybe better) refactor the Let me know what you think!
Any (non-trivial) code related to trees should live in Don't let this remove your creativity, these are just the thoughts I have assembled since yesterday. Apologies also if some of my recent changes broke your code. (I am still experiencing). Hopefully it is not too bad to repair. I have removed some variables from output:
Lines 715 to 730 in 127fe6c
Feel free to share any code. I can rework it to account for my recent changes. And make adjustments as needed to revert some changes. Any other comment / feedback welcome! You inspired me to make changes I didn't think of at first (avoid printing |
Thanks! I will be taking a look at it today... Here's what I'm thinking big picture for the outline interface:
The new simplified API
|
I like this! Do you want to open a PR, or do you want me to make these changes first? |
Hey I know I am procrastinating writing unit tests on my PR... But WRT to lightparser: I started trying out VSCode this week and I learned about "Language Server Protocols." Basically, there's too many types of files and too many IDEs and LSP provides a common interface and prevents the headache of re-implementing code analysis. I wonder if we could plug into the |
I understand. On my side, I have been able to successfully move link creation inside the print method. I am thinking about what you are proposing. Feel free to continue sharing what you find! The end goal is to improve our workflows, not to stick to a suboptimal solution |
Please comment on this issue if you tried the
*_outline()
functions and would like some functionality or encountered something unexpectedcf rstudio/rstudioapi#153 (comment)
Current plans
roxygen2::parse_package()
+ md (Use roxygen2 parser for roxy comments + lightparser for figure and tbl captions #29)Known issues
Falsely recognized commented code as headings in commented code.solved by roxygen2.multiline titles or fig-caps in qmd files, not recognizedsolved by lightparserOnly yaml style comments recognized (not in the chunk header)solved by lighparserThe text was updated successfully, but these errors were encountered: