Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More sophisticated detection for re-exported functions #144

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# downlit (development version)

* Re-exports detection no longer relies on name of `.Rd` file (#134).

* Adds support for new R pipe `|>` syntax (#126).

* Very long strings or other tokens are no longer truncated
Expand Down
27 changes: 16 additions & 11 deletions R/link.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,31 @@ href_topic_remote <- function(topic, package) {
return(NA_character_)
}

if (rdname == "reexports") {
return(href_topic_reexported(topic, package))
if (is_reexported(topic, package)) {
href_topic_reexported(topic, package)
} else {
paste0(href_package_ref(package), "/", rdname, ".html")
}
}

paste0(href_package_ref(package), "/", rdname, ".html")
is_reexported <- function(name, package) {
is_imported <- env_has(ns_imports_env(package), name)
is_exported <- name %in% getNamespaceExports(ns_env(package))

is_imported && is_exported
}

# If it's a re-exported function, we need to work a little harder to
# find out its source so that we can link to it.
href_topic_reexported <- function(topic, package) {
ns <- ns_env(package)
exports <- .getNamespaceInfo(ns, "exports")

if (!env_has(exports, topic)) {
NA_character_
} else {
obj <- env_get(ns, topic, inherit = TRUE)
package <- find_reexport_source(obj, ns, topic)
href_topic_remote(topic, package)
if (!env_has(ns, topic, inherit = TRUE)) {
return(NA_character_)
}

obj <- env_get(ns, topic, inherit = TRUE)
ex_package <- find_reexport_source(obj, ns, topic)
href_topic_remote(topic, ex_package)
}

find_reexport_source <- function(obj, ns, topic) {
Expand Down