Skip to content

Commit fc875a8

Browse files
committed
Trigger namespace resource from browser() too
1 parent d19da05 commit fc875a8

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

crates/ark/src/modules/positron/hooks.R

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,30 @@
66
#
77

88
register_hooks <- function() {
9-
rebind("utils", "View", .ps.view_data_frame, namespace = TRUE)
10-
rebind("base", "debug", new_ark_debug(base::debug), namespace = TRUE)
11-
rebind("base", "debugonce", new_ark_debug(base::debugonce), namespace = TRUE)
9+
rebind(
10+
"utils",
11+
"View",
12+
.ps.view_data_frame,
13+
namespace = TRUE
14+
)
15+
rebind(
16+
"base",
17+
"debug",
18+
new_ark_debug(base::debug),
19+
namespace = TRUE
20+
)
21+
rebind(
22+
"base",
23+
"debugonce",
24+
new_ark_debug(base::debugonce),
25+
namespace = TRUE
26+
)
27+
rebind(
28+
"base",
29+
"browser",
30+
new_ark_browser(base::browser),
31+
namespace = TRUE
32+
)
1233
register_getHook_hook()
1334
}
1435

@@ -24,7 +45,7 @@ rebind <- function(pkg, name, value, namespace = FALSE) {
2445
pkg = pkg,
2546
name = name,
2647
value = value
27-
)
48+
)
2849
}
2950
}
3051

@@ -42,7 +63,11 @@ pkg_bind <- function(pkg, name, value) {
4263
env <- as.environment(env)
4364

4465
if (!exists(name, envir = env, mode = "function", inherits = FALSE)) {
45-
msg <- sprintf("Can't register hook: function `%s::%s` not found.", pkg, name)
66+
msg <- sprintf(
67+
"Can't register hook: function `%s::%s` not found.",
68+
pkg,
69+
name
70+
)
4671
stop(msg, call. = FALSE)
4772
}
4873

@@ -70,7 +95,12 @@ register_getHook_hook <- function() {
7095
local_unlock_binding(ns, "getHook")
7196

7297
ns[["getHook"]] <- function(hookName, ...) {
73-
hooks <- get0(hookName, envir = .userHooksEnv, inherits = FALSE, ifnotfound = list())
98+
hooks <- get0(
99+
hookName,
100+
envir = .userHooksEnv,
101+
inherits = FALSE,
102+
ifnotfound = list()
103+
)
74104

75105
if (!grepl("^UserHook::.*::onLoad$", hookName)) {
76106
return(hooks)

crates/ark/src/modules/positron/srcref.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,37 @@ new_ark_debug <- function(fn) {
7676
fn
7777
}
7878

79+
new_ark_browser <- function(fn) {
80+
browser <- base::browser
81+
82+
function(text = "", condition = NULL, expr = TRUE, skipCalls = 0L) {
83+
local({
84+
if (!.ps.internal(do_resource_namespaces(default = TRUE))) {
85+
return() # from local()
86+
}
87+
88+
pkgs <- loadedNamespaces()
89+
90+
# Give priority to the namespace of the calling function
91+
env <- topenv(parent.frame())
92+
if (isNamespace(env)) {
93+
pkgs <- unique(c(getNamespaceName(env), pkgs))
94+
}
95+
96+
# Enable namespace resourcing for all future loaded namespaces and
97+
# resource already loaded namespaces so we get virtual documents for
98+
# step-debugging.
99+
options(ark.resource_namespaces = TRUE)
100+
.ps.internal(resource_loaded_namespaces(pkgs))
101+
})
102+
103+
# Skip this wrapper
104+
skipCalls <- skipCalls + 1L
105+
106+
browser(text = text, condition = condition, expr = expr, skipCalls = skipCalls)
107+
}
108+
}
109+
79110
do_resource_namespaces <- function(default) {
80111
getOption("ark.resource_namespaces", default = default)
81112
}

0 commit comments

Comments
 (0)