From 92c7a66d0a835bea9246deae036931fae49394a1 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 6 Jun 2024 18:57:04 -0400 Subject: [PATCH] in `file_outline()`, `complete_todo()` links are no longer generated in non-interactive sessions, nor in `proj_outline()`. Only on TODO.R files and when requesting outline for active file. --- NEWS.md | 2 + R/outline.R | 22 ++++-- README.md | 114 +++++++++++++++---------------- tests/testthat/_snaps/outline.md | 8 +-- 4 files changed, 80 insertions(+), 66 deletions(-) diff --git a/NEWS.md b/NEWS.md index 21e9536..ed5ec98 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # reuseme (development version) +* `proj_outline()` no longer shows `complete_todo()` links for items in non-interactive sessions. `complete_todo()` links are now only shown when calling `file_outline()` on the active file. + * `proj_list()` / `proj_switch()` no longer opens a nested project if looking for `"pkgdown"`, `"testthat"`, etc. * `active_rs_doc_nav()` is a new function to navigate to files pane location. diff --git a/R/outline.R b/R/outline.R index 1132ce9..f8822d6 100644 --- a/R/outline.R +++ b/R/outline.R @@ -200,7 +200,13 @@ file_outline <- function(pattern = NULL, file_sections1 <- display_outline_element(file_sections0, dir_common) # Create hyperlink in console - file_sections <- construct_outline_link(file_sections1, is_saved_doc, dir_common, pattern) + file_sections <- construct_outline_link( + file_sections1, + is_saved_doc, + is_active_doc = is_active_doc, + dir_common, + pattern + ) if (alpha) { # remove inline markup first before sorting alphabetically @@ -602,7 +608,7 @@ define_important_element <- function(.data) { ) } -construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) { +construct_outline_link <- function(.data, is_saved_doc, is_active_doc, dir_common, pattern) { rs_avail_file_link <- is_rstudio("2023.09.0.375") # better handling after .data <- define_important_element(.data) @@ -612,10 +618,15 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) { .data$rs_version <- ifelse(!is_rstudio("2023.12.0.274") && is_rstudio(), ".", "") .data$has_inline_markup <- dplyr::coalesce(stringr::str_detect(.data$outline_el, "\\{|\\}"), FALSE) .data$is_saved_doc <- is_saved_doc + # Only show `complete_todo()` links for TODO.R files or active file in interactive sessions + # Using rlang::is_interactive to be able to test it if I ever feel the need. + .data$complete_todo_link <- rlang::is_interactive() & .data$is_todo_fixme & (is_active_doc | grepl("TODO.R", .data$file, fixed = TRUE)) .data <- dplyr::mutate( .data, - condition_to_truncate = !is.na(outline_el) & !has_title_el & (is_todo_fixme) & is_saved_doc & !has_inline_markup, - condition_to_truncate2 = !is.na(outline_el) & !has_title_el & !is_todo_fixme & (is_second_level_heading_or_more | is_subtitle) & is_saved_doc & !has_inline_markup + # to create `complete_todo()` links (only with active doc + is_todo_fixme) (and truncate if necessary) + condition_to_truncate = !is.na(outline_el) & !has_title_el & (complete_todo_link) & is_saved_doc & !has_inline_markup, + # Truncate todo items, subtitles + condition_to_truncate2 = !is.na(outline_el) & !has_title_el & (is_todo_fixme & !complete_todo_link) & (is_second_level_heading_or_more | is_subtitle) & is_saved_doc & !has_inline_markup ) # r-lib/cli#627, add a dot before and at the end (Only in RStudio before 2023.12) .data$outline_el2 <- NA_character_ @@ -643,7 +654,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) { .data <- dplyr::mutate( .data, outline_el2 = ifelse( - is.na(outline_el2) & !is.na(outline_el) & !has_title_el & is_todo_fixme & is_saved_doc, + is.na(outline_el2) & !is.na(outline_el) & !has_title_el & complete_todo_link & is_saved_doc, paste0( outline_el, "- {.run [Done{cli::symbol$tick}?](reuseme::complete_todo(", @@ -698,6 +709,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) { style_fun = NULL, is_saved_doc = NULL, is_roxygen_comment = NULL, + complete_todo_link = NULL, is_news = NULL, # I may put it back ... importance = NULL, diff --git a/README.md b/README.md index f2c6335..be9f0cf 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ bench::mark( #> # A tibble: 1 × 6 #> expression min median `itr/sec` mem_alloc `gc/sec` #> -#> 1 outline <- proj_outline() 489ms 524ms 1.91 21.2MB 3.81 +#> 1 outline <- proj_outline() 495ms 504ms 1.98 21.1MB 4.96 ```
@@ -183,11 +183,11 @@ outline #> `i` Load packages #> `i` Wrangle + visualize data #> `i` A great title -#> `i` TODO improve this Viz!- `Done✔?` +#> `i` TODO improve this Viz! #> #> ── `R/dplyr-plus.R` dplyr extra -#> `i` FIXME Doesn't work, problem with symbols here- `Done✔?` -#> `i` TODO use `check_length()` when implemented. r-lib/rlang#1618 ()- `Done✔?` +#> `i` FIXME Doesn't work, problem with symbols here +#> `i` TODO use `check_length()` when implemented. r-lib/rlang#1618 () #> `i` summarise with total #> #> ── `R/eda-identity.R` dplyr/base identity helpers -------------------- @@ -198,28 +198,28 @@ outline #> `i` helpers #> #> ── `R/files-conflicts.R` -#> `i` TODO insert in either proj_outline, or rename_file- `Done✔?` -#> `i` TODO probably needs a `detect_genuine_path()`- `Done✔?` +#> `i` TODO insert in either proj_outline, or rename_file +#> `i` TODO probably needs a `detect_genuine_path()` #> `i` Helpers -#> `i` TODO Add false positive references- `Done✔?` -#> `i` TODO fs::path and file.path should be handled differently- `Done✔?` +#> `i` TODO Add false positive references +#> `i` TODO fs::path and file.path should be handled differently #> #> ── `R/import-standalone-types-check.R` #> `i` Scalars #> `i` Vectors #> #> ── `R/open.R` -#> `i` FIXME why is this code like this?- `Done✔?` -#> `i` TODO structure and summarise information.- `Done✔?` -#> `i` FIXME (upstream) the color div doesn't go all the way r-lib/cli#694 ()- `Done✔?` +#> `i` FIXME why is this code like this? +#> `i` TODO structure and summarise information. +#> `i` FIXME (upstream) the color div doesn't go all the way r-lib/cli#694 () #> #> ── `R/outdated-pkgs.R` -#> `i` TODO figure out pad :)- `Done✔?` +#> `i` TODO figure out pad :) #> #> ── `R/outline-criteria.R` #> `i` Add variable to outline data frame -#> `i` TODO strip is_cli_info in Package? only valid for EDA- `Done✔?` -#> `i` FIXME try to detect all the chunk caption, but would have to figure out the end of it maybe lightparser.- `Done✔?` +#> `i` TODO strip is_cli_info in Package? only valid for EDA +#> `i` FIXME try to detect all the chunk caption, but would have to figure out the end of it maybe lightparser. #> `i` it is 'R/outline.R' #> #> ── `R/outline.R` `proj_outline()` @@ -227,26 +227,26 @@ outline #> `i` File outline #> `i` Print method #> `i` Step: tweak outline look as they show -#> `i` TODO reanable cli info- `Done✔?` -#> `i` TODO Improve performance with vctrs tidyverse/dplyr#6806 ()- `Done✔?` +#> `i` TODO reanable cli info +#> `i` TODO Improve performance with vctrs tidyverse/dplyr#6806 () #> #> ── `R/proj-list.R` -#> `i` TODO maybe add a max?- `Done✔?` -#> `i` TODO improve on this message- `Done✔?` +#> `i` TODO maybe add a max? +#> `i` TODO improve on this message #> #> ── `R/rename.R` #> `i` After here, we start doing some renaming real situations -#> `i` TODO verify if path should be normalized.- `Done✔?` +#> `i` TODO verify if path should be normalized. #> `i` Helpers #> `i` helpers for computing scope of renaming -#> `i` TODO measure of string proximity- `Done✔?` +#> `i` TODO measure of string proximity #> `i` Prevent renaming if something is going on -#> `i` FIXME maybe not fail while testing- `Done✔?` -#> `i` TODO Check that old file is more recent- `Done✔?` +#> `i` FIXME maybe not fail while testing +#> `i` TODO Check that old file is more recent #> #> ── `R/todo.R` -#> `i` TODO think about maybe using todo = clipr::read_clip()- `Done✔?` -#> `i` TODO nice to have, but would need to extract duplicates- `Done✔?` +#> `i` TODO think about maybe using todo = clipr::read_clip() +#> `i` TODO nice to have, but would need to extract duplicates #> `i` Helpers #> #> ── `R/utils-proj.R` usethis adaptions utils @@ -267,7 +267,7 @@ outline #> `i` Read my streets () data #> `i` data wrangling #> `i` Write my streets -#> `i` TODO Create a new version- `Done✔?` +#> `i` TODO Create a new version #> `i` 'R/my-file.R' #> `i` Section title #> @@ -276,7 +276,7 @@ outline #> ── `tests/testthat/_outline/titles.md` The title is the only outline element #> `i` Another title #> `i` Second level -#> `i` TODO this is an item- `Done✔?` +#> `i` TODO this is an item #> `i` Last title #> `i` `function_name()` title #> @@ -344,7 +344,7 @@ outline #> #> ── `tests/testthat/test-dplyr-plus.R` #> `i` filter_if_any() errors with across() -#> `i` TODO improve this error- `Done✔?` +#> `i` TODO improve this error #> `i` adds rows in front, but warns the user #> `i` summarise_with_total() keeps factors #> @@ -353,7 +353,7 @@ outline #> `i` Side effects are what's intended in interactive sessions #> #> ── `tests/testthat/test-escape-inline-markup.R` -#> `i` TODO could probably be {. } works?- `Done✔?` +#> `i` TODO could probably be {. } works? #> #> ── `tests/testthat/test-markup.R` #> `i` link_gh_issue() + markup_href() work @@ -371,7 +371,7 @@ outline #> ── `tests/testthat/test-outline.R` #> `i` alpha and work_only arguments work #> `i` file_outline() is a data frame -#> `i` TODO change tests for data frame size when stable (efficiency). As stil…- `Done✔?` +#> `i` TODO change tests for data frame size when stable (efficiency). As still debugging, better to keep all snapshots. #> `i` file_outline() with only title doesn't error #> `i` file_outline() contains function calls #> @@ -385,34 +385,34 @@ outline #> `i` Marking TODO as done detects tags #> #> ── `TODO.R` -#> `i` TODO screenshot make the behaviour different when vignettes vs articl…- `Done✔?` -#> `i` TODO screenshot RStudio addin to insert the code directly in the qmd …- `Done✔?` -#> `i` TODO use_family() to edit .R file to add @family data frames tags to ro…- `Done✔?` -#> `i` TODO mutate_identity redundant if the focus pillar PR was merged. r-lib/pillar#585 ()- `Done✔?` -#> `i` TODO rename if many matches, separate those with the exact path.- `Done✔?` -#> `i` TODO outline make ggtitle work- `Done✔?` -#> `i` TODO outline show extra msg only for some, but in file outline, not i…- `Done✔?` -#> `i` TODO outline detect help calls and apply markup. `?fs::file_show` dis…- `Done✔?` -#> `i` TODO outline renable cli info.- `Done✔?` -#> `i` TODO escape_markup doesn't work with complex operation {x^2} for example. Maybe if detecting something complex, use cli_escape function. escape-complex-markyp branch created to try to address this.- `Done✔?` -#> `i` TODO outline avoid evaluating in current env.- `Done✔?` -#> `i` TODO wrap regexps in functions- `Done✔?` -#> `i` TODO outline remove examples from outline. Sometimes commented code i…- `Done✔?` -#> `i` TODO outline roxygen comments processing should be left to `roxygen2::parse_file()`- `Done✔?` -#> `i` TODO outline show key like `pak::pkg_deps_tree()` does.- `Done✔?` -#> `i` TODO outline roxygen function title- `Done✔?` -#> `i` TODO outline remove ggtext markup from plot title.- `Done✔?` -#> `i` FIXME outline comments are now interpreted as section- `Done✔?` -#> `i` TODO outline todos in qmd file inside html comment- `Done✔?` -#> `i` TODO reframe more than one issue. nw drive- `Done✔?` -#> `i` TODO delete generated files- `Done✔?` -#> `i` TODO [proj_file] to accesss data (return the path in this case?)- `Done✔?` -#> `i` TODO [check_referenced_files] doesn't check for 'R/file.R'- `Done✔?` -#> `i` TODO explain rationale behind `work_only`. Suggest to transform to TODO…- `Done✔?` -#> `i` TODO browse_pkg should open by default if no vignettes are found, becau…- `Done✔?` -#> `i` TODO exclude _files from `proj_list()`- `Done✔?` -#> `i` TODO rename_files should be less noisy about project name file- `Done✔?` -#> `i` TODO add_to_tricks(). when detecting TRICK like complete todo, but not …- `Done✔?` +#> `i` TODO screenshot make the behaviour different when vignettes vs articles: vignettes should place it in man/figures, while articles could put it in vignettes/articles file. +#> `i` TODO screenshot RStudio addin to insert the code directly in the qmd doc. No longer needed with RStudio 2023.12 +#> `i` TODO use_family() to edit .R file to add @family data frames tags to roxygen +#> `i` TODO mutate_identity redundant if the focus pillar PR was merged. r-lib/pillar#585 () +#> `i` TODO rename if many matches, separate those with the exact path. +#> `i` TODO outline make ggtitle work +#> `i` TODO outline show extra msg only for some, but in file outline, not in proj? +#> `i` TODO outline detect help calls and apply markup. `?fs::file_show` disregard finishing `.` (not followed by dot) +#> `i` TODO outline renable cli info. +#> `i` TODO escape_markup doesn't work with complex operation {x^2} for example. Maybe if detecting something complex, use cli_escape function. escape-complex-markyp branch created to try to address this. +#> `i` TODO outline avoid evaluating in current env. +#> `i` TODO wrap regexps in functions +#> `i` TODO outline remove examples from outline. Sometimes commented code is caught. +#> `i` TODO outline roxygen comments processing should be left to `roxygen2::parse_file()` +#> `i` TODO outline show key like `pak::pkg_deps_tree()` does. +#> `i` TODO outline roxygen function title +#> `i` TODO outline remove ggtext markup from plot title. +#> `i` FIXME outline comments are now interpreted as section +#> `i` TODO outline todos in qmd file inside html comment +#> `i` TODO reframe more than one issue. nw drive +#> `i` TODO delete generated files +#> `i` TODO [proj_file] to accesss data (return the path in this case?) +#> `i` TODO [check_referenced_files] doesn't check for 'R/file.R' +#> `i` TODO explain rationale behind `work_only`. Suggest to transform to TODO if this item is no longer critical. `work_only` goal is to show you exactly where you need to do work +#> `i` TODO browse_pkg should open by default if no vignettes are found, because there is not much to do in the R-session. +#> `i` TODO exclude _files from `proj_list()` +#> `i` TODO rename_files should be less noisy about project name file +#> `i` TODO add_to_tricks(). when detecting TRICK like complete todo, but not remove line. requires a scheme. moves the item to tricks.md at the correct place. (copy to clipboard is probably enough) #> #> ── `NEWS.md` #> `i` reuseme (development version) diff --git a/tests/testthat/_snaps/outline.md b/tests/testthat/_snaps/outline.md index 0aeed79..90a4458 100644 --- a/tests/testthat/_snaps/outline.md +++ b/tests/testthat/_snaps/outline.md @@ -21,12 +21,12 @@ `i` Last title `i` Second level `i` `function_name()` title - `i` TODO this is an item- `Donev?` + `i` TODO this is an item Message -- `my-analysis.R` Analyse my {streets} Output - `i` TODO Create a new version- `Donev?` + `i` TODO Create a new version `i` Read my streets () data `i` Section title `i` Write my streets @@ -58,7 +58,7 @@ `i` Load packages `i` Wrangle + visualize data `i` A great title - `i` TODO improve this Viz!- `Donev?` + `i` TODO improve this Viz! # pattern works as expected @@ -76,7 +76,7 @@ -- `outline-script.R` Example for `file_outline()` Output - `i` TODO improve this Viz!- `Donev?` + `i` TODO improve this Viz! ---