Skip to content

Commit 2357de6

Browse files
authored
Use more generic x-r-run over ide:run (#1604)
1 parent db4dd9a commit 2357de6

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

R/rd.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ roclet_output.roclet_rd <- function(x, results, base_path, ..., is_first = FALSE
6060

6161
names <- unname(map_chr(results, ~ .$get_name()[[1]]))
6262
if (length(names) > 0) {
63-
hrefs <- paste0("ide:run:pkgload::dev_help('", names, "')")
63+
commands <- paste0("pkgload::dev_help('", names, "')")
6464
} else {
65-
hrefs <- character()
65+
commands <- character()
6666
}
6767

6868
# Always check for roxygen2 header before overwriting NAMESPACE (#436),
6969
# even when running for the first time
70-
mapply(write_if_different, paths, contents, href = hrefs)
70+
mapply(write_if_different, paths, contents, command = commands)
7171

7272
if (!is_first) {
7373
# Automatically delete any files in man directory that were generated

R/utils.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ nice_name <- function(x) {
6161
x
6262
}
6363

64-
write_if_different <- function(path, contents, href = NULL, check = TRUE) {
64+
write_if_different <- function(path, contents, command = NULL, check = TRUE) {
6565
if (!file.exists(dirname(path))) {
6666
dir.create(dirname(path), showWarnings = FALSE)
6767
}
@@ -87,8 +87,10 @@ write_if_different <- function(path, contents, href = NULL, check = TRUE) {
8787
))
8888
FALSE
8989
} else {
90-
if (!is.null(href)) {
91-
name <- cli::style_hyperlink(name, href)
90+
if (!is.null(command)) {
91+
scheme <- "x-r-run"
92+
url <- paste0(scheme, ":", command)
93+
name <- cli::style_hyperlink(name, url)
9294
}
9395
cli::cli_inform("Writing {.path {name}}")
9496

tests/testthat/_snaps/utils.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@
2727
Output
2828
[1] FALSE
2929

30+
# write_if_different produces correct command hyperlink
31+
32+
Code
33+
write_if_different(path, "a <- 2", command = "rlang::inform('hi')")
34+
Message
35+
Writing ']8;;x-r-run:rlang::inform('hi')test.R]8;;'
36+
Output
37+
[1] TRUE
38+

tests/testthat/test-utils.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,13 @@ test_that("write_if_different and end of line", {
6868
expect_message(write_if_different(tmp, cnt_mix, check = FALSE), "Writing ")
6969
expect_identical(readBin(tmp, "raw", 100), readBin(tmp_win, "raw", 100))
7070
})
71+
72+
test_that("write_if_different produces correct command hyperlink", {
73+
testthat::local_reproducible_output(hyperlinks = TRUE)
74+
75+
dir <- withr::local_tempdir()
76+
path <- file.path(dir, "test.R")
77+
78+
write_lines(made_by("#"), path)
79+
expect_snapshot(write_if_different(path, "a <- 2", command = "rlang::inform('hi')"))
80+
})

0 commit comments

Comments
 (0)