From ca99e67cea15004598c5f901f2486202a12c246c Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Fri, 19 Dec 2025 09:09:11 +0100 Subject: [PATCH 1/5] Inject breakpoints in Positron --- R/source.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/R/source.R b/R/source.R index f09646e3..da2dd16f 100644 --- a/R/source.R +++ b/R/source.R @@ -30,6 +30,17 @@ source_one <- function(file, encoding, envir = parent.frame()) { isFile = TRUE ) + ark_annotate_source <- env_get(baseenv(), ".ark_annotate_source", default = NULL) + if (!is.null(ark_annotate_source)) { + # Just to be sure, but should already be normalized + file <- normalizePath(file, mustWork = TRUE) + + # Ark expects URIs + uri <- paste0("file://", file) + + lines <- ark_annotate_source(uri, paste_line(lines)) %||% lines + } + withCallingHandlers( exprs <- parse(text = lines, n = -1, srcfile = srcfile), error = function(cnd) handle_parse_error(cnd, file) From 5c8300b9f2d3b8ebef22bdc03c54f3b45456208c Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Sat, 17 Jan 2026 00:15:58 +0100 Subject: [PATCH 2/5] Fix srcref issue --- R/source.R | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/R/source.R b/R/source.R index da2dd16f..2287742e 100644 --- a/R/source.R +++ b/R/source.R @@ -23,14 +23,12 @@ source_one <- function(file, encoding, envir = parent.frame()) { stopifnot(is.environment(envir)) lines <- read_lines_enc(file, file_encoding = encoding) - srcfile <- srcfilecopy( - file, - lines, - file.info(file)[1, "mtime"], - isFile = TRUE - ) - ark_annotate_source <- env_get(baseenv(), ".ark_annotate_source", default = NULL) + ark_annotate_source <- env_get( + baseenv(), + ".ark_annotate_source", + default = NULL + ) if (!is.null(ark_annotate_source)) { # Just to be sure, but should already be normalized file <- normalizePath(file, mustWork = TRUE) @@ -38,9 +36,19 @@ source_one <- function(file, encoding, envir = parent.frame()) { # Ark expects URIs uri <- paste0("file://", file) - lines <- ark_annotate_source(uri, paste_line(lines)) %||% lines + annotated <- ark_annotate_source(uri, paste_line(lines)) + if (!is.null(annotated)) { + lines <- strsplit(annotated, "\n", fixed = TRUE)[[1]] + } } + srcfile <- srcfilecopy( + file, + lines, + file.info(file)[1, "mtime"], + isFile = TRUE + ) + withCallingHandlers( exprs <- parse(text = lines, n = -1, srcfile = srcfile), error = function(cnd) handle_parse_error(cnd, file) From 2a2b2107dc44b33a74ba6c37607a5d88b9c5e758 Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Sat, 17 Jan 2026 00:19:59 +0100 Subject: [PATCH 3/5] Fix URIs on Windows --- R/source.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/source.R b/R/source.R index 2287742e..541ca916 100644 --- a/R/source.R +++ b/R/source.R @@ -34,7 +34,7 @@ source_one <- function(file, encoding, envir = parent.frame()) { file <- normalizePath(file, mustWork = TRUE) # Ark expects URIs - uri <- paste0("file://", file) + uri <- paste0("file:///", sub("^/", "", file)) annotated <- ark_annotate_source(uri, paste_line(lines)) if (!is.null(annotated)) { From 6cc3650a05aae507fbeb11ccc50ba0c543d126ba Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Sat, 17 Jan 2026 00:26:20 +0100 Subject: [PATCH 4/5] Reorder arguments --- R/source.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/source.R b/R/source.R index 541ca916..34a93e9b 100644 --- a/R/source.R +++ b/R/source.R @@ -36,7 +36,7 @@ source_one <- function(file, encoding, envir = parent.frame()) { # Ark expects URIs uri <- paste0("file:///", sub("^/", "", file)) - annotated <- ark_annotate_source(uri, paste_line(lines)) + annotated <- ark_annotate_source(paste_line(lines), uri) if (!is.null(annotated)) { lines <- strsplit(annotated, "\n", fixed = TRUE)[[1]] } From 3e4de5f5f1cd74dc43b158e0d227a48bcab0e828 Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Thu, 22 Jan 2026 14:12:17 +0100 Subject: [PATCH 5/5] Catch Positron-side errors and downgrade to warning --- R/source.R | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/R/source.R b/R/source.R index 34a93e9b..4f5f6acc 100644 --- a/R/source.R +++ b/R/source.R @@ -30,16 +30,24 @@ source_one <- function(file, encoding, envir = parent.frame()) { default = NULL ) if (!is.null(ark_annotate_source)) { - # Just to be sure, but should already be normalized - file <- normalizePath(file, mustWork = TRUE) - - # Ark expects URIs - uri <- paste0("file:///", sub("^/", "", file)) - - annotated <- ark_annotate_source(paste_line(lines), uri) - if (!is.null(annotated)) { - lines <- strsplit(annotated, "\n", fixed = TRUE)[[1]] - } + tryCatch( + { + # Just to be sure, but should already be normalized + file <- normalizePath(file, mustWork = TRUE) + + # Ark expects URIs + uri <- paste0("file:///", sub("^/", "", file)) + + annotated <- ark_annotate_source(paste_line(lines), uri) + if (!is.null(annotated)) { + lines <- strsplit(annotated, "\n", fixed = TRUE)[[1]] + } + }, + + error = function(cnd) { + warn("Can't inject breakpoints", parent = cnd) + } + ) } srcfile <- srcfilecopy(