Skip to content

Commit

Permalink
Add hyperlink to errors (#1335)
Browse files Browse the repository at this point in the history
Fixes #1323
  • Loading branch information
hadley authored Apr 25, 2022
1 parent cab1639 commit f4f7274
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Depends:
R (>= 3.3)
Imports:
brew,
cli (>= 3.2.0.9000),
cli (>= 3.3.0),
commonmark,
desc (>= 1.2.0),
digest,
Expand Down Expand Up @@ -53,5 +53,3 @@ Language: en-GB
Roxygen: list(markdown = TRUE, load = "installed")
RoxygenNote: 7.1.2.9000
SystemRequirements: C++11
Remotes:
r-lib/cli
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# roxygen2 (development version)

* If you have a daily build of RStudio, roxygen2 warnings will now include a
clickable hyperlink that will take you directly to the problem (#1323).

* Inline R code is now powered by knitr. Where available, (knit) print methods
are applied (#1179). This change alters outputs and brings roxygen in line
with console and R markdown behavior. `x <- "foo"` no longer inserts anything
Expand Down
2 changes: 1 addition & 1 deletion R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,6 @@ parse_description <- function(tags) {
}

warn_roxy_block <- function(block, message, ...) {
message[[1]] <- paste0("[", block$file, ":", block$line, "] ", message[[1]])
message[[1]] <- paste0(link_to(block$file, block$line), " ", message[[1]])
cli::cli_warn(message, ..., .envir = parent.frame())
}
11 changes: 9 additions & 2 deletions R/tag.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ roxy_tag_warning <- function(x, ...) {
#' @rdname roxy_tag
warn_roxy_tag <- function(tag, message, ...) {
message[[1]] <- paste0(
"[", tag$file, ":", tag$line, "] ",
"@", tag$tag, " ",
link_to(tag$file, tag$line), " @", tag$tag, " ",
if (is.null(tag$raw)) ("(automatically generated) "),
message[[1]]
)
cli::cli_warn(message, ..., .envir = parent.frame())
}

link_to <- function(file, line) {
paste0("[", cli::style_hyperlink(
paste0(basename(file), ":", line),
paste0("file://", file),
params = c(line = line, col = 1)
), "]")
}

0 comments on commit f4f7274

Please sign in to comment.