From f4f72748b2519a697c5664257a703cc8435ce4c3 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 25 Apr 2022 07:32:45 -0500 Subject: [PATCH] Add hyperlink to errors (#1335) Fixes #1323 --- DESCRIPTION | 4 +--- NEWS.md | 3 +++ R/block.R | 2 +- R/tag.R | 11 +++++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c2607b71..0b2c2264 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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, @@ -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 diff --git a/NEWS.md b/NEWS.md index 3b4333a7..93e7bfd2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/block.R b/R/block.R index ad7fdd7f..0f82f007 100644 --- a/R/block.R +++ b/R/block.R @@ -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()) } diff --git a/R/tag.R b/R/tag.R index 583c7f10..ef34f398 100644 --- a/R/tag.R +++ b/R/tag.R @@ -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) + ), "]") +}