-
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
Use roxygen2 parser for roxy comments + lightparser for figure and tbl captions #29
Open
olivroy
wants to merge
83
commits into
main
Choose a base branch
from
roxy-parse
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
8db3686
Awesome progress on roxy parsing!
olivroy cdd9c70
Speed things up!
olivroy d2578be
Tiny modifications to ensure comparison between the other outline files.
olivroy a887d76
Other fixes
olivroy 0e4f9fc
Remove cli info
olivroy 1ee6d49
Add support for outline-roxy
olivroy 88bb444
Fix color in message
olivroy 2f66540
Add tests to see if it works correctly.
olivroy 401997c
Use `line` instead of line_id
olivroy 0e74f37
Commit remaining breakage
olivroy 314fa9b
Merge
olivroy de4fc3e
Merge branch
olivroy 145809c
rename `o_is_object_title()` to `o_is_tab_plot_title()`
olivroy 3a875df
Exclude `@keywords` and `@noRd` (will only need to exclude undocument…
olivroy f8fe284
Create `define_criteria_roxy()` to define criteria independently for …
olivroy 92335a4
Update snapshots
olivroy 38a71a0
Handle empty case better
olivroy 97da597
Fix logic to include object titles in outline
olivroy ebc4355
Commit changes to README
olivroy d3bf724
Refine some criteria to exclude some contents or files.
olivroy 557209a
Avoid index roxygen comments in tests
olivroy 29375cf
Merged origin/main into roxy-parse
olivroy fa9d935
Improve table detection. Improve package version detection in news.
olivroy 1db1418
Add markup for linking local issues
olivroy d172b30
Update R/outline.R
olivroy d3506b4
Last update
olivroy 646fe4b
Add parent error for debugging.
olivroy e481ac3
I identified the issue. Will try to fix.
olivroy 323a121
Fix `pos` and `objects` to make sure they have a common length.
olivroy 910a202
Add `active_rs_doc_nav()` to navigate to Files Pane at location.
olivroy 8cec6ce
Rename to `_outline` for consistency.
olivroy 406a0c4
Better topic name detection
olivroy c0e9063
Improve regex to allow for title to be wrapped in function + family t…
olivroy 8badd76
Improve `proj_file()` if exact match in `proj`.
olivroy 83f0c4a
Make sure pos and objects have the same length.
olivroy 594b627
fix regex for plot title.
olivroy 35ba23d
Avoid uninteresting roxy headings.
olivroy 15be047
Don't parse roxy comments in `proj_file()` + add `options("reuseme.ro…
olivroy a742214
Avoid recognizing test_that("a", expect_true(TRUE))
olivroy eeadbaa
Temporarily change directory when parsing roxy comments as it may help?
olivroy b5f1896
Fix mistake
olivroy decdd06
Use lightparser for caption parsing!
olivroy d5b6ad3
Some fixups for revdeps and plot titles to remove some false positive…
olivroy 6af2548
Don't error if you couldn't find gh URL.
olivroy 27cd5cb
Clean workaround
olivroy a497218
Add to NEWS + minor adjustments to make outline and usethis to keep w…
olivroy fc50e76
More robust `escape_markup()` (add `\\.` as an acceptable start of va…
olivroy 49e443b
Add some workarounds to make cli parsing and escaping work a bit bett…
olivroy 57547f1
mark todos as complete...
olivroy 420fd50
Rename `print_todo` -> `exclude_todos`...
olivroy 93b1805
Rm redundant heading
olivroy 938193b
Avoid empty todos + html sourceCode (tidyselect integration)
olivroy 11880b1
Lint + use base R replacements
olivroy 51bde5c
Recognize the last way possible to specify chunk options.
olivroy 5751577
Rename `is_chunk_cap` to `is_object_caption`
olivroy 871dd05
Add the factored `exclude_example_files()`
olivroy 21fcdc3
Improve knitr notebook support
olivroy 33a4d33
Sort out uninteresting headings.
olivroy d5782e4
Experimental support for displaying topic.
olivroy 7dac4e5
Fix problem of incorrect dir.
olivroy 9d07e39
Use mocking for mocking RStudio + change dir
olivroy 72c3d45
Fix snap
olivroy 9e00edc
Tweaks based on integration testing,
olivroy e45b749
More integration adjustments and addition of examples.
olivroy 1429c02
Address some comments.
olivroy cdd0cc9
Make sure is_doc_title doesn't interleave with , prefer is_object_tit…
olivroy 434b92f
Add files from violetcereza as testing.
olivroy 3cb9225
Test adding indent
olivroy d11f9d5
Merge main
olivroy d926d32
Fix conflict [ci skip]
olivroy 1d84af2
Merge
olivroy 8f9978c
merge [ci skip]
olivroy 392591b
Merge main [ci skip]
olivroy f87c935
Merge
olivroy 4d87700
Merge
olivroy 56a4062
[ci skip] adjust news
olivroy 0fb7264
merge
olivroy cce2805
notebook are already supported on main.
olivroy 27bdec2
[ci skip]
olivroy f7105c2
Merge
olivroy 5f665cb
fix merge [ci skip]
olivroy 322e5d0
Merge
olivroy caa185c
Merge branch 'main' into roxy-parse
olivroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
#' Extract roxygen tag | ||
#' | ||
#' Tell me what this does | ||
#' | ||
#' # Section to extract | ||
#' | ||
#' Well this is a section | ||
#' | ||
#' @noRd | ||
#' @param file A list of roxy blocks | ||
#' @returns A named list with name = file:line, and element is the section title | ||
#' @examples | ||
#' extract_roxygen_tag_location(tag = "title") | ||
|
||
extract_roxygen_tag_location <- function(file, tag) { | ||
# suppressMessages(aa <- roxygen2::parse_file(file)) | ||
# browser() | ||
aa <- file | ||
pos <- purrr::map(aa, \(x) roxygen2::block_get_tags(x, tags = tag)) | ||
# browser() | ||
if (all(lengths(pos) == 0L)) { | ||
return(character(0L)) | ||
} | ||
aa <- aa[lengths(pos) > 0L] | ||
pos <- purrr::list_flatten(pos) | ||
objects <- purrr::map( | ||
aa, | ||
\(x) x$object$topic | ||
) | ||
if (any(lengths(objects) == 0)) { | ||
name_tag <- purrr::map( | ||
aa, | ||
\(x) roxygen2::block_get_tag_value(x, "name") | ||
) | ||
for (i in seq_along(objects)) { | ||
if (is.null(objects[[i]])) { | ||
if (!is.null(name_tag[[i]])) { | ||
objects[[i]] <- name_tag[[i]] | ||
} else { | ||
objects[[i]] <- "no-topic" | ||
} | ||
} | ||
} | ||
if (any(lengths(objects) == 0)) { | ||
# should not happen. I chose "no-topic" instead. | ||
cli::cli_abort("Could not resolve object or topic names.") | ||
} | ||
} | ||
|
||
|
||
# browser() | ||
pos <- purrr::set_names(pos, pos$file) | ||
|
||
# browser() | ||
val <- withCallingHandlers( | ||
purrr::map2(pos, objects, \(x, obj_name) { | ||
el <- x$val | ||
el_has_names <- !is.null(names(el)) | ||
|
||
if (length(el) == 1 && !el_has_names) { | ||
el <- paste0( | ||
el, "____", obj_name | ||
) | ||
names(el) <- x$line | ||
return(el) | ||
} | ||
if (tag %in% c("description", "details") && !el_has_names) { | ||
# TODO when stable delete | ||
# print(x$val) | ||
# print(el_has_names) | ||
# cli::cli_inform("return early (no headings)") | ||
return(NULL) | ||
} | ||
# use raw instead | ||
lines <- stringr::str_split_1(x$raw, "\n") | ||
# browser() | ||
keep <- which(o_is_section_title(lines)) | ||
|
||
if (length(keep) == 0L) { | ||
# TODO Delete when stable debugging | ||
# cli::cli_inform(" No section title detected") | ||
return(NULL) | ||
} | ||
# line position. | ||
line_pos <- x$line + seq_along(lines) - 1L | ||
final_lines_to_include <- lines[keep] | ||
# Will not make this transformation and will consider roxygen comments to be | ||
# final_lines_to_include <- stringr::str_remove(final_lines_to_include, "^#+\\s") | ||
|
||
final_lines_to_include <- paste0(final_lines_to_include, "____", obj_name) | ||
names(final_lines_to_include) <- line_pos[keep] | ||
# TODO Delete when stable for debugging | ||
# if (length(final_lines_to_include) != 1) { | ||
# cli::cli_warn("el resulted to {.val {final_lines_to_include}}", "using first element for now") | ||
# } | ||
final_lines_to_include | ||
}), | ||
error = function(e) { | ||
cli::cli_abort( | ||
"For tag = {tag}, obj_name = {objects}, wrong size, should be {length(pos)}" | ||
) | ||
|
||
}) | ||
|
||
# rlang::set_names(val, nam) | ||
# merge line number and file name | ||
# I wonder if purrr make it easy to do tidyverse/purrr#1064 | ||
# list(x = c(el1 = 1), x = c(el2 = 2, el3 = 3)) | ||
#> list(x = c(el1 = 1, el2 = 2, el3 = 3)) | ||
val <- val |> purrr::compact() | ||
|
||
if (FALSE) { | ||
val <- unlist(val) | ||
names(val) <- stringr::str_replace(names(val), "\\.(\\d+)$", ":\\1") | ||
} else { | ||
# purrr::list_flatten( | ||
# name_spec = "{outer}:{inner}" | ||
# ) | ||
val <- vctrs::list_unchop( | ||
val, | ||
name_spec = "{outer}:{inner}", | ||
ptype = "character" | ||
) | ||
} | ||
|
||
|
||
# hack to keep tag | ||
if (length(val) > 0) { | ||
names(val) <- paste0(names(val), "____", tag) | ||
} | ||
val | ||
} | ||
|
||
join_roxy_fun <- function(file) { | ||
# don't parse noRd tags | ||
parsed_files <- purrr::discard(file, \(x) roxygen2::block_has_tags(x, "noRd")) | ||
# Return early if no roxy tags | ||
if (length(parsed_files) == 0) { | ||
return(character(0L)) | ||
} | ||
if (is.null(names(parsed_files))) { | ||
# browser() | ||
parsed_files <- parsed_files |> purrr::set_names(purrr::map_chr(parsed_files, \(x) x$file)) | ||
# cli::cli_abort("parsed files must be named at this point.") | ||
} | ||
# parsed_files <- set_names(parsed_files, \(x)) | ||
titles_list <- purrr::map(parsed_files, \(x) extract_roxygen_tag_location(x, tag = "title")) | ||
|
||
section_list <- purrr::map(parsed_files, \(x) extract_roxygen_tag_location(x, tag = "section")) | ||
subsection_list <- purrr::map(parsed_files, \(x) extract_roxygen_tag_location(x, tag = "subsection")) | ||
|
||
desc_list <- purrr::map(parsed_files, \(x) extract_roxygen_tag_location(x, tag = "description")) | ||
|
||
details_list <- purrr::map(parsed_files, \(x) extract_roxygen_tag_location(x, tag = "details")) | ||
|
||
family_list <- purrr::map(parsed_files, \(x) extract_roxygen_tag_location(x, tag = "family")) | ||
concept_list <- purrr::map(parsed_files, \(x) extract_roxygen_tag_location(x, tag = "concept")) | ||
roxy_parsed <- vctrs::vec_c( | ||
titles_list, | ||
section_list, | ||
subsection_list, | ||
desc_list, | ||
details_list, | ||
family_list, | ||
concept_list#, | ||
#.name_spec = "{outer}:::::{inner}", | ||
) |> | ||
vctrs::list_unchop( | ||
name_spec = "{outer}.....{inner}" | ||
) |> | ||
tibble::enframe() |> | ||
tidyr::separate_wider_delim( | ||
cols = name, | ||
names = c("file_line", "tag"), | ||
delim = "____" | ||
) | ||
|
||
roxy_parsed <- roxy_parsed |> | ||
tidyr::separate_wider_delim( | ||
cols = value, | ||
delim = "____", | ||
names = c("content", "topic"), | ||
) | ||
if (!all(grepl("\\.{5}", roxy_parsed$file_line, fixed = F))) { | ||
problems <- which(!grepl("\\.{5}", roxy_parsed$file_line, fixed = F)) | ||
#rowser() | ||
# roxy_parsed | ||
cli::cli_abort("Malformed file line at {problems}.") | ||
} | ||
roxy_parsed <- roxy_parsed |> | ||
tidyr::separate_wider_delim( | ||
file_line, | ||
delim = ".....", | ||
names = c("file", "line") | ||
) | ||
roxy_parsed |> | ||
dplyr::mutate( | ||
#file = fs::path_real(file) |> as.character(), | ||
#file_line = paste0(file, ":", line) | ||
) |> | ||
dplyr::relocate( | ||
file, topic, content, line, tag | ||
) |> | ||
dplyr::mutate( | ||
is_md = tag %in% c("subsection", "details", "description", "section"), | ||
# content = paste0("#' ", outline_el), | ||
is_object_title = tag == "title", | ||
line = as.integer(line), | ||
file_ext = "R", | ||
tile_el = NA_character_, | ||
title_el_line = NA_integer_, | ||
is_news = FALSE, | ||
is_roxygen_comment = TRUE, | ||
is_test_file = FALSE, | ||
is_snap_file = FALSE, | ||
before_and_after_empty = TRUE, | ||
is_section_title = TRUE, | ||
is_section_title_source = TRUE, | ||
is_saved_doc = TRUE, | ||
has_inline_markup = FALSE # let's not mess with inline markup | ||
) |> | ||
dplyr::filter( | ||
content != "NULL" | ||
) | ||
} | ||
|
||
# helper for interactive checking ----------- | ||
|
||
|
||
active_doc_parse <- function(doc = active_rs_doc()) { | ||
doc <- purrr::set_names(doc) | ||
parsed <- purrr::map(doc, roxygen2::parse_file) | ||
parsed |> join_roxy_fun() | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjust the CLI color issue as noted in the FIXME comment.
Change the FIXME comment to a TODO to monitor the upstream issue regarding the CLI color division. This keeps the codebase clean while acknowledging that the issue is recognized and being tracked.
Committable suggestion